[英]How can I set the lower bound on the x axis for a google chart?
I'm trying set the x range on a date based google bar chart.我正在尝试在基于日期的谷歌条形图上设置 x 范围。 I'd like the year of the chart to start at January 1, even though the data doesn't start until April.
我希望图表中的年份从 1 月 1 日开始,即使数据直到 4 月才开始。
I've seen a number of suggestions for how to set the min and max vertical range, but I could not make them work on the x axis.我已经看到了许多关于如何设置最小和最大垂直范围的建议,但我无法让它们在 x 轴上工作。 I don't know if the issue is the x-axis, or the fact that I'm using dates as my x axis.
我不知道问题是 x 轴,还是我使用日期作为 x 轴的事实。 I do get this error when I try to set a min
当我尝试设置分钟时,我确实收到此错误
"a.getTime is not a function" “a.getTime 不是函数”
Here's my working code, with no limits:这是我的工作代码,没有限制:
var data = new google.visualization.DataTable();
data.addColumn("date", "Season Start Date")
data.addColumn("number", "Acres Burned")
var options = {
"title": "US Fire data TBD!!!",
"hAxis": {
"title": "Year"
},
"vAxis": {
"title": "Total Acres Burned"
}
}
data.addRows([
[new Date(2021, 5, 12), 1000],
[new Date(2021, 5, 14), 400],
[new Date(2021, 5, 15), 0],
[new Date(2021, 5, 16), -39],
[new Date(2021, 5, 17), 165],
[new Date(2021, 5, 18), 0],
[new Date(2021, 5, 19), 1000],
[new Date(2021, 5, 20), 1000],
]);
var chart = new google.visualization.ColumnChart(document.getElementById("us_chart"))
chart.draw(data, options);
This code renders the error message ("a.getTime is not a function"), instead of the chart:此代码呈现错误消息(“a.getTime 不是函数”),而不是图表:
var options = {
"title": "US Fire data TBD!!!",
"hAxis": {
"title": "Year",
"viewWindowMode":"explicit",
"viewWindow": {
"min": "new Date(2021, 5, 1)",
"max": "new Date(2021, 8, 1)"
}
},
"vAxis": {
"title": "Total Acres Burned"
}
}
Any ideas?有任何想法吗?
Thanks!谢谢!
the min / max values for the axis should be dates, not strings.轴的最小值/最大值应该是日期,而不是字符串。
var options = {
"title": "US Fire data TBD!!!",
"hAxis": {
"title": "Year",
"viewWindow": {
"min": new Date(2021, 5, 1),
"max": new Date(2021, 8, 1)
}
},
"vAxis": {
"title": "Total Acres Burned"
}
}
and the following option isn't necessary...并且不需要以下选项...
"viewWindowMode":"explicit",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.