wiesson
wiesson

Reputation: 6812

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

Upvotes: 3

Views: 1133

Answers (1)

Sebastian Bochan
Sebastian Bochan

Reputation: 37578

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/

Upvotes: 3

Related Questions