[英]Google Charts Y-Axis unsorted
I try to use Google Charts in one of my projects. 我尝试在我的一个项目中使用Google Charts。 Everything works pretty good, but my Y-Axis is completely unsorted.
一切正常,但我的Y轴完全未分类。
This is the actual code I use to display my chart: 这是我用来显示图表的实际代码:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', { 'packages': ['corechart', 'bar'] });
google.charts.setOnLoadCallback(function () {
var title = 'Total Sales By Market and Year';
var subtitle = 'Cincinnati, Cleveland, Columbus, and Dayton';
var dataTable = new google.visualization.DataTable(
{"cols":[{"label":"UsageDates","type":"string"},{"label":"C1","type":"string"},{"label":"C2","type":"string"},{"label":"C3","type":"string"},{"label":"C4","type":"string"}],"rows":[{"c":[{"v":"14.06.2016"},{"v":0},{"v":0},{"v":6},{"v":7}]},{"c":[{"v":"15.06.2016"},{"v":50},{"v":0},{"v":0},{"v":0}]},{"c":[{"v":"16.06.2016"},{"v":0},{"v":13},{"v":1},{"v":3}]},{"c":[{"v":"20.06.2016"},{"v":5},{"v":7},{"v":0},{"v":0}]}]}
);
drawBarChart('chart_div', title, subtitle, dataTable);
//drawColumnChart('chart', title, dataTable);
});
function drawColumnChart(elementId, title, dataTable) {
var options = {
title: title,
vAxis: { format: 'decimal' }
};
var chart = new google.visualization.ColumnChart(document.getElementById(elementId));
chart.draw(dataTable, options);
}
</script>
The result looks a bit strange, I think the values for the Y-Axis aren't sorted but are taken as they come in. 结果看起来有些奇怪,我认为Y轴的值不是排序的,而是在输入时采用的。
I hope someone can help me out on this.
我希望有人可以帮助我。
Try changing the cols
definitions for C1..C4 from "string" to "number" to match the data you provided. 尝试将C1..C4的
cols
定义从“字符串”更改为“数字”以匹配您提供的数据。
"cols":[{"label":"UsageDates","type":"string"},{"label":"C1","type":"number"},{"label":"C2","type":"number"},{"label":"C3","type":"number"},{"label":"C4","type":"number"}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.