Arctic-101
Posts: 4
Joined: Mon Mar 27, 2023 2:07 am

.setVisible crashes application/ Can’t change visibility for individual datapoints

Hello. I’m relatively new to highcharts and JavaScript development in general. I am making an application to compile and show flight data using a world map from highcharts . It handles a lot of data and each flight is grouped into a highchart series by date and mapped out onto the world map.

Now here’s the problem, I am making a new feature that would allow the user to filter the flights by date, only showing the flights within the selected date range. This is achieved using .setVisible on all highchart series with the incorrect date value. This works but it takes a very, very long time and almost crashes the application.

I’ve narrowed the problem down to come from .setVisible as to what’s taking up all the processing power. Previously I had all flights grouped in the same highchart series and tried setting the visibility locally for each datapoint, but then they were overridden by the visibility property for the series that they were stored in. Due to this I made each date into its own series.


If there’s anything I’ve done wrong or any solution to this that you can think of, I’d highly appreciate your input. Thank you :D
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: .setVisible crashes application/ Can’t change visibility for individual datapoints

Hi,

Welcome to our forum & thanks for the question!

You can use point.update({ visible: true }). The second argument of the points.update() is the redraw which determines whether the chart is going to be redrawn immediately after the update.

If you update a few points in a row, you should set this to false and redraw the chart after all the updates are performed.

API: https://api.highcharts.com/class-refere ... int#update

Here's a short demo: https://jsfiddle.net/BlackLabel/ucqsnv8p/

I believe that this example will help you.

If not, please do not hesitate to let me know.

Best regards,
Jakub
Jakub
Highcharts Developer
Arctic-101
Posts: 4
Joined: Mon Mar 27, 2023 2:07 am

Re: .setVisible crashes application/ Can’t change visibility for individual datapoints

Thank you for your answer! This appears to solve my problem regarding speed and efficiency. However the problem of .setVisible() not working for individual data still remains. Using setVisible() to hide an entire series works, but when it’s used for individual data, visible is set to false, but nothing shows or changes on the map.

Again, Thanh you for the quick and helpful response :)
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: .setVisible crashes application/ Can’t change visibility for individual datapoints

Sure, no problem! :)

Unfortunately, I'm not sure I understand your last point.

There is no method setVisible on the Highcharts.Point (https://api.highcharts.com/class-refere ... arts.Point), only on the Highcharts.Series.

That's why in the demo I've sent you I used point.update({ visible: false }) - that's the way to make a point invisible.

Let me know if that answers your question.

Best regards,
Jakub
Jakub
Highcharts Developer
Arctic-101
Posts: 4
Joined: Mon Mar 27, 2023 2:07 am

Re: .setVisible crashes application/ Can’t change visibility for individual datapoints

Okay thanks I think I understand. Previously I've been using the .setVisible method on individual data by navigating through their series.

When I try and use the point.update method i get this error:

Argument of type '{ visible: boolean; }' is not assignable to parameter of type 'PointOptionsType'.
Object literal may only specify known properties, and 'visible' does not exist in type 'PointOptionsObject | (string | number)[]'.ts(2345)
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: .setVisible crashes application/ Can’t change visibility for individual datapoints

Hi,

You're right!

Unfortunately, Highcharts is only partially written in TypeScript and there are still some issues - itt's being rewritten to support everything in TypeScript, but we're not there yet.

The easiest solution is to just cast the object you pass to point.update as any.

Here's a demo: https://codesandbox.io/s/recursing-snowflake-xne9iw

Let me know if that solves your problem.

Best regards,
Jakub
Jakub
Highcharts Developer
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: .setVisible crashes application/ Can’t change visibility for individual datapoints

I'm glad it helped!

Do not hesitate to ask if any more questions come up.

Best regards,
Jakub
Jakub
Highcharts Developer

Return to “Highcharts Usage”