我已经解决了这个问题:
我会为其他人发布我的解决方案,因为我发现这很难搜索:
qset = bills.values("billing_date","energy_kwh").order_by() # Obtain data from database
description = {'billing_date': ('date','billing_date'), 'zcolor':('string','',{'role':'style'}), 'energy_kwh': ('number','energy_kwh')} # indicate columns as dictionaries {"id": "type", "label", "custom property"}
for row in qset:
row['zcolor'] = 'color: green' #Set color to green for all rows to test
data_table = gviz_api.DataTable(description) # load description
data_table.LoadData(qset) # load dataset
我得到以下输出:
{"cols":[{"type":"date","id":"billing_date","label":"billing_date"},{"type":"number","id":"energy_kwh","label":"energy_kwh"},{"type":"string","p":{"role":"style"},"id":"zcolor","label":""}],"rows":[{"c":[{"v":"Date(2011,0,16)"},{"v":23150},{"v":"color: green"}]},{"c":[{"v":"Date(2011,1,10)"},{"v":126025},{"v":"color: green"}]},{"c":[{"v":"Date(2011,2,14)"},{"v":18675},{"v":"color: green"}]},{"c":[{"v":"Date(2011,3,11)"},{"v":19850},{"v":"color: green"}]},{"c":[{"v":"Date(2011,4,15)"},{"v":16400},{"v":"color: green"}]},{"c":[{"v":"Date(2011,5,13)"},{"v":19225},{"v":"color: green"}]},{"c":[{"v":"Date(2011,6,13)"},{"v":22400},{"v":"color: green"}]},{"c":[{"v":"Date(2011,7,15)"},{"v":22400},{"v":"color: green"}]},{"c":[{"v":"Date(2011,8,13)"},{"v":18150},{"v":"color: green"}]},{"c":[{"v":"Date(2011,9,18)"},{"v":17000},{"v":"color: green"}]},{"c":[{"v":"Date(2011,10,10)"},{"v":15875},{"v":"color: green"}]},{"c":[{"v":"Date(2011,11,12)"},{"v":7600},{"v":"color: green"}]},{"c":[{"v":"Date(2012,0,12)"},{"v":32850},{"v":"color: green"}]},{"c":[{"v":"Date(2012,1,13)"},{"v":7600},{"v":"color: green"}]},{"c":[{"v":"Date(2012,2,12)"},{"v":20925},{"v":"color: green"}]},{"c":[{"v":"Date(2012,3,19)"},{"v":18950},{"v":"color: green"}]},{"c":[{"v":"Date(2012,4,11)"},{"v":16400},{"v":"color: green"}]},{"c":[{"v":"Date(2012,5,12)"},{"v":18100},{"v":"color: green"}]},{"c":[{"v":"Date(2012,6,12)"},{"v":16975},{"v":"color: green"}]},{"c":[{"v":"Date(2012,7,14)"},{"v":24650},{"v":"color: green"}]},{"c":[{"v":"Date(2012,8,12)"},{"v":16475},{"v":"color: green"}]},{"c":[{"v":"Date(2012,9,12)"},{"v":17000},{"v":"color: green"}]},{"c":[{"v":"Date(2012,10,18)"},{"v":15625},{"v":"color: green"}]},{"c":[{"v":"Date(2012,11,11)"},{"v":1475},{"v":"color: green"}]},{"c":[{"v":"Date(2013,0,14)"},{"v":8225},{"v":"color: green"}]},{"c":[{"v":"Date(2013,1,12)"},{"v":9050},{"v":"color: green"}]},{"c":[{"v":"Date(2013,2,12)"},{"v":7250},{"v":"color: green"}]},{"c":[{"v":"Date(2013,3,11)"},{"v":18950},{"v":"color: green"}]},{"c":[{"v":"Date(2013,4,13)"},{"v":16375},{"v":"color: green"}]},{"c":[{"v":"Date(2013,5,12)"},{"v":18675},{"v":"color: green"}]},{"c":[{"v":"Date(2013,6,11)"},{"v":7600},{"v":"color: green"}]},{"c":[{"v":"Date(2013,7,13)"},{"v":10525},{"v":"color: green"}]},{"c":[{"v":"Date(2013,8,12)"},{"v":44850},{"v":"color: green"}]},{"c":[{"v":"Date(2013,9,10)"},{"v":32250},{"v":"color: green"}]},{"c":[{"v":"Date(2013,10,13)"},{"v":9600},{"v":"color: green"}]},{"c":[{"v":"Date(2013,11,11)"},{"v":15500},{"v":"color: green"}]},{"c":[{"v":"Date(2014,0,13)"},{"v":9600},{"v":"color: green"}]},{"c":[{"v":"Date(2014,1,12)"},{"v":7950},{"v":"color: green"}]},{"c":[{"v":"Date(2014,2,12)"},{"v":7775},{"v":"color: green"}]},{"c":[{"v":"Date(2014,3,16)"},{"v":7950},{"v":"color: green"}]},{"c":[{"v":"Date(2014,4,12)"},{"v":14675},{"v":"color: green"}]},{"c":[{"v":"Date(2014,5,24)"},{"v":15850},{"v":"color: green"}]},{"c":[{"v":"Date(2014,6,14)"},{"v":10225},{"v":"color: green"}]},{"c":[{"v":"Date(2014,9,1)"},{"v":10200},{"v":"color: green"}]},{"c":[{"v":"Date(2014,9,10)"},{"v":18100},{"v":"color: green"}]}]}
请注意,我遇到的问题是订单。具有该属性的列必须直接位于您正在绘制的数据列之后。我在文档的任何地方都找不到这个事实。
我主要使用https://developers.google.com/chart/interactive/docs/roles来帮助我解决问题。