javascript 谷歌图表折线图小时和分钟
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12711667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Chart Line Chart hours and minutes
提问by user1717513
I'm trying to use Google's chart API to show a line chart.
I have created a data table with two columns, a date and a numeric value. The line is displayed correctly but the labels on the X axis are missing.
All the data are in the same day, but at different hours. If I edit the dates in order to spread them over different days everything works.
I need to focus my chart in one day only and show hours and minutes on the X axis.
How can I do that?
我正在尝试使用 Google 的图表 API 来显示折线图。
我创建了一个包含两列的数据表,一个日期和一个数值。该线显示正确,但 X 轴上的标签丢失。所有数据都在同一天,但在不同的时间。如果我编辑日期以将它们分布在不同的日子,一切正常。
我只需要在一天内聚焦我的图表并在 X 轴上显示小时和分钟。
我怎样才能做到这一点?
Thanks.
谢谢。
回答by ficuscr
Usually comes down to how you pass the data. With arrayToDataTable
your dates are just strings. If you instantiate a JS date object and build the dataTable
you should get better results. This code works for me (see it live):
通常归结为您如何传递数据。有了arrayToDataTable
您的日期仅仅是字符串。如果您实例化一个 JS 日期对象并构建它,dataTable
您应该会得到更好的结果。此代码适用于我(实时查看):
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Time of Day');
data.addColumn('number', 'Some Measurement');
data.addRows([
[new Date(2012,10,3,11,30,0), 12],
[new Date(2012,10,3,11,45,0), 2],
[new Date(2012,10,3,12,1,0), 16],
[new Date(2012,10,3,12,15,0), 3],
[new Date(2012,10,3,12,30,0), 12],
[new Date(2012,10,3,12,45,0), 7]
]);
new google.visualization.LineChart(document.getElementById('visualization')).
draw(data, {curveType: "function",
width: 500, height: 400,
vAxis: {maxValue: 10}}
);
}
I used to be a fan of Google Visualization but have been burned too many times by their unannounced updates. It also has a lot of limitations. Check out Dygraphwhich handles time series very well.
我曾经是 Google Visualization 的粉丝,但被他们的未宣布更新烧毁了太多次。它也有很多限制。查看可以很好地处理时间序列的Dygraph。
回答by user1477388
To focus my chart in one day only and show hours and minutes on the X axis.
you need to do this in your query. This doesn't have anything to do with Google Charts. You could look at the haxis parameters to see if you can change some of those values to achieve what you desire https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart
为了focus my chart in one day only and show hours and minutes on the X axis.
你需要做这在您的查询。这与 Google Charts 没有任何关系。您可以查看 haxis 参数,看看是否可以更改其中一些值以实现您想要的https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart