简体   繁体   English

在x轴上的dateTime的最大间隔最大间隔?

[英]Highcharts max interval for dateTime in x-axis?

I have a daily graph, spanning across 00:00 to 23:59. 我有一个每日图表,跨越00:00到23:59。 but for live data, let's say currently is 9AM, by default it will stretch the graph from 00:00 - 09:00, which doesn't look nice to me. 但是对于实时数据,假设当前是9AM,默认情况下它将从00:00到09:00拉伸图形,这对我来说不太好看。 What I want is the x-axis max at 23:59 of the same day, so it will show 09:00 - 23:59 as blank. 我想要的是同一天23:59的x轴最大值,因此它将显示为09:00 - 23:59为空白。 I tried $graph["xAxis"]["max"] = (time()+86400)*1000 but without avail. 我试过$graph["xAxis"]["max"] = (time()+86400)*1000但没有用。 any suggestion? 有什么建议吗? thanks! 谢谢!

(Although this is an old question, I came here using google search and it is still very much at the top of search results when searching for max time for x axis in highcharts, so I think this comment is still useful.) (虽然这是一个老问题,我使用谷歌搜索来到这里,在搜索highcharts中x轴的最大时间时,它仍然是搜索结果的顶部,所以我认为这个评论仍然有用。)

The accepted answer may be true for older versions of highcharts, but in the current version (v3.0.7) you can also set the xAxis.max attribute to the datetime you want the graph to end on. 对于旧版本的highcharts,接受的答案可能是正确的,但在当前版本(v3.0.7)中,您还可以将xAxis.max属性设置为您希望图表结束的日期时间。 This would look like this, and is IMO a way cleaner solution: 这看起来像这样,IMO是一种更清洁的解决方案:

$(function () {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container'
        },
        xAxis: {
            type: 'datetime',
            max: Date.UTC(2010, 0, 2),
            dateTimeLabelFormats: {
                day: '%e of %b'   
            }
        },

        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6],
            pointStart: Date.UTC(2010, 0, 1),
            pointInterval: 1 * 3600 * 1000 // one hour
        }]
    });
});

See this jsfiddle example . 看到这个jsfiddle示例

Highcharts will only show the last data point that is specified. Highcharts只显示指定的最后一个数据点。 If you want to force it to show the 0900 - 23:59 you will have to pass it all the data points for the those times you want displayed, but for the value pass null . 如果要强制它显示0900 - 23:59,则必须将所有数据点传递给您想要显示的那些时间, 但是对于值传递null Here is an example: jsfiddle example . 这是一个例子: jsfiddle示例

Once the data points go over the hour range it will automatically format the datatime labels differently. 一旦数据点超过小时范围,它将自动格式化数据时间标签。 You may want to control the formatting of the data labels via dateTimeLabelFormats . 您可能希望通过dateTimeLabelFormats控制数据标签的格式。

As stated in a previous answer, by default, 如前一个答案中所述,默认情况下,

Highcharts will only show the last data point that is specified. Highcharts只显示指定的最后一个数据点。

However, as you can see on default jsfiddle for min max setting , you have to specify both in addition to min and max that endOnTick and startOnTick are false. 但是,正如您在默认jsfiddle中看到的最小最大设置 ,除了min和max之外,还必须指定endOnTick和startOnTick都为false。 Moreoever, when dealing with missing data on datetime types, you'd to set ordinal to false in order to let space for empty data. 此外,在处理datetime类型的缺失数据时,您需要将ordinal设置为false,以便为空数据留出空间。

It means that your xAxis should look like below: 这意味着您的xAxis应如下所示:

xAxis : {
    allowDecimals : false,
    endOnTick : false,
    max : /** Date in timestamp for the end the day */,
    min : /** Date in timestamp for the beginning the day */,
    ordinal : false,
    startOnTick : false,
    type : 'datetime'
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM