【发布时间】:2011-08-15 17:31:03
【问题描述】:
如果它是一个单独的 JSON 文件,我如何检索和使用谷歌图表的数据集?我尝试了 jQuery getJSON 但无法正常工作.. Google Viz 应该使用 JSON 来绘制条形图 有原生的谷歌 API 方式吗?或者我可以找到一种使用 jQuery 的方法吗? 谢谢
// 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', 'Products');
data.addColumn('number', 'Automated');
data.addRows([
['Product 1', 85],
['Product 2', 75],
['Product 3', 90],
['Product 4', 40],
['Product 5', 40]
]);
// Set chart options
var pie_options = {'title':'How Much Automated our Products are?',
'width':520,'height':300
};
var bar_options ={'width': 620, 'height': 300,
'title': 'Products',
'hAxis': {'title': '% Automated', 'titleTextStyle': {'color': 'red', 'fontSize': 16}}
}
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('piechart_div'));
chart.draw(data, pie_options);
var chart = new google.visualization.ColumnChart(document.getElementById('barchart_div'));
chart.draw(data, bar_options);
}
【问题讨论】:
-
您能否尽可能多地发布您的代码,以便我们有效地帮助您?
标签: javascript jquery ajax google-visualization