0
  1. 手动删除图例并将其添加到 LightiningChart JS 的方法
  2. 删除 PointSeries 并将其添加到 LightiningChart JS 的方法
4

1 回答 1

1

1. 手动删除和添加图例到LightiningChart JS的方法

您可以使用 dispose 方法从 legendBox 中手动删除条目。

// 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()

请注意,处理条目不会删除组标题,即使该组中没有任何条目。

目前,无法将已删除的条目恢复到 legendBox,但您可以将系列再次添加到 legendBox。如果给定相同的标题,legendBox 将自动将新条目与同一组中的其他条目分组。

// 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. LightiningChart JS 中删除和添加 PointSeries 的方法

如果要在图表中删除和添加相同的 PointSeries,只需分别调用 dispose() 和 restore() 方法即可。

// 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()

只要您仍然参考该系列,就可以将已处理的系列恢复到图表中。

于 2020-01-22T12:25:48.193 回答