Skip to content Skip to sidebar Skip to footer

Create Dynamic Labels For Google Chart Using Gchartwrapper

I'm using the awesome Google Chart Wrapper to create charts as part of my Django project. Right now I'm creating the chart instance using Python in my views, and then adding the in

Solution 1:

In order to understand how to properly pass the labels it's important to know what *args means.

*args (which is an asterisk + an arbitrary argument name) in a function (or method as in this case) definition means any number (including 0) of anonymous arguments.

See this answer for a more thorough explanation.

This means that the method in question accepts one obligatory argument index which is the index of the axis to be labelled and any number of anonymous arguments (actual labels).

Knowing this, it should already be clear that the proper way to call label() is as follows:

chart.axes.label( 0, 'date 1', 'date 2', 'date 3', ... )

where 0 is the index of the X-axis and all the other arguments are respective labels.

The reason why this is implemented in this manner is that the number of lables is unknown - it depends on the chart, so accepting any number of labels seems like a good idea.

You may also want to take a look at the example here

Post a Comment for "Create Dynamic Labels For Google Chart Using Gchartwrapper"