Simple bar charts

Bar charts are typically used like line charts, but they fill the full area of the chart. They also help show values to categories of information. Let's build a simple bar chart, copy the following code into a new file called bar_chart.py, and run the script:

# -*- coding: utf-8 -*-
import pygal

#create a new bar chart.
bar = pygal.Bar()
bar.title = 'Searches for term: sleep'
bar.x_labels = map(str, range(2011, 2015))
bar.add('Searches', [81, 88, 88, 100])
bar.render_to_file('bar_chart.svg')

Go to your project directory and open bar_chart.svg in your browser. Note that the code hasn't changed much beyond the data provided and the type of chart defined (in this case, it is pygal.Bar()). The following screenshot shows the results of our script:

Simple bar charts
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.47.25