0
我一直在寻找利用实时客户端数据从谷歌图表填充图表的可能性。我尝试过向后端发送请求的解决方案,但我希望将此端与客户端环境分开,并且API目前仍在开发中。带有客户端数据填充的谷歌图表
这是一个标准的饼图
//JS Code
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
//HTML Code
<div id="chart_div"></div>
示例代码有没有办法从正在显示与jQuery甚至纯JavaScript表中检索数据来填充谷歌图表?我想这将是这个样子:
data.addRows([
[$('#textfield1').getAttribute('value'), 3],
[$('#textfield2').getAttribute('value'), 1],
[$('#textfield3').getAttribute('value'), 1],
[$('#textfield4').getAttribute('value'), 1],
[$('#textfield5').getAttribute('value'), 2]
]);
有没有人有经验,在尝试此,甚至不知道它是否有可能?
欣赏任何输入!
感谢您的回复!它像一个魅力。 –