I am having trouble propagating custom_properties, such as color, to my google diagram through the python gviz_api layer.
I would like to create a histogram with individually colored stripes, for example, in the example: https://developers.google.com/chart/interactive/docs/gallery/barchart#BarStyles
But I cannot figure out how to configure this for gviz_api ( http://code.google.com/p/google-visualization-python/ ).
I perfectly write data in any case, dictionaries, lists, stupids, one line at a time, while I can color the strips separately. Here is my last failed attempt, generate.py:
import gviz_api def main(): # Creating the data description = {"test" : ("string", "Test name"), "duration" : ("number", "Duration")} data = [dict(test="test A", duration=1000, custom_properties={"role":"color:green"}), {"test": "test B", "duration": 4000}] # Loading it into gviz_api.DataTable data_table = gviz_api.DataTable(description, custom_properties={"role":"style"}) data_table.LoadData(data) # Creating a JSon string json = data_table.ToJSon(columns_order=("test", "duration"), order_by="test") # Read page_template from file f = open('template.html', 'r') page_template = f.read() # Putting the JSon string into the template print page_template.format(json) if __name__ == '__main__': main()
And the corresponding .html template:
<html> <script src="https://www.google.com/jsapi" type="text/javascript"></script> <script> google.load('visualization', '1', {{packages:['corechart']}}); google.setOnLoadCallback(drawChart); function drawChart() {{ var options = {{ title: 'Test results', legend: 'none', chartArea: {{ width: "50%", height: "70%" }} }} var json_chart = new google.visualization.BarChart(document.getElementById('chart_div')); var json_data = new google.visualization.DataTable({0}, 0.6); json_chart.draw(json_data, options); }} </script> <body> <div id="chart_div"></div> </body> </html>