Discuss Python and Google Chart Tool - Help in the Python Programming forum on Dev Shed. Python and Google Chart Tool - Help Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 4
Time spent in forums: 56 m
Reputation Power: 0
Python and Google Chart Tool - Help
Hello, I'm new to Python and was tinkering around with Google Chart Tools. Really cool! I'm able to use the below python code to create some html that populates a nice table chart. My question is, how would I convert the chart type to something else, say a pie chart? I would appreciate examples if any has them. Thank you.
Code:
import gviz_api
page_template = """
<html>
<head>
<title>Static example</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script>
google.load("visualization", "1", {packages:["table"]});
google.setOnLoadCallback(drawTable);
function drawTable() {
%(jscode)s
var jscode_table = new google.visualization.Table(document.getElementById('table_div_jscode'));
jscode_table.draw(jscode_data, {showRowNumber: true});
var json_table = new google.visualization.Table(document.getElementById('table_div_json'));
var json_data = new google.visualization.DataTable(%(json)s, 0.5);
json_table.draw(json_data, {showRowNumber: true});
}
</script>
</head>
<body>
<H1>Table created using ToJSCode</H1>
<div id="table_div_jscode"></div>
<H1>Table created using ToJSon</H1>
<div id="table_div_json"></div>
</body>
</html>
"""
def main():
# Creating the data
description = {"name": ("string", "Name"),
"salary": ("number", "Salary"),
"full_time": ("boolean", "Full Time Employee")}
data = [{"name": "Mike", "salary": (10000, "$10,000"), "full_time": True},
{"name": "Jim", "salary": (800, "$800"), "full_time": False},
{"name": "Alice", "salary": (12500, "$12,500"), "full_time": True},
{"name": "Bob", "salary": (7000, "$7,000"), "full_time": True}]
# Loading it into gviz_api.DataTable
data_table = gviz_api.DataTable(description)
data_table.LoadData(data)
# Creating a JavaScript code string
jscode = data_table.ToJSCode("jscode_data",
columns_order=("name", "salary", "full_time"),
order_by="salary")
# Creating a JSon string
json = data_table.ToJSon(columns_order=("name", "salary", "full_time"),
order_by="salary")
# Putting the JS code and JSon string into the template
print page_template % vars()
if __name__ == "__main__":
main()
Posts: 4
Time spent in forums: 56 m
Reputation Power: 0
Thanks but that is not helpful. I'm just trying to understand the concept of presenting the data in a different format. I don't care if it's a pie chart or histogram. I just don't want to present it in a table.
Posts: 4
Time spent in forums: 56 m
Reputation Power: 0
Thanks I have read these documents. I'm new to Python and can honestly say it's hard to follow a lot of this material with my lack of experience.This exercise is for my own educational purpose.
I copied and pasted the example by gziv because it works. I know how I can make a barchart (or whatever) using just html/java but don't know how to get it to populate from source inside of Python like the gziv example.