Search code examples
javascriptecharts

Is there a way to remove all series without having to reload the chart in echart?


I'm trying to empty an echart chart. I tried adding "true" at the setOption method, but that resets all the other options in the chart. To make it work, I made a default option object, to load every time I need to empty the chart, but that messes with some of the fluent interactivity of the chart. Is there a way to remove ONLY the series?

 echart.setOption({series: []}, true);

Solution

  • You can use the replaceMerge parameter of the setOption function. From the documentation:

    replaceMerge Optional. Users can specify "component main types" here, which are the properties under the root of the option tree in configuration item manual (e.g., xAxis, series). The specified types of component will be merged in the mode "replaceMerge". If users intending to remove some part of components, replaceMerge can be used.

    Therefore, the following will remove all series:

    echart.setOption({series: []}, {replaceMerge: ['series']})