How can I use Chart.Tooltip.positioners.cursor in angular ng2 chart?

1k Views Asked by At

https://stackblitz.com/edit/ng2-chart-example

here is working example in js : https://jsfiddle.net/edicarlos10/35081nag/

I want to use this code in my project but am not able to find, how can I use this code.

the working example is done by using chart.js and I want to make it done using ng2-charts, You can see in working example the tooltip is moveable on mouse position, I want to implement in angular project.

Chart.Tooltip.positioners.cursor = function(chartElements, coordinates) {
      return coordinates;
    };
1

There are 1 best solutions below

0
On

you need to import Chart from chart.js

import { Chart } from "chart.js";

then you can use it in constructor

  constructor() {
    Chart.Tooltip.positioners.cursor = (chartElements, coordinates) => {
      return coordinates;
    };
  }

and put it in options with name 'cursor'

lineChartOptions: any = {
    tooltips: {
      intersect: false,
      position: 'cursor',
      mode: 'index'
    }
  };