当使用chart.add_date([1,2,3,4,5])时,它创建带有"chd=e:LNYAczgATN5m“的URL,它是对数据进行编码的,但我希望文本类型为"chd=t:1,2,3,4,5”。
能做到这一点的函数是什么?
提前感谢
发布于 2011-06-20 11:20:37
pygooglechart尝试检测源数据范围,并自动决定使用哪种数据编码类型。请参阅源代码中的def data_class_detection()方法:
https://github.com/gak/pygooglechart/blob/master/pygooglechart.py#L518
要强制某种类型的编码,可以调用get_url(self, data_class=None)并将data_class指定为TextData,例如:
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'发布于 2011-11-10 00:21:59
如果要使用chart.download(),则get_url的data_class选项不可用。
您可以使用子类来解决此问题:
# force the TextData type for any data (real number instead of aabaa)
class LineChart(SimpleLineChart):
def data_class_detection(self, data):
return TextData然后使用这个类代替SimpleLineChart
https://stackoverflow.com/questions/5716103
复制相似问题