[Chartjs]-TypeError: Cannot read property 'legend' of undefined | Angular + ng2-charts

6👍

Remove [legend]="arbarChartLegend" from your html.

In TS, arbarChartOptions: any = { legend: { display: true, labels: { fontColor: 'black' } }

3👍

For me it was enough to initialise empty arbarChartOptions like:

public arbarChartLabels: Label[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
public arbarChartType = 'bar';
public arbarChartLegend = true;
public arbarChartData: ChartDataSets[] = [
  {data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A'},
  {data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B'}
];
public arbarChartOptions: ChartOptions = {}

to solve the error

Leave a comment