When trying to create charts in Angular using Highchart, I encountered an error during compilation. The properties seem to be compatible, but the TypeScript compiler is throwing an error that I don't quite understand. Any suggestions on how to avoid this error? I am currently using Angular 11.
error TS2322: Type '{ chart: { type: string; }; title: { text: string; }; xAxis: { categories: string[]; }; yAxis: { title: { text: string; }; }; series: ({ name: string; data: number[]; type: string; color?: undefined; } | { name: string; data: number[]; type: string; color ...
[options]="chartOptions"
~~~~~~~~~~~~~~~~~~~~~~~~
import { Component, OnInit } from '@angular/core';
import * as Highcharts from 'highcharts';
title = 'myHighchart';
Highcharts: typeof Highcharts = Highcharts;
data = [{
name: 'ItSolutionStuff.com',
data: [500, 700, 555, 444, 777, 877, 944, 567, 666, 789, 456, 654],
type: "spline",
}, {
name: 'Nicesnippets.com',
data: [677, 455, 677, 877, 455, 778, 888, 567, 785, 488, 567, 654],
type: "spline",
color: '#3183F5'
}];
chartOptions = {
chart: {
type: "spline"
},
title: {
text: "Monthly Site Visitor"
},
xAxis: {
categories:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
},
yAxis: {
title:{
text:"Visitors"
}
},
series: this.data
};
<highcharts-chart
[Highcharts]="Highcharts"
[options]="chartOptions"
style="width: 100%; height: 400px; display: block;">
></highcharts-chart>