Displaying no data

One parameter worth looking at is the no_data_text parameter, which allows us to set a text overlay for our chart, just in case we create a chart without loading data. This is helpful if we are building a dynamic chart where we pull data from a data source, either online or locally, through a file or command-line parameters. Here's an example of the no_data_text parameter in action:

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

param_line_chart = pygal.Line(no_data_text='Unable to load data')
param_line_chart.title = 'Parameter Line Chart'
param_line_chart.x_title='Data-Sets (X Axis)'
param_line_chart.y_title='Values (Y Axis)'

param_line_chart.x_labels = map(str, ["Data Object 1", "Data Object 2", "Data Object 3", "Data Object 4", "Data Object 5", "Data Object 6"])

#param_line_chart.add('Data-Set 1', [8, 16, 24, 32, 48, 56])
#param_line_chart.add('Data-Set 2', [2, 4, 6, 8, 10, 12])
#param_line_chart.add('Data-Set 3', [1, 3, 5, 7, 9, 12])

param_line_chart.render_to_file('lineparam.svg')

The following screenshot shows the results of our script:

Displaying no data
..................Content has been hidden....................

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