HighStock if time inertval missing shows red line

2019-07-21 03:01发布

问题:

Hi I used high stock chart for showing data in time series format. I received data every 5 minutes, for X-axis I set timestamp which I received on every 5 minutes. but in case some data not coming from 5 minutes then I want to display that line in red or blank below I tried

JsFiddle link

In this demo data come at 10:25 and after 10:35 so in between I want to shows red line or blank space. Following images shows expected output

Or

回答1:

I think the issue here is how is highcharts supposed to know that there is no data at 10:30? Your data timestamp intervals are not identical (meaning they don't occur every 5 minutes).

What you could do is put a watcher function in place that gets the data first. Inside of this put a timer that if 5 minutes go by without any data being retrieved, send out a data point like [<the time stamp>, null]. Now, you will also need to a property to not link null points called connectNulls. This is false by default so your 2nd option above is satisfied (see this fiddle).

For option 1 (the red line) you would need to create a new series containing the previous point and the next point surrounding your no-data point and set its series color to red. The drawback here is that if you have many cases with data gaps you will be creating many 2 point series. An example series to add would be:

{
    color: 'red',
    showInLegend: false,
    data: [
    [1415787839488, 0.5590000152587891],
    [1415788494848, 0.5139999985694885]
        ]
}

And an example fiddle.