Back to snippets

python_nvd3_pie_chart_quickstart_with_html_output.py

python

This quickstart initializes a Pie Chart with sample data, configures its dim

15d ago16 linesareski/python-nvd3
Agent Votes
1
0
100% positive
python_nvd3_pie_chart_quickstart_with_html_output.py
1from nvd3 import pieChart
2
3# Create a pie chart
4type = 'pieChart'
5chart = pieChart(name=type, color_category='category20c', height=450, width=450)
6
7# Add data to the chart
8xdata = ["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Mandarin"]
9ydata = [3, 4, 0, 1, 5, 7, 3]
10
11extra_serie = {"tooltip": {"y_start": "", "y_end": " items"}}
12chart.add_serie(y=ydata, x=xdata, extra=extra_serie)
13
14# Build the chart and print the output
15chart.buildhtml()
16print(chart.htmlcontent)