ngx-echarts icon indicating copy to clipboard operation
ngx-echarts copied to clipboard

There is a chart instance already initialized on the dom.

Open y0nd0 opened this issue 3 years ago • 7 comments

I just created one chart and get this warning on console:

There is a chart instance already initialized on the dom. (echarts.js:2168)

I just update options. I'm on Ionic (Angular) and show this chart on page navigation. But this is not the problem. I get this warning only once or twice (directly at the same time).

image

If I navigate back and then forward again to the page with the chart, there is no more warning. Only the two (or sometimes only one) message you see above.

On ngOnChanges I reassign the chart options like this.options = {...this.options} to trigger an update. Any idea? ...

{
    "echarts": "^5.0.2",
    "ngx-echarts": "^6.0.1",
}

y0nd0 avatar Apr 03 '21 17:04 y0nd0

@y0nd0 What version of angular are you on?

kevin-objectstudio avatar Apr 09 '21 17:04 kevin-objectstudio

Angular 12

jtomek avatar Jun 06 '21 19:06 jtomek

Same issue: Angular 12, "echarts": "^5.2.1", "ngx-echarts": "^7.0.2",

alextroto avatar Sep 29 '21 11:09 alextroto

Instead of updating the object passed to [options], you can define the changing data in a separate variable and pass that variable to [merge].

Example:

HTML:

<div echarts [options]="gaugeCommonOptions" [merge]="cpuLoadChartOptions"></div>

Component:

@Component()
export class MyComponent {
  gaugeCommonOptions: EChartsOption = {
    series: [
      {
        type: 'gauge',
      }
    ]
  }
  cpuLoadChartOptions: EChartsOption = {};

  plotCpuLoad(): void {
    this.cpuLoadChartOptions = {series: [{data: [100]}]}
  }
}

MukeshS-hexaware avatar Nov 08 '21 07:11 MukeshS-hexaware

?

apoorv-2204 avatar Mar 02 '22 06:03 apoorv-2204

I solved it in vue 3, implementing a different id for each graph.

sergioriverafl avatar Sep 02 '23 16:09 sergioriverafl

Thanks, @sergioriverafl, I was able to do the same in Angular v16, having the ID as variable that changes with each chart solved it for me.

    <div
      echarts
      [options]="options"
      class="echart"
      [id]="'tankId' + tankId"
    ></div>

rami-alloush avatar Mar 11 '24 16:03 rami-alloush