I'm having the issue in my .jsp page, where I get my data from a MySQL
Database then put it as a Javascript Object.
I then want to display those objects , in this case names and integers to
produce a chart, but when I produce it my chart data is off.
<html>
<head>
<script type="text/javascript">
var theData = [ // Start of JavaScript data object
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root",
"nbuser");
PreparedStatement ps = con.prepareStatement("SELECT
department,SUM(cores) FROM project.booking GROUP BY department;");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
%>
[" <%= rs.getString(1)%>","<%= rs.getInt(2) %>"],
<%
};
// End of JavaScript object holding the data
%>
];
</script>
<script type="text/javascript"
src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable(
{
cols: [{id: '1', label: 'Department', type: 'string'},
{id: '4', label: 'Cores', type: 'number'},
{id: '5', label: 'Disk Space', type: 'number'}],
rows: [{c:[{v: 1}, {v: 2}]}
]
}
)
var options = {
title: 'Initial graph test'
};
var chart = new
google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
<a href="/ProjectAndBackend/System?action=livecharts">Live
Charts</a>
</body>
</html>
How do I correctly pass data in to the google charts from the MySQL data
I've previously accumulated
First post on this group so I hope I'm not out of context
Thanks
--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.