谷歌图表检索与ajax
Google Chart retrieve with ajax
目前我能够得到响应,但我不确定如何检索和设置数据。
当我调试jsonData时,它们将显示:https://gyazo.com/088664e92099686e7509a2fe7b483364https://gyazo.com/ef8af2f64fe7fd93743fc1933ea63817
当我调试jsonData responseText时,它们将显示"object JSON"
<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "Reports/reportDetail",
data: "cat_id=" + $("#cat").val(),
dataType:"json",
cache: false //Always false.
});
console.log(jsonData);
var res = jsonData.responseText;
var data = new google.visualization.DataTable(res);
console.log(data);
var data = new google.visualization.DataTable();
data.addColumn('string', 'Hours');
data.addColumn('number', 'South');
data.addColumn('number', 'South-East');
data.addColumn('number', 'North-East');
data.addColumn('number', 'North');
data.addRows([
]);
var options = {
chart: {
title: 'Time Interval during the Event',
subtitle: 'Number Of People'
},
width: 1000,
height: 600
};
var chart = new google.charts.Line(document.getElementById('linechart_material'));
chart.draw(data, options);
}
</script>
调试数据时它们显示如下:https://gyazo.com/125a7049606c51f0f47569a84679f81c
试试下面的代码,这里res[i].value1
, res[i].value2
等将是JSON对象返回的各自的属性。
<script type="text/javascript">
google.load('visualization', '1.1', { packages: ['line'] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "Reports/reportDetail",
data: "cat_id=" + $("#cat").val(),
dataType: "json",
cache: false //Always false.
});
console.log(jsonData);
var res = jsonData.responseText;
if (res != null) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Hours');
data.addColumn('number', 'South');
data.addColumn('number', 'South-East');
data.addColumn('number', 'North-East');
data.addColumn('number', 'North');
for (var i = 0; i < res.length; i++) {
data.addRow([res[i].value1, res[i].value2, res[i].value3, res[i].value4, res[i].value5]);
}
var options = {
chart: {
title: 'Time Interval during the Event',
subtitle: 'Number Of People'
},
width: 1000,
height: 600
};
var chart = new google.charts.Line(document.getElementById('linechart_material'));
chart.draw(data, options);
}
}
</script>
相关文章:
- 为什么jqPlot显示了一个错误的饼图,其中包含通过AJAX检索的数据
- 页面刷新后重新加载 ajax 检索到的数据
- 通过 AJAX 检索 Blob 时处理错误消息
- 从开放的外部API-visual studio-AJAX检索值
- 如何使用Ajax检索和存储数据
- 将 AJAX 检索到的 JSON 推送到数据表中
- JQuery:参数:硬编码字符串与 ajax 检索到的字符串
- 使用 php 从 ajax 检索已发布的数据
- 如何在特定的时间跨度使用 AJAX 检索 php 表单
- AJAX 检索 xml 响应
- 无法使用 PHP 和 AJAX 检索 + 字符
- Javascript 表单提交 prevent默认在使用 AJAX 检索表单时不起作用
- 从 AJAX 检索到的对象列表中打印特定属性
- 将 HTML 放在 Javascript 源代码中或使用 AJAX 检索 HTML
- php&ajax检索post数据失败
- 尝试打开从ajax检索到的数据以自动下载
- 使用jQuery AJAX检索数据而不在php中重新加载页面
- 使用ajax检索数据网格
- 无法从Twitter (AJAX)检索数据
- 使用AJAX检索HTML下拉列表值