Create a Liquid Fill Chart From Excel Data With Pyecharts
pyecharts draws animated liquid fill charts, a wave moving inside a circle or another shape, from a value between 0 and 1. This tutorial reads three KPI values from an Excel sheet with pandas, draws one liquid chart per KPI, places them side by side and saves the result as an HTML file that keeps its animation when you share it.
Install the packages
You need three packages: pyecharts draws the charts, pandas reads the Excel file, and openpyxl is the engine pandas uses for .xlsx files. Install them from a terminal:
pip install pyecharts
pip install pandas
pip install openpyxl
A first liquid chart
A liquid chart takes a list with one value between 0 and 1, so 0.95 shows as 95%. I import the Liquid chart and the options module, add the value, set a title and render the chart to an HTML file:
from pyecharts.charts import Liquid
from pyecharts import options as opts
# -- Create Liquid Chart
customer_satisfaction = (
Liquid()
.add('lq', [0.95])
.set_global_opts(title_opts=opts.TitleOpts(title='Customer Satisfaction'))
)
# -- Export to HTML
customer_satisfaction.render('Basic_Example.html')
Open Basic_Example.html in your browser to see the animated chart.
Position the chart and title
By default the chart sits in the middle of the page and the title in the top left corner, so they do not line up. The center argument of add moves the chart, as percentages of the page width and height, and pos_left moves the title:
customer_satisfaction = (
Liquid()
.add('lq', [0.95], center=["15%", "35%"])
.set_global_opts(
title_opts=opts.TitleOpts(title='Customer Satisfaction', pos_left="5%")
)
)

Read the values from Excel
To update the chart without touching the code, read the value from Excel instead of typing it in. My workbook data.xlsx has a sheet named KPI with one column per KPI and the values as decimals in the first row. pandas reads the sheet, and I take the first value of the Customer Satisfaction column:
from pyecharts.charts import Liquid
from pyecharts import options as opts
import pandas as pd
EXCEL_FILE = 'data.xlsx'
# -- Get values from Excel
kpi = pd.read_excel(EXCEL_FILE, sheet_name='KPI')
customer_satisfaction_value = kpi['Customer Satisfaction'].iloc[0]
# -- Create Liquid Chart
customer_satisfaction = (
Liquid()
.add('lq', [customer_satisfaction_value], center=["15%", "35%"])
.set_global_opts(
title_opts=opts.TitleOpts(title='Customer Satisfaction', pos_left="5%")
)
)
customer_satisfaction.render('Basic_Example.html')
Three charts on one page
To show several liquid charts on one page, I build one chart per KPI and combine them with the Grid class. Read the “Sales Target” and “Market Share” values the same way, and make sure the column names in your Excel file match exactly. Each chart gets its own center and title position, so the three sit side by side:
from pyecharts.charts import Grid, Liquid
from pyecharts import options as opts
import pandas as pd
EXCEL_FILE = 'data.xlsx'
# -- Get values from Excel
kpi = pd.read_excel(EXCEL_FILE, sheet_name='KPI')
customer_satisfaction_value = kpi['Customer Satisfaction'].iloc[0]
sales_target_value = kpi['Sales Target'].iloc[0]
market_share_value = kpi['Market Share'].iloc[0]
# -- Create Liquid Charts
customer_satisfaction = (
Liquid()
.add('lq', [customer_satisfaction_value], center=["15%", "35%"])
.set_global_opts(
title_opts=opts.TitleOpts(title='Customer Satisfaction', pos_left="5%")
)
)
sales_target = (
Liquid()
.add('lq', [sales_target_value], center=["50%", "35%"])
.set_global_opts(
title_opts=opts.TitleOpts(title='Sales Target', pos_left="40%")
)
)
market_share = (
Liquid()
.add('lq', [market_share_value], center=["85%", "35%"])
.set_global_opts(
title_opts=opts.TitleOpts(title='Overall Market Share', pos_left="75%")
)
)
# -- Combine the charts and export to HTML
grid = (
Grid()
.add(customer_satisfaction, grid_opts=opts.GridOpts())
.add(sales_target, grid_opts=opts.GridOpts())
.add(market_share, grid_opts=opts.GridOpts())
)
grid.render('KPI_Dashboard.html')
Change the shape
Each liquid chart can also take a different shape. I hide the outline and change the shape for the sales target and the market share. The shape constants live in pyecharts.globals, so add from pyecharts.globals import SymbolType to your imports first, then replace the two chart definitions:
sales_target = (
Liquid()
.add('lq',
[sales_target_value],
center=["50%", "35%"],
is_outline_show=False,
shape=SymbolType.DIAMOND,
)
.set_global_opts(
title_opts=opts.TitleOpts(title='Sales Target', pos_left="40%")
)
)
market_share = (
Liquid()
.add('lq',
[market_share_value],
center=["85%", "35%"],
is_outline_show=False,
shape=SymbolType.RECT,
)
.set_global_opts(
title_opts=opts.TitleOpts(title='Overall Market Share', pos_left="75%")
)
)

To place these KPIs next to bar charts and a calendar heatmap, see my pyecharts dashboard tutorial. If you only need a single KPI gauge rather than an animated liquid fill, my post on gauge and bullet charts with Python shows how I build those with Plotly.
If you want a quick dashboard without writing Python, the free dashboard maker builds one from pasted Excel cells in the browser.
Resources
from pyecharts.charts import Liquid, Grid
from pyecharts import options as opts
from pyecharts.globals import SymbolType
import pandas as pd
# GitHub: https://github.com/pyecharts/pyecharts/blob/master/README.en.md
# Documentation: https://pyecharts.org/#/en-us/
# Gallery: https://gallery.pyecharts.org/#/Liquid/multiple_liquid
EXCEL_FILE = 'data.xlsx'
# -- Get values from Excel
kpi = pd.read_excel(EXCEL_FILE, sheet_name='KPI')
customer_satisfaction_value = kpi['Customer Satisfaction'].iloc[0]
sales_target_value = kpi["Sales Target"].iloc[0]
market_share_value = kpi["Market Share"].iloc[0]
# -- Create Liquid Chart
customer_satisfaction = (
Liquid()
.add('lq', [customer_satisfaction_value], center=["15%", "35%"])
.set_global_opts(
title_opts=opts.TitleOpts(title='Customer Satisfaction', pos_left="5%")
)
)
sales_target = (
Liquid()
.add('lq',
[sales_target_value],
center=["50%", "35%"],
is_outline_show=False,
shape=SymbolType.DIAMOND,
)
.set_global_opts(
title_opts=opts.TitleOpts(title='Sales Target 2021', pos_left="40%")
)
)
market_share = (
Liquid()
.add('lq',
[market_share_value],
center=["85%", "35%"],
is_outline_show=False,
shape=SymbolType.RECT,
)
.set_global_opts(
title_opts=opts.TitleOpts(title='Overall Market Share', pos_left="75%")
)
)
grid = (
Grid()
.add(customer_satisfaction, grid_opts=opts.GridOpts())
.add(sales_target, grid_opts=opts.GridOpts())
.add(market_share, grid_opts=opts.GridOpts())
)
# -- Export to HTML
grid.render('KPI_Dashboard.html')