动态变化 - Google图表类型 [英] Dynamic Change - Google Chart Type
本文介绍了动态变化 - Google图表类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
取决于选择类型,应显示图表。我准备了JSON。但我需要动态更改图表类型。
Depends on the select type, the chart should display. I prepared JSON. But I need to change chart type dynamically.
我尝试了不同的方式。但是得到了一个错误。是否有任何替代解决方案可用于履行此senorio。
I tried differently. But got an error. Is there any alternative solution is available to fulfil this senorio.
JS代码:
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
.......
var chartType = document.getElementById("chartType").value;
var chartTypeContent = "new google.visualization." + chartType + "(document.getElementById('chart_div'))";
var chart = chartTypeContent ;
chart.draw(data, options_fullStacked);
}
HTML代码:
<select id="chartType" onchange="drawChart()">
<option value="ColumnChart">Column Chart</option>
<option value="BarChart">Bar Chart</option>
</select>
错误是:未捕获TypeError:chart.draw不是函数
我是谷歌排行榜的新手。请帮我解决这个问题。
I'm new to google chart. Please help me solve this issue.
推荐答案
试试这样......
try it like this...
var chartTypeContent = new google.visualization[chartType](document.getElementById('chart_div'));
这篇关于动态变化 - Google图表类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文