Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi i use plugin chartjs angular, i have error chart.crosshair is undefined how to fix this #128

Open
chetdi117 opened this issue Nov 15, 2023 · 1 comment

Comments

@chetdi117
Copy link

No description provided.

@akenshaw
Copy link

akenshaw commented Nov 25, 2023

I had the same problem. It was a scale type that I'm using but not included in the plugin for me.

If the chart.crosshair is undefined, the plugin probably just doing a "return", before it can create "chart.crosshair";

var CrosshairPlugin = {

  id: 'crosshair',

  afterInit: function(chart) {    
    // I've checked what properties I had on "chart" with "debugger;"
    if (!chart.config.options.scales.x) {
      // make sure that your x axis named just "x", it won't allow xAxis0 or anything custom like that. 
      return  
    }

    var xScaleType = chart.config.options.scales.x.type;

    if (xScaleType !== 'linear' && xScaleType !== 'time' && xScaleType !== 'category' && xScaleType !== 'logarithmic' && xScaleType !== 'timeseries') {
      /* I had "timeseries" type x scale, which wasn't included in here, I saw no reason why on the later parts of the plugin, so after adding, seems to solved it for me. */
      return;
    }

    if (chart.options.plugins.crosshair === undefined) {
      chart.options.plugins.crosshair = defaultOptions;
    }

    chart.crosshair = {
      enabled: false,
      suppressUpdate: false,
      x: null,
      originalData: [],
      originalXRange: {},
      dragStarted: false,
      dragStartX: null,
      dragEndX: null,
      suppressTooltips: false,
      ignoreNextEvents: 0,
      reset: function() {
        this.resetZoom(chart, false, false);
      }.bind(this)
    };
// the rest of the plugin...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants