javascript 在 Google 图表 CandlestickChart 中使用 DateTime 而不是 Date

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10188114/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:58:23  来源:igfitidea点击:

Using DateTime instead of Date in Google chart CandlestickChart

javascriptgoogle-visualization

提问by Dax

I'm trying to use datetime instead of date to build chart using the Google-chart API.

我正在尝试使用日期时间而不是日期来使用 Google-chart API 构建图表。

Based on the sample from Google (sample)

基于来自谷歌的样本(样本

 var data = new google.visualization.DataTable();
    data.addColumn('date', 'Date');
    data.addColumn('number', 'Stock low');
    data.addColumn('number', 'Stock open');
    data.addColumn('number', 'Stock close');
    data.addColumn('number', 'Stock high');

 data.addRows([
                  [new Date(2008, 1 ,1), 1000, 1000, 1500, 2000],
                  [new Date(2008, 1 ,2), 500, 1000, 1500, 2500],
                  [new Date(2008, 1 ,3), 1000, 1000, 1500, 2000]
    ]);

I can play with dates, but I want to use date & hours, something like

我可以玩日期,但我想使用日期和时间,比如

data.addRows([
              [new Date(2008, 1 ,1, 00, 00, 00), 1000, 1000, 1500, 2000],
              [new Date(2008, 1 ,1, 01, 00, 00), 500, 1000, 1500, 2500],
              [new Date(2008, 1 ,1, 02, 00, 00), 1000, 1000, 1500, 2000]

]);

This give me the following output

这给了我以下输出

Any idea ?

任何的想法 ?

回答by gatoatigrado

To clarify Mark's answer, change your line

为了澄清马克的答案,改变你的路线

data.addColumn('date', 'Date');

to

data.addColumn('datetime', 'Time');

this seems to work for me.

这似乎对我有用。

回答by Mark Maxham

You want 'datetime', not 'date'.

你想要“日期时间”,而不是“日期”。