【发布时间】:2016-10-13 14:24:36
【问题描述】:
我一直在研究具有日期轴的 Google 折线图。我注意到轴标签的刻度由网格线的数量决定,并且与我传递的数据不同。有人可以告诉我如何强制轴标签与我传递的数据同步。 请找到小提琴的链接:https://jsfiddle.net/FarhanI/5ga6xu44/
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Time of Day');
data.addColumn('number', 'Rating');
data.addRows([
[new Date(2015, 0, 1), 5],
[new Date(2015, 0, 7), 3],[new Date(2015, 0, 14), 3], [new Date(2015, 0, 21), 2],[new Date(2015, 0, 28), 8],
]);
var options = {
title: 'Rate the Day on a Scale of 1 to 10',
width: 900,
height: 500,
hAxis: {
format: 'M/d/yy',
gridlines: {count: 9}
},
vAxis: {
gridlines: {color: 'none'},
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
var button = document.getElementById('change');
button.onclick = function () {
// If the format option matches, change it to the new option,
// if not, reset it to the original format.
options.hAxis.format === 'M/d/yy' ?
options.hAxis.format = 'MMM dd, yyyy' :
options.hAxis.format = 'M/d/yy';
chart.draw(data, options);
};
}
我还试图让网格线显示为 y 轴,因为我无法使用折线图获得 Y 轴。我尝试将网格线指定为 1,但我也只能在 X 轴的中间获得 1 条网格线。
有人可以告诉我是否可以使用折线图获得 Y 轴。
感谢您的帮助, 法尔汉。
【问题讨论】:
标签: charts google-visualization