skip to Main Content

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);

2

Answers


  1. Chosen as BEST ANSWER

    I got a solution by replacing all the current series to empty series one by one:

    var option = this.echart.getOption();
    option.series.forEach(function(series) {
        series.data = [];
    });
    this.echart.setOption(option); 
    

  2. 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']})
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search