javascript - Google pie chart data table values -
Google website has a code for creating pie charts:
google.load (" Visualization "," 1 ", {Package: [" Corechart "]}); Google.setOnLoadCallback (drawChart); Function drawChart () {var data = google.visualization.arrayToDataTable ([['work', 'hour per day'], ['work', 11], ['eat', 2], ['commute', 2] , ['Clock TV', 2], ['sleep', 7]]); Var option = {title: 'my daily actions'}; Var chart = new google.visualization.PieChart (document.getElementById ('piechart')); Chart.draw (data, options); I have a global conflict which I would like to set it to value, and for example would like to introduce a new value in the chart:
var tmp = MyGlobalVariable 10; google.load ("visualization", "1", {package: ["corechart"]}); Google.setOnLoadCallback (drawChart); Function drawChart () {var data = google.visualization.arrayToDataTable ([['Task', 'Hour per day'], ['Work', TMP], ['et', 3], ['Commute', 2] , ['Clock TV', 2], ['sleep', 7]]); Every time I use TMP Var, it terminates 'work' from the chart. The Google Chart Library provides a SVG from a dataset.
If you want to change STVG, then you have to 'redraw (draw chart)' chart.
A small example (Unchester, too many times):
window.mychart = {data: [['task', 'hour per day'], [' '' My Daily Activities '' ['Kha', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep', 7]], }, Chart: empty, init: function (elId) {this.chart = new google.visualization.PieChart (document.getElementById (LID)); This.drawChart (); }, drawChart: function () {this.chart.draw (this.data, this.options); }}; Usage:
google.load ("visualization", "1", {package: ["corechart"]}); MyChart.init ('my-chart-id') google.setOnLoadCallback (myChart.drawChart); Then you want to change some data:
mychart.data ['work'] = 10; mychart.drawChart ();
Comments
Post a Comment