开发者

pygooglechart define data encoding

when using chart.add_date([1,2,3,4,5]) it creates the URL with "chd=e:LNYAczgATN5m", it is encoded the data but i want to be of type text as "c开发者_如何学运维hd=t:1,2,3,4,5"

What is the function that can do this ?

Thanks in Advance


pygooglechart attempts to detect the source data range, and automatically decide what data encoding type to use. See the def data_class_detection() method in the source:

https://github.com/gak/pygooglechart/blob/master/pygooglechart.py#L518

To force a certain type of encoding, you can call get_url(self, data_class=None) and specify the data_class as TextData, e.g.:

import pygooglechart as pygc
chart = pygc.SimpleLineChart(250, 100)
chart.add_data([1, 3, 2, 4, 5])

>>> chart.get_url(data_class=pygc.TextData)
'http://chart.apis.google.com/chart?cht=lc&chs=250x100&chd=t:0.0,40.0,20.0,60.0,80.0'

>>> chart.get_url()
'http://chart.apis.google.com/chart?cht=lc&chs=250x100&chd=e:AAMzZmmZzM'


if you want to use chart.download() then the data_class option of get_url is not available.

You can use a subclass to work around this problem:

# force the TextData type for any data (real number instead of aabaa)
class LineChart(SimpleLineChart):
   def data_class_detection(self, data):
       return TextData

and then use this class instead of SimpleLineChart

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜