Create A Liquid (Water Polo) Chart From Excel Data in Python | ‘PyeCharts’ Tutorials
Language:
This tutorial will show you how to turn the values from an Excel File into animated liquid/water polo charts using the Python library ‘pyecharts’. Pyecharts will render the liquid charts in an HTML file. So, if you want to spice up your next presentation or if you are tired of the Standard Excel charts, this tutorial might be interesting for you.
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')