Why to execute setOption? in setTimeout in echart4.0 share dataset

problem description

when using share dataset in the official echart4.0 example in vue, the pie chart above is updated by listening for updateAxisPointer events, but it is found that sometimes the label data of the pie chart has been updated, but the chart has not been redrawn, but the pie chart will be redrawn when the mouse is moved outside the area of the column chart below. I have seen the setTimeout function useful in the code of the official example, and I don"t know if this is the crux of the problem.

the environmental background of the problems and what methods you have tried

vue2.5.16 echart4.1.0
here I encapsulate echart as a component, and then call it somewhere else, such as echart.vue and dashboard-barpie.vue

related codes

/ / Please paste the code text below (do not replace the code with pictures)
/ / echart.vue

this.myChart.on("updateAxisPointer", event => { 
  var xAxisInfo = event.axesInfo[0];
  if (xAxisInfo) {
    this.$emit("change-barpie", xAxisInfo);
  }
});

/ / dashboard-barpie.vue

< echart: options= "option": chartID= "chartID" ref= "dashboard_barpie_chart": height= "height" vMuzonghuza Barpiec = "changeBarpie": chartType= ""dashboard-barpie"" > < / echart >

changeBarpie(xAxisInfo) {
  var dimension = xAxisInfo.value + 1;
  this.$refs.dashboard_barpie_chart.setOption({
    series: {
      id: "pie",
      label: {
        formatter: "{b}: {@[" + dimension + "]} ({d}%)"
      },
      encode: {
        value: dimension,
        tooltip: dimension
      }
    }
  });
}


what result do you expect? What is the error message actually seen?

this is when the mouse hovers over the middle column area, the label data of the pie chart is updated, but the pie chart is obviously not redrawn

.
Dec.14,2021

  1. the code written on his official website is rather casual
  2. does not say that it must be executed in setTimeout (but event listening and event response are a different matter)
  3. with regard to the redrawing question in your question, you have to consider whether there is a problem with the logic of your code that leads to the redrawing delay. I have tried the example on the official website, and it doesn't matter whether you want setTimeout or not. as long as you move or hover the mouse in the chart area, updateAxisPointer events will continue to respond and execute, resulting in a continuous redrawing of pie, resulting in a serious waste of performance.
  4. as for verification, you only need to add a console.log ('update event.') to the callback for event listening, and you can see that it has been triggered countless times and the pie has to be redrawn after triggering
  5. .
  6. Why setTimeout I guess the purpose of the original author is to handle the updateAxisPointer event (for example, it triggers 100 times in a second, but only performs a callback, redraws the pie, instead of how many times it is triggered, and how many times it is redrawn), but his code is not finished, causing this illusion.
  7. how do I solve this problem?
//  lodash  debounce  .5 
this.v_rent_statistics_chart.on('updateAxisPointer', this._f.debounce(function (event) {
    console.log('pie...')
    let xAxisInfo = event.axesInfo[0]
    if (xAxisInfo) {
      let dimension = xAxisInfo.value + 1
      __this.v_rent_statistics_chart.setOption({
        series: {
          id: 'pie',
          encode: {
            value: dimension,
            tooltip: dimension
          }
        }
      })
    }
}, 500))

of course, it is only for personal understanding.

Menu