简体   繁体   English

图表未显示

[英]Chart not displaying

I've tried the below code to display chart but for some reason its not working. 我试过下面的代码来显示图表,但由于某种原因它不起作用。 I tried to display chart with line chart, with different color points. 我试图显示带有不同色点的折线图。 I'm trying to create google line charts 我正在尝试创建Google折线图

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawLoadChart);
function drawLoadChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Length');
data.addColumn('number', 'Load');
data.addRows([
[Zero, 0],
[One, 1],
[Two, 2]
]);
var formatter = new google.visualization.NumberFormat({
fractionDigits: 3
});
formatter.format(data, 0);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, 1]); 
var options = {'width':400,'height':300,
title: 'Load vs Length',
titlePosition: 'out',
legend: {
position: 'none'
},
hAxis: {
title: 'Length (inch)',
viewWindow: {
min: 0
},
format: '#.000'
},
vAxis: {
title: 'Load (pound)',
viewWindow: {
min: 0
}
},
series: {
0: {
color: 'black',
lineWidth: 2
},
1: {
color: 'red',
lineWidth: 0,
pointSize: 5
}
}
};
var loadChart = new google.visualization.LineChart(document.getElementById('line_chart'));
loadChart.draw(view, options);
}
</script>
</head>
<body>
<div id='line_chart'></div>
</body>
</html>

The expected chart has the above 3 points but when I try with TryItEditor chart is not displaying. 预期的图表具有上述3点,但是当我尝试使用TryItEditor时,图表未显示。

Here in your code change 在您的代码更改中

data.addRows([
[Zero, 0],
[One, 1],
[Two, 2]
]);

to this 对此

data.addRows([
['Zero', 0],
['One', 1],
['Two', 2]
]);

Strings has to be specified with quotes. 字符串必须用引号指定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM