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

afterDraw / beforeDraw functions #20

Open
10YAR opened this issue Apr 24, 2024 · 1 comment
Open

afterDraw / beforeDraw functions #20

10YAR opened this issue Apr 24, 2024 · 1 comment

Comments

@10YAR
Copy link

10YAR commented Apr 24, 2024

Hello,

I was just wondering if you guys implemented the afterDraw / beforeDraw functions from chart js ?
Because it doesn't seem to work with a <CChartDoughnut> on React.

I'm using these versions :

"@coreui/chartjs": "^4.0.0-rc.0",
"@coreui/coreui": "^5.0.0-rc-2",
"@coreui/react-chartjs": "^3.0.0-rc.0",
"chart.js": "^4.4.2",

and these are the options I use in the <CChartDoughnut> component

      options={{
        responsive: true,
        interaction: {
          intersect: false,
        },
        plugins: {
          afterDraw: (chart) => {
            const ctx = chart.ctx
            ctx.save()
            const centerX = (chart.chartArea.left + chart.chartArea.right) / 2
            const centerY = (chart.chartArea.top + chart.chartArea.bottom) / 2
            ctx.textAlign = 'center'
            ctx.textBaseline = 'middle'
            ctx.font = '16px Arial'
            ctx.fillText(`${percentage.toFixed(2)}%`, centerX, centerY)
            ctx.restore()
          },
          tooltip: {
            enabled: false,
          },
          legend: {
            display: legend,
          },
          title: {
            display: false,
          },
        },
      }}
@xidedix
Copy link
Member

xidedix commented Apr 24, 2024

@10YAR
It seems there is something wrong with your options.plugins config, see:

otherwise, could you provide a working reproduction of this issue, either via a github repo or a stackblitz repro

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