Reputation: 166
Upvotes: 0
Views: 532
Reputation: 391
1. Way to manually remove and add legends to LightiningChart JS
You can manually remove entries from a legendBox by using the dispose method.
// Add legend box to the chart
const lb = chart.addLegendBox()
// Add all Series in a chart to the legendBox, and cache the entries
const entries = lb.add(chart)
// Remove an entry from the legendBox; this will remove the checkbox and the title of the series that was removed
entries[2].dispose()
Note that disposing entries does not remove the group title, even if there are no entries left in that group.
Currently, there is no way to restore a removed entry to the legendBox, but you can just add the series again to the legendBox. If given the same title, the legendBox will automatically group the new entry with the other entries in the same group.
// Argument 1: Series to add.
// Argument 2: Boolean, if the object attached to this entry should be disposed when checkbox is clicked.
// Argument 3: Group this entry should be attached to. If empty, entry will be attached to 'undefined group'.
lb.add( series, true, 'group name' )
2. Way to remove and add PointSeries to LightiningChart JS
If you want to remove and add the same PointSeries in the Chart, you can just call the dispose() and restore() methods respectively.
// Add a new PointSeries to the chart, where the points are shaped as triangles.
const pointSeries = chartXY.addPointSeries( { pointShape: PointShape.Triangle } )
// Remove the PointSeries from the chart.
pointSeries.dispose()
// Add the PointSeries back to the chart.
pointSeries.restore()
Disposed series can be restored to the chart as long as you still have reference to that series.
Upvotes: 2