Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Area Chart Not Compiling #376

Open
fireflysemantics opened this issue Nov 23, 2022 · 2 comments
Open

Basic Area Chart Not Compiling #376

fireflysemantics opened this issue Nov 23, 2022 · 2 comments

Comments

@fireflysemantics
Copy link

Hi,

I'm trying to get the basic area chart working on Stackblitz. I've installed ngx-echarts and imported the module. I've added the options to app.component.ts like this:

option = {
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: 'line',
      areaStyle: {}
    }
  ]
};

And declared the chart in app.component.html.

<div echarts [autoResize]="false" [options]="option" class="demo-chart"></div>

And it produces this very long error:


Type '{ xAxis: { type: string; boundaryGap: boolean; data: string[]; }; yAxis: { type: string; }; series: { data: number[]; type: string; areaStyle: {}; }[]; }' is not assignable to type 'EChartsOption'.
Types of property 'xAxis' are incompatible.
Type '{ type: string; boundaryGap: boolean; data: string[]; }' is not assignable to type 'XAXisOption | XAXisOption[]'.
Type '{ type: string; boundaryGap: boolean; data: string[]; }' is not assignable to type 'CategoryAxisBaseOption & { gridIndex?: number; gridId?: string; position?: CartesianAxisPosition; offset?: number; categorySortInfo?: OrdinalSortInfo; } & { ...; }'.
Type '{ type: string; boundaryGap: boolean; data: string[]; }' is not assignable to type 'CategoryAxisBaseOption'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"category"'.

Any ideas?

@fireflysemantics
Copy link
Author

Ok I figured it out. The options for the chart have to be set in ngOnInit otherwise the chart will not render. I'll leave the issue open since it's a little strange that it does not work the other way as well.

https://stackoverflow.com/questions/74551778/basic-area-echart-not-compiling-with-ngx-echarts/74552248#74552248

@xieziyu
Copy link
Owner

xieziyu commented Nov 24, 2022

@fireflysemantics
Your option is initialized untyped, so compiler has to infer its type which seems incorrect. You can fix the issue by adding the EChartsOption:

import type { EChartsOption } from 'echarts';

option: EChartsOption = {
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: 'line',
      areaStyle: {}
    }
  ]
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants