2015-01-14 3 views
0

Я создал диаграмму столбцов, используя aviz_api.py, python и django.Как использовать пользовательские свойства с диаграммами Google Python aviz_api.py

Однако я с настройкой свойств, которые изложены в неприятности: справки о https://developers.google.com/chart/interactive/docs/gallery/columnchart#ColumnStyles

aviz_api.py имеет, как представляется, имеет возможность задать свойства для определенных столбцов с помощью метода SetRowsCustomProperties (Row/Строки, пользовательской Имущество).

Я пробовал много вещей безрезультатно. График продолжает загружаться, но не применяет настраиваемое свойство. Вот моя последняя попытка:

data_table.SetRowsCustomProperties([1, {"role:style":"gold"}) 

при печати таблицы данных я получаю следующее:

{"rows":[{"c":[{"v":"Date(2011,0,16)"},{"v":23150}]},{"p":{"role:style":"gold"},..... 

Показывая, что свойство установлено значение, но я понятия не имею, как форматировать настраиваемое свойство , у кого есть идеи?

Edit:

Я нашел это: https://developers.google.com/chart/interactive/docs/roles#stylerole

, который, как представляется, указывают, что мне нужно, чтобы добавить "р": { "роль": "стиль"} к описанию data_table. Я сделал это со следующим:

description = {'energy_kwh': ('number','energy_kwh',{"role":"Style"}), 'billing_date': ('date','billing_date')} 

Это дало мне DataTable:

{"cols":[{"label":"billing_date","type":"date","id":"billing_date"},{"label":"energy_kwh","type":"number","id":"energy_kwh","p":{"role":"style"}}],"rows".... 

Но теперь карта не загружается вообще. Я начинаю задаваться вопросом, должно ли свойство идти с данными о горизонтальной оси. Я попробую это дальше.

ответ

0

Я решил эту проблему:

Я отправлю мое решение для других, так как я нашел, что это очень трудно найти:

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, чтобы помочь мне решить эту проблему.

Смежные вопросы