veloopity
Posts: 45
Joined: Fri Dec 07, 2018 3:06 pm

Dates with holes in them

I need to display stock values: value on the y axis, dates on the x axis.

The stock dates I need to display for my customer have holes in them - not every day has a stock value. I'm sure this happens for most users :)

So far, I run a loop over all days from the requested timespan - if no data are found for this day, I create an entry in the series and fill it with 'null'; if data are found, I create an entry with the value [Date.UTC(20,11,7),436.12], for instance. Do I really have to do that?

The whole thing is too slow if the time span is years. I see two things that seem superfluous:

1. is there a way to omit the 'null' items and just throw the real values at Highcharts, making it position the values in the correct place anyway?

2. my date values come in this format from the database: "yyyy-mm-dd 00:00:00" - I have to call string functions to extract year/month/day and then call 'Date.UTC' for each item. I'm sure that slows everything down on the server and the client side if there are thousands of items in the chart. How would you do it?

-Michael
bastss
Site Admin
Posts: 1192
Joined: Wed Oct 17, 2018 10:59 am

Re: Dates with holes in them

Hello veloopity,

To your first issue - you don't have to loop over all days. In Highcharts exist a possibility to make a gap for days without data API: https://api.highcharts.com/highstock/pl ... ne.gapSize.
To your second issue - if your date comes from the database as a string you have to change it to a number, there is no other way. Only getting date value in milliseconds from your database will be a perfect solution.
For further problems with speed and performance in Highcharts I recommend to read about boost module API: https://www.highcharts.com/docs/advance ... ost-module
If you have an additional question feel free to ask and send a sample demo of your code :)

Best regards!
Sebastian Wędzel,
Highcharts Developer

Return to “Highcharts Stock”