Reputation: 131
So I have a highcharts setup, I would like to be able to replace the nulls with 0.
On the JSFiddle you can see the 18th and 19th (weekends) no one did any searches, however it carries onto the next point.
Is it possible to replace these empty values with 0, instead of having a not so aesthetically pleasing gap in each line?
I suspect I may have to use a formatter
tag to do this.
Upvotes: 0
Views: 285
Reputation: 11809
Altough Higcharts has the connectNulls
option, it will directly connect the value before with the next. The only way I can think of is to preprocess the data, reading the value before appending it to the series and converting nulls to zeros, like this:
// var seriesdatagorfromsomewhere
for (var i = 0; i < seriesdatagorfromsomewhere.length; i++) {
if (seriesdatagorfromsomewhere[i][1] === null) {
seriesdatagorfromsomewhere[i][1] = 0;
}
}
And then append the data to the series as you normally do.
If your code don't generate nulls, you can do it 2 ways: To check the points against the server date in some way and to check the points between series.
The idea is to process the points, one by one, getting the first parameter of each one (the date). When you encounter a non-existant date, just add it with a zero value. You should stop processng info when you reach the stop date (from the server, or the request you made to show the info, whatever)
The other one is the same approach but stop when any series has no value. One problem with this is that if any series has data for a weekend, then you will not create any zeros for it.
Example:
// var seriesdatagorfromsomewhere
// var stopdate (from server/request or highest date value from all series)
// var startdate (from server/request or lowest date value from all series)
// var currentseriespos = 0;
while (startdate <= stopdate) {
var date = seriesdatagorfromsomewhere[currentseriespos][0];
if (startdate != date) {
seriesdatagorfromsomewhere.splice(currentseriespos, [startdate, 0]);
}
startdate = increaseOneDay(startdate);
currentseriespos++;
}
Not tested. Surely the loop wont work like this and you will get an infinite loop, but you get the idea.
Upvotes: 1