const annotation1 ={type:'line',borderColor:'lightGreen',borderWidth:10,label:{display:false,backgroundColor:'green',drawTime:'afterDatasetsDraw',content:(ctx)=>['Average of dataset','is: '+average(ctx).toFixed(3)]},scaleID:'y',value:(ctx)=>average(ctx),// For simple property changes, you can directly modify the annotation// element's properties then return true to force chart re-drawing. This is faster.enter({element}, event){
element.label.options.display =true;returntrue;},leave({element}, event){
element.label.options.display =false;returntrue;}};
const annotation2 ={type:'line',borderColor:'lightBlue',borderWidth:10,label:{display:(ctx)=> ctx.hovered,backgroundColor:'blue',drawTime:'afterDatasetsDraw',content:(ctx)=>['Min of dataset','is: '+min(ctx).toFixed(3)],position:(ctx)=> ctx.hoverPosition
},scaleID:'y',value:(ctx)=>min(ctx),// For more complex dynamic properties, you can store values on the persistent// context object then retrieve them via scriptable properties. You'll have// to call chart.update() to reprocess the chart.enter(ctx, event){
ctx.hovered =true;
ctx.hoverPosition =(event.x / ctx.chart.chartArea.width *100)+'%';
ctx.chart.update();},leave(ctx, event){
ctx.hovered =false;
ctx.chart.update();}};