RFMV34
Posts: 2
Joined: Fri Jun 18, 2021 1:09 pm

Network graph recalculate positions on serie hide/show

Hi,

First thanks for your awesome work, I used HC for my multiple charts implementations. Currently, I try to create a network graph. I need to recalculate the positions of nodes when I hide or show some serie. Currently, when I hide serie, Serie is disappear, but there is no recalculation of position, but only blank space. See Images.
I tried a lot of methods, but no one worked for me. Is there any official method? Can you point me in the right direction, please?

Thanks!

Filip.
Attachments
hc.png
hc.png (174.21 KiB) Viewed 857 times
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Network graph recalculate positions on serie hide/show

Hi,
Welcome to our forum and thanks for contacting us with your question!

There is no such functionality in the API, you will need to update the series each time you click the legend.
Then the update will be performed and using series.layoutAlgorithm.initialPositions you will set the position to the beginning.

API References:
https://www.highcharts.com/docs/chart-a ... hm-options
https://api.highcharts.com/highcharts/p ... lPositions

Let me know how are you going with this.
Best regards.
Sebastian Hajdus
Highcharts Developer
RFMV34
Posts: 2
Joined: Fri Jun 18, 2021 1:09 pm

Re: Network graph recalculate positions on serie hide/show

Hi, thanks for your reply!
I tried various methods, but without success, I always get error. (for example https://jsfiddle.net/Luw07mj8/20/)
I get following error:

Code: Select all

networkgraph.src.js:1198 Uncaught TypeError: Cannot read property 'id' of null
    at networkgraph.src.js:1198
    at Array.forEach (<anonymous>)
    at a (networkgraph.src.js:1197)
    at networkgraph.src.js:1210
    at Array.forEach (<anonymous>)
    at reingold-fruchterman.setCircularPositions (networkgraph.src.js:1208)
    at reingold-fruchterman.initPositions (networkgraph.src.js:1179)
    at reingold-fruchterman.start (networkgraph.src.js:1023)
    at networkgraph.src.js:1506
    at Array.forEach (<anonymous>)
(anonymous) @ networkgraph.src.js:1198
a @ networkgraph.src.js:1197
(anonymous) @ networkgraph.src.js:1210
setCircularPositions @ networkgraph.src.js:1208
initPositions @ networkgraph.src.js:1179
start @ networkgraph.src.js:1023
(anonymous) @ networkgraph.src.js:1506
(anonymous) @ networkgraph.src.js:1505
(anonymous) @ highcharts.src.js:1961
A @ highcharts.src.js:1958
a.redraw @ highcharts.src.js:30111
a.update @ highcharts.src.js:36009
hide @ New Text Document (6).html:65
(anonymous) @ highcharts.src.js:1961
A @ highcharts.src.js:1958
a.setVisible @ highcharts.src.js:36280
c @ highcharts.src.js:29260
A @ highcharts.src.js:1968
(anonymous) @ highcharts.src.js:29282
and graph is not updated, this error come from setCircularPositions HC method.
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Network graph recalculate positions on serie hide/show

Hi,
I think you should try to set position inside chart.events.render, like an example from this topic.

https://github.com/highcharts/highchart ... -514189710
https://jsfiddle.net/BlackLabel/kzwhna2q/

API References:
https://api.highcharts.com/highcharts/c ... nts.render

Best regards.
Sebastian Hajdus
Highcharts Developer

Return to “Highcharts Usage”