Search code examples
javascriptangulartypescriptngx-graph

Reload ngx-graph with new data


I am trying out swimlane ngx-graph, in my application user can delete or add nodes. Based on delete or add action I will update my data accordingly.

Real question now is how can I refresh my graph without refreshing entire page.


Solution

  • You can update it by using the update$ option of the graph,

    HTML :

    <ngx-graph
        . . . // Other options
        [update$]="update$"
        . . . 
    >
    

    TS :

    // Observable for update 
    update$: Subject<any> = new Subject();
    
    // Update function
    updateChart(){
        this.update$.next(true);
    }
    

    Once you update your data, call updateChart()