【发布时间】:2018-10-16 05:20:49
【问题描述】:
我是 JavaScript 新手。我试图让滚动为谷歌线图工作,但我得到的只是一个静态图,没有滚动。我正在使用我在以下链接中找到的示例,该示例适用于示例中定义的数据集,但是当我尝试从 CSV 文件加载数据时,则只是静态图。
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="jquery.csv.js"></script>
<script type="text/javascript">
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(BasicLine);
function BasicLine()
{
$.get("mil.csv", function(csvString)
{
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar}),
data = new google.visualization.arrayToDataTable(arrayData),
options = {
hAxis:
{
title: 'Date'
},
vAxis:
{
title: 'Total'
},
backgroundColor: '#f1f8e9',
lineWidth: 0.7,
chartArea:{width:'100%',height:'100%'},
vAxis: {
minValue: 0
},
explorer: {
axis: 'horizontal',
keepInBounds: true,
maxZoomIn: 4.0
},
},
chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}, 'text');
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
CSV 文件(前 20 行)
Date,Total
9-Oct-17,103173
10-Oct-17,103377
11-Oct-17,103903
12-Oct-17,103644
13-Oct-17,103511
14-Oct-17,103511
15-Oct-17,103511
16-Oct-17,103541
17-Oct-17,103636
18-Oct-17,103868
19-Oct-17,104419
20-Oct-17,104770
21-Oct-17,104770
22-Oct-17,104770
23-Oct-17,104748
24-Oct-17,104986
25-Oct-17,104994
26-Oct-17,105246
27-Oct-17,105424
【问题讨论】:
-
感谢您的回复。我已经用我的 csv 文件的前 20 行更新了问题
标签: javascript charts google-visualization