简体   繁体   English

如何在谷歌图表中动态编辑表格?

[英]How to make a table editable dynamically in google charts?

I have created a table using DataTable in google charts. 我在谷歌图表中使用DataTable创建了一个表格。 and also creating a pie chart using the table data. 并使用表格数据创建饼图。

I need to update/modify the table data dynamically on the browser and need to update the chart accordingly. 我需要在浏览器上动态更新/修改表数据,并需要相应地更新图表。

Please let me know how to make a table editable in the browser using google charts ? 请告诉我如何使用谷歌图表在浏览器中编辑表格?

Thanks in advance 提前致谢

the data can be modified by using one of the available methods 可以使用其中一种可用方法修改数据

such as setValue 比如setValue
data.setValue(rowIndex, columnIndex, newValue);

anytime the data is changed, the chart must be re-drawn 无论何时更改data都必须重新绘制chart

see following working snippet, after the initial draw, 在初始抽奖后,请参阅以下工作片段,
the data values are doubled and drawn again... 数据值加倍并再次绘制......

 google.charts.load('current', { callback: function () { var container = document.getElementById('chart_div'); var chart = new google.visualization.PieChart(container); var data = google.visualization.arrayToDataTable([ ['Task', 'Hours'], ['A', 2], ['B', 4], ['C', 6], ['D', 8], ['E', 10], ['F', 12], ['G', 14] ]); var options = { height: 400, chartArea: { top: 24 }, legend: 'top', pieHole: 0.4, pieSliceText: 'value', width: 400 }; google.visualization.events.addOneTimeListener(chart, 'ready', function () { // edit data for (var i = 0; i < data.getNumberOfRows(); i++) { // double values data.setValue(i, 1, data.getValue(i, 1) * 2); } chart.draw(data, options); }); chart.draw(data, options); }, packages: ['corechart'] }); 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM