Chartjs-How to use chartjs-plugin-crosshair in Angular 6+?

2👍

You need to import crosshair.

import * as crosshair from 'chartjs-plugin-crosshair';

If you are using ng2-charts define plugin in ts file.

public chartPlugins = [crosshair];

and then on html page use plugins

      <canvas baseChart
            [datasets]="barChartData"
            [labels]="barChartLabels"
            [options]="barChartOptions"
            [plugins]="chartPlugins"
            [legend]="barChartLegend"
            [chartType]="barChartType"
            [colors]="chartColors">
    </canvas>

Leave a comment