0

Here is the clear view of the error: Can someone help me resolve it?

Type '{ legend: { position: string; }; title: { display: true; text: string; }; }' is not assignable to type '_DeepPartialObject<CoreChartOptions<"bar"> & ElementChartOptions<"bar"> & PluginChartOptions<"bar"> & DatasetChartOptions<"bar"> & ScaleChartOptions<...> & BarControllerChartOptions>'. Object literal may only specify known properties, and 'legend' does not exist in type '_DeepPartialObject<CoreChartOptions<"bar"> & ElementChartOptions<"bar"> & PluginChartOptions<"bar"> & DatasetChartOptions<"bar"> & ScaleChartOptions<...> & BarControllerChartOptions>'.ts(2322) index.esm.d.ts(3599, 3): The expected type comes from property 'options' which is declared here on type 'ChartConfiguration<"bar", any, unknown>'

Here I have attached my code in my component.ts.

new Chart('myChart',{
       type: 'bar',
       data :{
         labels: this.team,
         datasets: [
           {
             data: this.totalDefects,
             borderColor : '#000000',
             backgroundColor : '#8e5ea2',
             label : "Total defect count",
           }
         ]
       },
       options: {
         legend: {
         position : 'top',
          },
         title:{
           display: true,
           text : 'Total number of defects raised by each team across iterations'
         }
       }
    });
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
Tobias S.
  • 21,159
  • 4
  • 27
  • 45

1 Answers1

1

That is because you are using v2 syntax with v3, legend and title options have to be configured in the options.plugins namespace instead of in the root of the options namespace

LeeLenalee
  • 27,463
  • 6
  • 45
  • 69
  • thank you so much, I have resolved the issue. But now there are no compilation errors, but the chart is not rendered on the page as I am getting an error ' "bar" is not a registered controller.' Can you please help me out, I'm sorry I am a beginner. – Niveditha Kannan Apr 19 '22 at 06:50
  • https://stackoverflow.com/a/67727684/8682983 – LeeLenalee Apr 19 '22 at 07:21