Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts line with null values

I'm trying to create a line diagram (datetime x-axis) with null values.

var rawData = [{
    (...)
}, {
    "PointOfTime": 1424991600,
    "value": 6831.28806
}, {
    "PointOfTime": 1425078000,
    "value": null
}, {
    "PointOfTime": 1425164400,
    "value": null
}, {
    (...)
}];

Adjust the data from a json source to an array:

rawData.forEach(function (d) {
    var datetime = (d.PointOfTime + 3600) * 1000;
    data.push([datetime, parseFloat(d.value)]);
});

As stated in the following fiddle, http://jsfiddle.net/wiesson/1m5hpLef there are no lines, only bullets. Any suggestions? I need the PointOfTime to create the range of the x-axis, even they are empty.

// Edit: As displayed in the following figure, the values in the future are unknown and not 0, therefore I would like to set them to null.

Example Picture

like image 712
wiesson Avatar asked Mar 21 '26 21:03

wiesson


1 Answers

Add a condition, which check if your value is null. If yes then push this, instead of call parseFloat(null).

rawData.forEach(function (d) {
    var datetime = d.PointOfTime * 1000;
    if(d.value!==null)
        data.push([datetime, parseFloat(d.value)]);
    else
         data.push([datetime, null]);
});

Example: http://jsfiddle.net/wiesson/1m5hpLef/

like image 75
Sebastian Bochan Avatar answered Mar 24 '26 09:03

Sebastian Bochan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!