【发布时间】:2019-12-01 17:44:15
【问题描述】:
我想在我的网站上实现这个漂亮的日历图表。
https://developers-dot-devsite-v2-prod.appspot.com/chart/interactive/docs/gallery/calendar
假设客户端在页面加载时执行 ajax 请求,服务器从数据库中查询数据并以 JSON 格式的多维数组进行响应。
如何循环更新地图?
<script>
google.charts.load("current", {packages:["calendar"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'date', id: 'Date' });
dataTable.addColumn({ type: 'number', id: 'Won/Loss' });
dataTable.addRows([
[ new Date(2012, 3, 13), 37032 ],
[ new Date(2012, 3, 14), 38024 ],
[ new Date(2012, 3, 15), 38024 ],
[ new Date(2012, 3, 16), 38108 ],
[ new Date(2012, 3, 17), 38229 ],
// Many rows omitted for brevity.
[ new Date(2013, 9, 4), 38177 ],
[ new Date(2013, 9, 5), 38705 ],
[ new Date(2013, 9, 12), 38210 ],
[ new Date(2013, 9, 13), 38029 ],
[ new Date(2013, 9, 19), 38823 ],
[ new Date(2013, 9, 23), 38345 ],
[ new Date(2013, 9, 24), 38436 ],
[ new Date(2013, 9, 30), 38447 ]
]);
var chart = new google.visualization.Calendar(document.getElementById('calendar_basic'));
var options = {
title: "Red Sox Attendance",
height: 950,
};
chart.draw(dataTable, options);
}
</script>
【问题讨论】:
-
您能否详细说明...。所以,您不想像上面的示例那样添加硬编码数据,而是希望发出 ajax 请求,并将该数据填充到图表中?
标签: javascript charts google-visualization