hi all,

I am writing a python script that connects to MySQL database and gets data 
and I store that data as python dictionary. I want to plot a graph between 
keys and values using Google Visualization api. 
Here's the code as well. How to parse the python dictionary into gviz data 
table? 



#!/usr/bin/python
import sys, pkg_resources, imp
import commands
import pyodbc
import MySQLdb
import gviz_api

#Connect to ens-db, database circuits
conn_ensdb = MySQLdb.Connection(db='NHS_db', host='ens-db', user='asdgghh', 
passwd='ilthnmk')
cursor_ensdb = conn_ensdb.cursor()
cursor_ensdb.execute("SELECT ManagedType,TotalCount from TotalManaged_DC")
rows = cursor_ensdb.fetchall()

#converting tuple output to dictionary format
my_list = [data for data in rows]
dict_with_strs=dict(my_list)                                                    
                                                                     
//Output of dictionary will be:- {'Center': 4, ' Office ': 14, ' Core Data 
': 7, 'Managed ': 25}
dict_with_ints=dict((k,int(v)) for k,v in dict_with_strs.iteritems())

print ""

print '''
<html>
  <head>
    <script type="text/javascript" src="
https://www.google.com/jsapi";></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = 
google.visualization.arrayToDataTable([                                         
                              
//I want to parse this dictionary into data table. Plot Google charts 
between dict keys vs dict values .How can I pass dict ?
        ]);
        var options = {
          chart: {
            title: 'Company Performance',
          },
          bars: 'horizontal' // Required for Material Bar Charts.
        };
        var chart = new 
google.charts.Bar(document.getElementById('barchart_material'));
        chart.draw(data, options);
      }
    </script>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to