-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Label inside donut chart #78
Comments
me too +1 |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Would putting this data in an HTML absolutely positioned element over the top of the doughnut not be a better solution than adding more to chart.js to achieve this? |
+1 |
It's fairly easy to do this with HTML, but it would be nice if the chart exposed some sort of event API to hook into to populate the value. |
+1 |
1 similar comment
+1 |
+1 Although, as well as a label I think it would also be good to have it auto add the sum-total of the data put in, or the data type etc I may work on a way to pass this in if I get the chance this week, though doing the total automatically shouldn't be too much of a stretch. |
+1 |
is there any option to write label for each section? |
+1 Yes, this can be accomplished easily with HTML, but I would love to see something like this implemented into the core. |
+1 |
1 similar comment
+1 |
+2 |
+3 |
-1 I think the HTML approach is better. The label will only make sense inside the canvas if it is very small. I would consider these to be a special-purpose of pie chart: single value pie charts with label in the middle. Recommending implementation should be outside chart.js |
@fulldecent The advantage to having a label/legend built into the chart is that the user can take the image itself and use it in another doc or presentation without having to re-create the legend. In fact, for my users, this is an absolute requirement - a chart without a legend is useless to them. |
+1 |
1 similar comment
+1 |
tagging: NEW CHART TYPES |
This may be useful for some of you since I've had the same requirement a few weeks ago. |
Any solution about it (http://stackoverflow.com/questions/20911919/put-sum-of-values-in-center-of-doughnut-chart) ? |
+1 |
I don't think having a label in the middle of the chart is quite yet needed in the core logic of chartjs. We will probably soon be adding new event-hook-like api's into the core though, that would allow you to achieve this quite easily in a custom implementation along with a lot of other things. |
I added the center label easily with an absolute positioned HTML element, though having this feature natively to ChartJS would be cool. What brought me here and what I'm really pining for is something like @dannysindra 's example of having percentage labels (or even just having the tooltips always on) inside each area of the chart. I've tried implementing it in our Angular app but am having trouble. A built in solution to do this seems like a no-brainer. Add my voice to that feature request! |
@emn178 just tried your solution and its working! you are awesome! |
to get this working I extended the draw function for Chart,Tooltip with the following:
You can now add on the options for tooltip whether to display percentage or not, and it'll appear in the center when hovering. The sum calculation is using lodash, this could be a simple function |
Hi, var ctx2 = document.getElementById("PieChart2");
When hovering, it is displays the data. But i want it be appeared always. Any help! Thanks in Advance! |
+1 |
Any news on whether this is being still being worked on or planned for a release as I noticed it has been added and removed to milestones multiples times. |
@ShawnCorrigan that is excellent as it's Edit: actually found an issue with this. Destroy / re adding the chart - the text keeps on adding on and get's blurry. |
Any of this solutions is working on my code, can someone help me? Here is the HTML code: and javascript code: Thank you on advise |
Here is what worked for me. Thanks to google and such a great community out there. 😄 : CLOSED
So what it actually does is, it takes the height, width of the chart and then places the desired text at half the height and width of your chart. You don't have to worry about the responsiveness and changing size(handled similarly) of the chart. Its completely dynamic this way. |
I have almost no experience with JavaScript, and I need to put a FontAwesome icon inside the doughnut chart. It would be a chart to show the temperature, and the thermometer icon should be in it's middle. Could anyone help me? |
@gabarreto Here is not the best place to ask questions about implementation. I recommend creating a question in StackOveflow with the tag chart.js. |
To expand on the plugin provided by @abhinav1602 to center text, I did the following to show percentage on my doughnut charts:
An example of my usage:
|
I've added a new plugin that allows to display multiple lines of text in the center of the doughnut on Github: chartjs-plugin-doughnutlabel if that helps. See the Demo. |
To place the text in the center, you need to consider the size of the font size. another fix for the solution of gbrits. in the textY `object:
|
I'm going to close this issue since many solutions exist now and maintainers decided to not add it to the core package. I think the best approach is to use a plugin such as chartjs-plugin-doughnutlabel (thanks @ciprianciurea) and at some point, the datalabels plugin may also offer a (limited) way to center labels. @ciprianciurea feel free to open a PR adding it to the docs. |
Below the code work for me, but in the centre text (100%) appearing in another chart in same page !.
|
Does anyone have an updated plugin for center doughnut labels for chartJS v4? |
AFAIK there isn't. There is a pending PR in chartjs-plugin-annotation for that: chartjs/chartjs-plugin-annotation#825 |
Can you please reopen this issue? Seems like no one cares about the plugin. |
Hi,
I would like to be able to add a label inside a donut chart like this charts
Thks
The text was updated successfully, but these errors were encountered: