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: 'Nearby galaxies',
subtitle: 'distance on the left, brightness on the right'
},
bars: 'horizontal', // Required for Material Bar Charts.
series: {
0: { axis: 'distance' }, // Bind series 0 to an axis named
'distance'.
1: { axis: 'brightness' } // Bind series 1 to an axis named
'brightness'.
},
axes: {
x: {
distance: {label: 'parsecs'}, // Bottom x-axis.
brightness: {side: 'top', label: 'apparent magnitude'} // Top
x-axis.
}
}
};
var chart = new google.charts.Bar(document.getElementById('dual_x_div'
));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="dual_x_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Any help on this? Thanks.
Raj
~
On Wed, Jun 24, 2015 at 3:13 PM, 'Hisham Alkilani' via Google Visualization
API <[email protected]> wrote:
> Hello Raj,
>
> Check this link: i think it will help you...
> http://stackoverflow.com/questions/30146385/draw-a-column-chart-using-google-charts-for-this-json-var-dump-data
> <http://stackoverflow.com/questions/30146385/draw-a-column-chart-using-google-charts-for-this-json-var-dump-data>
>
> Best Regards,
> Hisham
>
>
> On Thursday, June 25, 2015 at 12:46:24 AM UTC+3, Raj wrote:
>>
>> Hi Asgallant and Ms.Gupta,
>>
>> I am trying to pull data from MySQL db. Now that I pulled my data and
>> have it as dictionary( Python). I want to plot a Google graph for
>> Dictionary Keys VS Dictionary Values. How can I pull my data from
>> dictionary to plot it as google graph using ChatWrapper Function or
>> Function Drawtable. I am looking for Bar graph. Are you guys active? Can
>> you guys help?
>>
>> Thanks.
>> Raj
>>
>>
>> On Tuesday, July 26, 2011 at 12:24:36 PM UTC-7, GerBen wrote:
>>
>>> Hello Colleagues,
>>> How can I read data from an external database (say, MS SQL Server or
>>> MySQL) and show it in a Google Chart?
>>> Thank you.
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Google Visualization API" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-visualization-api/UdOFybnvFo0/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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.
>
--
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.