Skip to content

[Bug] EChartsOption missing tooltip when creating pie chart data series #19293

@fireflysemantics

Description

@fireflysemantics

Version

5.4.2

Link to Minimal Reproduction

https://stackblitz.com/edit/stackblitz-starters-v7ee5w?file=src%2Fecharts.component.ts

Steps to Reproduce

The chart is created like this using ngx-echarts:

import {
  ChangeDetectionStrategy,
  Component,
  OnInit,
  ViewEncapsulation,
} from '@angular/core';
import { NgxEchartsModule, NGX_ECHARTS_CONFIG } from 'ngx-echarts';
import { fromEvent, debounceTime } from 'rxjs';
import { EChartsOption, graphic } from 'echarts';

@Component({
  standalone: true,
  imports: [NgxEchartsModule],
  providers: [
    {
      provide: NGX_ECHARTS_CONFIG,
      useFactory: () => ({ echarts: () => import('echarts') }),
    },
  ],
  selector: 'app-animated-bar-chart',
  template:
    '<div style="height: 300px;" echarts (chartInit)="onChartInit($event)" [autoResize]="false" [options]="options"></div>',
  styles: [
    `app-animated-bar-chart {
    display:block;
}`,
  ],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AnimatedBarChartComponent implements OnInit {
  private data: number[] = [300, 520, 435, 530, 730, 620, 660, 860];

  echartsIntance: any;

  //  options!: EChartsOption;
  options!: EChartsOption;
  //options!: any;
  constructor() {
    this.resize();
  }
  ngOnInit(): void {
    this.options = {
      tooltip: {
        trigger: 'item',
        formatter: '',
      },
      series: [
        {
          name: ' ',
          clockwise: true,
          type: 'pie',
          radius: ['65%', '100%'],
          center: ['50%', '50%'],
          data: [
            {
              value: 500,
              name: 'Solana',
              label: {
                position: 'center',
                formatter: '',
                fontSize: 22,
                fontWeight: 600,
                fontFamily: 'Roboto',
                color: 'blue',
              },
              tooltip: {},
            },
            {
              value: 500,
              name: 'Tether',
            },
            {
              value: 1000,
              name: 'Golem',
            },
          ],
        },
      ],
    };
  }

  resize() {
    fromEvent(window, 'resize')
      .pipe(debounceTime(200))
      .subscribe((e) => {
        console.log('RESIZE');
        if (this.echartsIntance) {
          this.echartsIntance.resize({
            animation: {
              duration: 1500,
              easing: 'elasticOut',
            },
          });
        }
      });
  }

  onChartInit(echarts: any) {
    this.echartsIntance = echarts;
  }
}

Current Behavior

The EChartsOption should allow for specifying a tooltip when creating a pie chart data series. I've documented the rest in this Stackoverflow question with a runnable example.

https://stackoverflow.com/questions/77442901/adding-a-tooltip-configuration-to-a-pie-chart-data-item-in-echarts

Expected Behavior

It should compile. However this error is produced.

Error in src/echarts.component.ts (66:15)
Type '{ name: string; clockwise: true; type: "pie"; radius: string[]; center: string[]; data: ({ value: number; name: string; label: { position: "center"; formatter: string; fontSize: number; fontWeight: number; fontFamily: string; color: string; }; tooltip: {}; } | { ...; })[]; }' is not assignable to type 'SeriesOption$1'.
Types of property 'data' are incompatible.
Type '({ value: number; name: string; label: { position: "center"; formatter: string; fontSize: number; fontWeight: number; fontFamily: string; color: string; }; tooltip: {}; } | { value: number; name: string; })[]' is not assignable to type '(OptionDataValueNumeric | OptionDataValueNumeric[] | PieDataItemOption)[]'.
Type '{ value: number; name: string; label: { position: "center"; formatter: string; fontSize: number; fontWeight: number; fontFamily: string; color: string; }; tooltip: {}; } | { value: number; name: string; }' is not assignable to type 'OptionDataValueNumeric | OptionDataValueNumeric[] | PieDataItemOption'.
Type '{ value: number; name: string; label: { position: "center"; formatter: string; fontSize: number; fontWeight: number; fontFamily: string; color: string; }; tooltip: {}; }' is not assignable to type 'OptionDataValueNumeric | OptionDataValueNumeric[] | PieDataItemOption'.
Object literal may only specify known properties, and 'tooltip' does not exist in type 'OptionDataValueNumeric[] | PieDataItemOption'.

Environment

- OS:macOS Sonoma 14
- Browser: Chrome and Firefox
- Framework: Angular

Any additional comments?

I was trying to create a PIE chart with a tooltip on the data series.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenThis issue is in EnglishpendingWe are not sure about whether this is a bug/new feature.typescript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions