Dear Raj, Unfortunately that i know nothing about python :) sorry, i'm glad that i helped you i wish your charts worked with php and mysql - i ran throw this because i wanted to connect php with oracle database so to make charts for old ages products for my company, but listen you can ask your question on stackoverflow.com and you will get better answers there trust me and you can use my question as a reference and put your code with it and choose your tags wisely.
I think your trying to make a nested loop throw python without the need to use php and json right? i can help you with the logic i guess- first loop that loops throw keys and inside of it the second loop that retrieve all values for every key, idk :/ i tried to do this but in php, check this link too this is another solution it may help you .. http://stackoverflow.com/questions/29969054/google-charts-from-mysql/30255703#30255703 Regards, Hisham On Thursday, June 25, 2015 at 1:30:22 AM UTC+3, Raj wrote: > > Hi Hisham, > > Thanks for your link. I was wondering if we can take Google chart input > from python dictionary and dump Google visualization code in python. I did > go through Json and PHP. I am totally new to both languages. I am still > figuring out if I can make this happen without touching JSON and PHP. And > just go with python dictionary. > > *My Python code that gives dictionary output after connecting to the > database* > > > import sys, pkg_resources, imp > import os > import commands > import pyodbc > import MySQLdb > import gviz_api > from decimal import * > from datetime import * > import datetime > import time > #Connect to database > conn_ensdb = MySQLdb.Connection(db='******', host='*****', user='*****', > passwd='******') > cursor_ensdb = conn_ensdb.cursor() > cursor_ensdb.execute("SELECT ManagedType,TotalCount from TotalManaged_DC") > rows = cursor_ensdb.fetchall() > my_list = [data for data in rows] > dict_with_strs=dict(my_list) > dict_with_ints=dict((k,int(v)) for k,v in dict_with_strs.iteritems()) > print dict_with_ints > > > My Output:- > {'Off-prem Core Data Center': 4, 'On-prem Remote Office DC': 14, 'On-prem > Core Data Center': 7, 'Total Managed Data Centers': 25} > > > > > I want this output to be input for Google charts:-//I will integrate this > html code in my python file > > This is an example Bar chart using Google Visualization > > > <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(drawStuff); > > function drawStuff() { > var data = new google.visualization.arrayToDataTable([ > > //want my dictionary items in here. Graph is Dictionary Keys vs Vs > Dictionary Values > *['Galaxy', 'Distance', 'Brightness'], * > *['Canis Major Dwarf', 8000, > 23.3], * > *['Sagittarius Dwarf', 24000, 4.5],* > *['Ursa Major II Dwarf', 30000, 14.3],* > *['Lg. Magellanic Cloud', 50000, 0.9],* > *['Bootes I', 60000, 13.1]* > ]); > > var options = { > width: 900, > chart: { > title > ... -- 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.
