There are a few things to fix here:
1) load the "controls" package instead of the "corechart" package
2) this line:
var dashboard = new
google.visualization.PieChart(document.getElementById('dash_div'));
creates a PieChart, not a Dashboard, change it to this:
var dashboard = new
google.visualization.Dashboard(document.getElementById('dash_div'));
3) the Value column is type "number", but you are entering all of the
values as strings, which will cause the PieChart to draw incorrectly.
Typecast the output from your database with the (int) or (float) operator
(depending on the type of the number) to make it enter as a number:
$a = "3"; // string "3"
$b = (int) $a; // integer 3
See a working version here: http://jsfiddle.net/asgallant/sLrhg/
On Friday, April 12, 2013 5:16:11 AM UTC-4, kolo ken wrote:
>
> yes, i have a CategoryFilter,but the result shows blank page
>
> source from php
> {"cols":[{"label":"Item","type":"string"},{"label":"Type","type":"string"},{"label":"Value","type":"number"}],"rows":[{"c":[{"v":"A"},{"v":"Very
>
> Good"},{"v":"80"}]},{"c":[{"v":"A"},{"v":"Good"},{"v":"70"}]},{"c":[{"v":"A"},{"v":"Not
>
> Good"},{"v":"50"}]},{"c":[{"v":"B"},{"v":"Very
> Good"},{"v":"85"}]},{"c":[{"v":"B"},{"v":"Good"},{"v":"77"}]},{"c":[{"v":"B"},{"v":"Not
>
> Good"},{"v":"40"}]},{"c":[{"v":"C"},{"v":"Very
> Good"},{"v":"90"}]},{"c":[{"v":"C"},{"v":"Good"},{"v":"70"}]},{"c":[{"v":"C"},{"v":"Not
>
> Good"},{"v":"44"}]}]}
>
> goo3.html
> <!DOCTYPE html>
> <html>
> <head>
> <link rel="stylesheet" type="text/css" href="tryit.css" />
> <meta charset="utf-8">
> <script type="text/javascript" src="http://www.google.com/jsapi
> "></script>
> <script src="//
> ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
>
> <script type="text/javascript">
> google.load('visualization', '1', {packages: ['corechart']});
> google.setOnLoadCallback(drawChart);
>
> function drawChart() {
> var jsonData =$.ajax({
> url: "Item.php",
> dataType:"json",
> async: false
> }).responseText;
>
> var data = new google.visualization.DataTable(jsonData);
> var columnsTable = new google.visualization.DataTable();
> columnsTable.addColumn('number', 'colIndex');
> columnsTable.addColumn('string', 'colLabel');
> var initState= {selectedValues: []};
> // put the columns into this data table (skip column 0)
> for (var i = 2; i < data.getNumberOfColumns(); i++) {
> columnsTable.addRow([i, data.getColumnLabel(i)]);
> initState.selectedValues.push(data.getColumnLabel(i));
> }
>
> var chart = new google.visualization.ChartWrapper({
> chartType: 'PieChart',
> containerId: 'chart_div',
> options: {
> title: 'Percentage',
> width: 750,
> height: 400
> },
> view: {
> columns: [1,2]
> }
> });
>
> var ItemFilter = new google.visualization.ControlWrapper({
> controlType: 'CategoryFilter',
> containerId: 'ItemFilter_div',
> options: {
> filterColumnLabel: 'Item',
> ui: {
> label: 'Item',
> allowTyping: false,
> allowMultiple: false,
> selectedValuesLayout: 'belowStacked'
> }
> }
> });
>
> var dashboard = new
> google.visualization.PieChart(document.getElementById('dash_div'));
> dashboard.bind([ItemFilter], [chart]);
> dashboard.draw(data);
> }
> </script>
> </head>
> <body style="font-family: Arial;border: 0 none;">
> <div id="dash_div">
> <div id="ItemFilter_div" style="float: left;"></div>
> <div style="clear: both;"></div>
> <div id="chart_div"></div>
> </div>
> </body>
> </html>
>
--
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.