pyhtmlchart
Bar Chart Page
Home Tutorial History Help

Bar Chart

To make a Simple Bar Chart with pyhtmlchart. Follow the given code below:
import pyhtmlchart as chart
bar_chart = chart.bar_chart.BarChart(location='bar', title='Chart')
columns = ['Time', 'Number1', 'Number2']
all_data = [[1, 200, 300], [2, 500, 400]]
bar_chart.add_data(data=all_data, data_titles=columns)
bar_chart.open()

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

Explanation:
The BarChart Class:
Parameters:

The bar chart class is the class to make a bar 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. chart_actions :- Chart Actions such as pan and zoom. Set it to True if you want chart actions.

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

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

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

  11. bar_width :- The width of the bar in bar chart.

  12. 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
bar_chart = chart.bar_chart.BarChart(location='bar', title='Chart')
columns = ['Time', 'Number1', 'Number2']
all_data = [[1, 200, 300], [2, 500, 400]]
bar_chart.add_data(data=all_data, data_titles=columns)
bar_chart.enable_auto_update(time=5000)
bar_chart.open()

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


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