chartjs-plugin-crosshair icon indicating copy to clipboard operation
chartjs-plugin-crosshair copied to clipboard

Crosshair is rendered on top of tooltips

Open CreativeCoders opened this issue 4 years ago • 5 comments

Screenshot 2020-08-24 at 13 13 54

Crosshair is rendered on top of tooltips (and the datalabels plugin annotations). It would be nice to be able to push it behind elements in the chart.

CreativeCoders avatar Aug 24 '20 11:08 CreativeCoders

Has anyone resolved this?

jclusso avatar Sep 15 '20 13:09 jclusso

Not to my knowledge @jclusso

CreativeCoders avatar Sep 15 '20 13:09 CreativeCoders

@CreativeCoders actually this guys version adds an option drawUnderChart that fixes this.

jclusso avatar Sep 15 '20 20:09 jclusso

@daraeman could make a PR to include this feature maybe, it would be great!

se98100 avatar Oct 14 '20 13:10 se98100

Here's is a very simple workaround, if you have the plugin globally registered in ChartJS:

// Fix for crosshair plugin drawing over the chart and tooltip

let crosshairPlugin = Chart.registry.plugins.get("crosshair");
const afterDraw = crosshairPlugin.afterDraw.bind(crosshairPlugin);

crosshairPlugin.afterDraw = function (chart, args, options) {};

crosshairPlugin.afterDatasetDraw = function (chart, args, options) {
    afterDraw(chart, args, options);
};

This plugin is rendering the crosshair during the afterDraw state which is triggered after the tooltip has been rendered. This workaround moves the rendering logic to the afterDatasetDraw function instead.

shi-314 avatar Feb 05 '24 11:02 shi-314