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

How do you add text at the center of a doughnut chart? #183

Open
Vruttant opened this issue Apr 6, 2021 · 2 comments
Open

How do you add text at the center of a doughnut chart? #183

Vruttant opened this issue Apr 6, 2021 · 2 comments
Labels
question Further information is requested

Comments

@Vruttant
Copy link

Vruttant commented Apr 6, 2021

Describe your question

How do you add text at the center of a doughnut chart?

Which Blazor project type is your question related to?

  • Client-Side

Which charts is this question related to?

  • Doughnut Chart

JavaScript equivalent

{       
        ...
        var text = "75%",
        textX = Math.round((width - ctx.measureText(text).width) / 2),
        textY = height / 2;
        ctx.fillText(text, textX, textY);
        ctx.save();
        ...
}

Additional context

https://jsfiddle.net/cmyker/ooxdL2vj/

@Vruttant Vruttant added the question Further information is requested label Apr 6, 2021
@Daanziaat
Copy link

This response might be kinda late since I just recently got into ChartJS, my apologies.

I kinda had the same problem and was searching for a solution around here. At the end, I have found a solution.

I solved this by adding a negative padding on the Title (which puts the Title of the chart in the center), maybe this works for you as well.

Example:

CutoutPercentage = 95,
and
Title = new OptionsTitle { Display = true, Text = "title", Padding = -130, FontSize = 40, }

Cheers

@Vruttant
Copy link
Author

Hey, thanks for your reply! I actually asked this when I was interning at a company last year haha. Good to know that you were able to solve it. As far as I remember I had used CSS (absolute) positioning to center a regular span tag over the component. That worked since our app's usage was limited to laptop devices.

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

No branches or pull requests

2 participants