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

Tooltips callbacks doesn't work #6

Open
BlowofDeath opened this issue Jun 23, 2021 · 2 comments
Open

Tooltips callbacks doesn't work #6

BlowofDeath opened this issue Jun 23, 2021 · 2 comments

Comments

@BlowofDeath
Copy link

Hi, i've tried to set a label using callbacks funcction, but i'm getting errors. Am i doing something wrong or is it an issue with library?

const chart = new fabric.Chart(options as fabric.IChartConfiguration);

  chart.set({
    chart: {
      options: {
        tooltips: {
          callbacks: {
            label: function (tooltipItem, data) {
              let total = 0;
              data.datasets[tooltipItem.datasetIndex].data.forEach((item) => {
                total += Number(item);
              });

              const label = data.datasets[tooltipItem.datasetIndex].label;
              return `${label}: ${tooltipItem.yLabel} of ${total}`;
            },
          },
        },
      },
    },
  });

image

@yassilah
Copy link
Owner

From what I can see you made a mistake, you should be setting options.plugins.tooltips.callbacks.label and not options.tooltips.callbacks.label as described here. Please let me know if that works.

@BlowofDeath
Copy link
Author

That doesn't help, chart-js-fabric use "dependencies": {"chart.js": "^2.9.3",}
2.9.3 documentation tells you to use options.tooltips.callbacks.label, but i tried to use options.plugins.tooltips.callbacks.label and i'm got same error. I also tried to use onClick

 chart.set({
    chart: {
      options: {
        onClick: () => {
          console.log('click');
        },
      },
    },
  });

it doesn't work as well.

It works, only when i set this functions using fabric.util.chart.setDefaults, but i need this to be set only on specyfic chart.

  fabric.util.chart.setDefaults({
    options: {
      tooltips: {
        callbacks: {
          label: function (tooltipItem, data) {
            let total = 0;
            data.datasets[tooltipItem.datasetIndex].data.forEach((item) => {
              total += Number(item);
            });

            const label = data.datasets[tooltipItem.datasetIndex].label;
            return `${label}: ${tooltipItem.yLabel} of ${total}`;
          },
        },
      },
      onClick(e, elements) {
        const pointedElement = this.getElementAtEvent(e)[0];
        pointedElement &&
          chart.canvas.fire('openChartViewModal', {
            options: options.chart,
            pointedElement: {
              datasetIndex: pointedElement._datasetIndex,
              index: pointedElement._index,
            },
            datasourceInfo: options.datasourceInfo,
          });
      },
    },
  });



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