Share this

Loading millions of points in Highcharts

News Avatar

by

2 minutes read

Million data

How do you load millions of points in Highcharts?

The browsers have limitations when it comes to great amounts of data. Think about loading 1 million points of OHLC data – with three and four values each point, it will mean megabytes of data and heavy looping to process it. Perhaps some modern browsers can cope with it, but legacy browsers won’t get anywhere near it.

Enter the server. Backed by a database, we can load just the resolution we want to look at. In our new lazy loading demo, we set up a backend in PHP and MySQL. The original data is minute data for the AAPL stock, in total 1.7 million records. We wanted to display a candlestick chart with open, high, low and close data values, so we hit a limitation in MySQL. Since it lacks the concept of first and last in groups (open/close), we needed a nested select, which made it slow. So instead, we created four data tables holding data for minutes, hours, days and months respectively. If we wanted to display a simple line chart with average values, we wouldn’t need more than the original minute table.

Furthermore, to prevent the Highstock navigator from adjusting to the new data and sending off another setExtremes event, we needed to introduce a new option, navigator.adaptToUpdatedData. Now we can do whatever we want with the data in the main chart without affecting the navigator series, which always displays the entire data range.

Now as you can see in the source code below, the client server connection happens through jQuery.getJSON. We hook up to the X axis afterSetExtremes event, which unlike setExtremes fires after the new extremes have been adjusted for the X axis minRange and other variables. In the event handler we show a loading screen, then send off the new extremes to the server. The server then chews through this information, decides which resolution it should go for, selects the data and sends it back. Client receives it, hides the loading screen and sets new data to the series.

 

 

Stay in touch

No spam, just good stuff

We're on discord. Join us for challenges, fun and whatever else we can think of
XSo MeXSo Me Dark
Linkedin So MeLinkedin So Me Dark
Facebook So MeFacebook So Me Dark
Github So MeGithub So Me Dark
Youtube So MeYoutube So Me Dark
Instagram So MeInstagram So Me Dark
Stackoverflow So MeStackoverflow So Me Dark
Discord So MeDiscord So Me Dark

Comments

  1. Kristopher Larson

    |

    the chart is broken for anything but a year


    1. highcharts

      |

      Hi Kristopher, thanks for letting us know. We have updated the demo and it should be fixed now


      1. Martin Hammer

        |

        Great, you could improve the quality of the sample a lot by putting a small delay in the setExtremes function to prevent spamming your API resource.


        1. Dillibabu

          |

          hi hicharts taking more loading time when more than 500 records


          1. Mustapha Mekhatria

            |

            There is a new demo now, feel free to test it 🙂


  2. Benny Neugebauer

    |

    Your article says “in total 1.7 records”. I guess you meant “in total 1.7 million records”? 😉 Best, Benny


    1. Mustapha Mekhatria

      |

      Thx. Done 🙂


  3. Joe

    |

    Extremely helpful article, solved my issue! I’m curious about the MySQL limitation mentioned.

    “Since it lacks the concept of first and last in groups (open/close), we needed a nested select, which made it slow.”

    What is meant by the concept of first and last and how did/does that apply to this example. I feel it is something I should be aware of as I shall be storing OHLC data is a SQL database eventually.


    1. Mustapha Mekhatria

      |

      Hi,
      Feel free to use the boost module to handle a big amount of data: https://www.highcharts.com/docs/advanced-chart-features/boost-module


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.