pyhtmlchart
Pie Chart Page
Home Tutorial History Help

Pie Chart

To make a Simple Pie Chart with pyhtmlchart. Follow the given code below:
import pyhtmlchart as chart
pie_chart = chart.pie_chart.PieChart(location='pie', title='Chart')
columns = ['Time', 'Number1']
all_data = [['1', 200], ['2', 500]]
pie_chart.add_data(data=all_data, data_titles=columns)
pie_chart.open()

The above code will open the following chart in the browser:

Explanation:
The PieChart Class:
Parameters:

The pie chart class is the class to make a pie chart. It contains following parameters:
  1. location :- The location of the chart to be saved.

  2. title :- The title of the chart.

  3. background_color :- The background color of the chart.

  4. legend_position :- The legend position of the chart. It's values can be 'top', 'bottom', 'right'

  5. width :- The width of the chart.

  6. height :- The height to the chart.

  7. y_axis_title :- The title of the Y axis of the chart.

  8. x_axis_title :- The title of the X axis of the chart.

  9. color :- The list of all colors to be added in the chart.

  10. is3d :- Set it to True if you want the pie chart to be 3D.

  11. print_log :- Set it to True if you want the chart log to be printed out.
Functions:
add_data(data, data_titles) :-
The function to add the data to the chart. Check the above code to understand it.
enable_auto_update(time=5000) :-
The function to enable the auto update to the chart. Give the time parameter an 'int' value in milliseconds.
disable_auto_update() :-
The function to disable auto update to the chart.
update_data(data, append=False, wait=True) :-
The function to update the given data. Give the data parameter the nested list to be added. Set append to True if you want the data to append and set wait to True if you want the program to wait for the update time and then update the data.
open() :-
The function to automatically open the chart in the browser.
print_chart_settings() :-
The function to print the chart settings.

Making a simple auto update chart:

Following is a simple code that auto updates a chart using random values:
import pyhtmlchart as chart
import random
pie_chart = chart.pie_chart.PieChart(location='pie', title='Chart')
columns = ['Time', 'Number1']
all_data = [['1', 200], ['2', 500]]
pie_chart.add_data(data=all_data, data_titles=columns)
pie_chart.enable_auto_update(time=5000)
pie_chart.open()

i = 3
while True:
    data = [str(i), random.randint(1, 1000)]
    pie_chart.update_data(data=[data], append=True)
    i += 1


Multiple Charts:
To display multiple charts on one page go to Multiple Charts Tutorial.