1

I have upgraded the chart.js 2.x to 4.x version.

So I got resolving but when I get declaring the variable for chart

ts file :

let chart= new Chart(
donutCtx, //error here
{
    "type":'doughnut',
     "data" : dataformat,
     "options":{
       plugin:{
       'legend':{  
         labels:{
          fontColor:"#333",
          fontSize:9
         }, 
       onClick: null  // error here Type 'null'  is not assignable to type '((event: MouseEvent,                   
                       //legendItem: ChartLegendLabelItem) => void | undefined' .ts 
    },
    'title':{
       fontColor:"#333",
          fontSize:9
     }
     },
     pieceLabel:{ // error Object literal may only specify known properties and 'pieceLable' doenot             

                   // exist type 'Elementchartoptions<"doughnut"> & pluginChartOptions<"doughnut">
      render:'percentage',
       precision:2
     }
  }    
});
> //error here-- donutCtx -- Argument of type 'CanvasRenderingContext2D | null' is not assignable to parameter of type 'chartItem'.
> Type 'null' is not assignable to type 'ChartItem'.
> 
> let donutCtx: CanvasRenderingContext2D | null

I have tried to add if condition to donutCtx to check null below are the tried code error not there but onClick: null is not assignable getting

if(donutCtx !== null){
let chart= new Chart(
donutCtx,
{
    "type":'doughnut',
     "data" : dataformat,
     "options":{
      plugin:{
       'legend':{  
         labels:{
          fontColor:"#333",
          fontSize:9
         }, 
       onClick: null  // error here Type 'null'  is not assignable to type '((event: MouseEvent,                   
                       //legendItem: ChartLegendLabelItem) => void | undefined' .ts 
    },
    'title':{
       fontColor:"#333",
          fontSize:9
     }},
     pieceLabel:{ // error here also how to access 'pieceLabel' property
      render:'percentage',
       precision:2
     }
  }    
});
}
> //error here-- donutCtx -- Argument of type 'CanvasRenderingContext2D | null' is not assignable to parameter of type 'chartItem'.
> Type 'null' is not assignable to type 'ChartItem'.
> 
> let donutCtx: CanvasRenderingContext2D | null

Can anyone please help me to resolve this issue.

Please help !

Jatniel
  • 1,967
  • 2
  • 19
  • 27
User0777
  • 21
  • 3

0 Answers0