Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make highcharts default to 0 for missing data

I have a time series at a 1 minute interval. I would like to display that in a chart with missing points as 0.

I've found xAxis.ordinal and turned that off which displays the time series properly spaced out. The issue is that it draws lines between the points directly without going to 0 for the missing data.

like image 483
Wraithan Avatar asked May 01 '12 07:05

Wraithan


People also ask

Is Highcharts angular free?

We are therefore happy to present to you our official Highcharts Angular wrapper, which is free to use (please note that using Highcharts for commercial projects require a valid license).

What is point in Highcharts?

The point objects are generated from the series. data configuration objects or raw numbers. They can be accessed from the Series. points array. Other ways to instantiate points are through Highcharts.

Can Highcharts be used in server?

The application can be used either as a CLI (Command Line Interface), as an HTTP server, or as a node.


2 Answers

One way is by pre-processing the data, replacing null with 0:

var withNulls = [null, 12, 23, 45, 3.44, null, 0]; var noNulls = withNulls.map(function (item) {     return (item === null) ? 0 : item; }); 

Example saved on jsfiddle: http://jsfiddle.net/7mhMP/

like image 142
eolsson Avatar answered Sep 19 '22 05:09

eolsson


I've thorougly searched the API reference of HighCharts, but they don't offer that option. What they do offer is the option to disable the connection of points when null data is in between (only line and area charts):

var chart = new Highcharts.Chart({     plotOptions: {         line: {             connectNulls: false         }     } }); 

This is the default setting according to the API, so I'm not sure why your data does connect with null values in between. Maybe they have changed the defaults lately?

Example of HighChart with missing data

I feel this is a good representation of your data, because defaulting null to 0 seems misleading.

like image 43
Justus Romijn Avatar answered Sep 22 '22 05:09

Justus Romijn