3

我需要为我的 hAxis 设置时间范围,使其 minValue 为 09:00,maxValue 为 17:00,增量为 1 小时(即 9、10、11、12、13、14、...、17)

目前我的数据格式为 H:m(例如:09:35、10:20)

var formatter3 = new google.visualization.DateFormat({pattern: 'H:m'});
formatter3.format(data,0); 

以下是我的选择:

var options = {           
            curveType: "function",
            title : '',           
            hAxis:{slantedTextAngle: 90,textStyle:{fontSize:8}},
            colors : ['red','#3366CC', '#999999'],
            vAxes: {
                0: {logScale: false, format:'0.0000'},
                1: {logScale: false}
            },
            hAxis: { 
                           format: 'H:m',
                           minValue: new Date(null, null, null, 9, 0, 0),
                           maxValue: new Date(null, null, null, 17, 0, 0),         
                           viewWindow:{min: new Date(null, null, null, 9, 0, 0),
                                       max: new Date(null, null, null, 17, 0, 0)},
            series: { 
                0: {targetAxisIndex:0, type: "line"},
                1: {targetAxisIndex:0, type: "line"},
                2: {targetAxisIndex:1, type: "bars"}
            }         
        };

但是,它仍然无法正常工作。请指教。谢谢!

4

1 回答 1

2

Unfortunately, the minValue, maxValue, and baseline value are ignored for date and time values. I am not sure that this is a recent bug but I just noticed it a week ago. You might try to experiment with the viewWindow min and max, and the gridlines.count option to get the desired result. Or you might be able to convert all your date values to strings, if the values are evenly spaced, in which case axes will use your explicit values.

Another new feature that could work for you is that you can provide an explicit array of tick values, with a ticks: [...] option. In the current release of gviz, the formatting is done using your format option, and that should be enough for your needs. In an upcoming release, you can also specify the formatting of each tick value.

So it might be best to specify the times in your example using timeofday values like so:

hAxis: {
  ticks: [[9, 0, 0], [10, 0, 0], [11, 0, 0], [12, 0, 0], ...]
}

I think you could do the same kind of thing with datetime values instead, if that's what your data values are.

于 2013-06-19T14:49:48.303 回答