admin管理员组文章数量:1390685
I am doing data visualizations with react
, react-chartjs-2
, and chart.js
version 2.2.1. There is a possibly related answer to this question here (look for 17.06.16 update), but I'm not sure what Chart.pluginService.register
is or whether it is patible with React. So far it hasn't worked for me.
I am simply looking to place a label inside the doughnut that is the sum of all data
subsets. I assume this is nested somewhere in the doughnut chart's options, but I haven't found it yet.
I am doing data visualizations with react
, react-chartjs-2
, and chart.js
version 2.2.1. There is a possibly related answer to this question here (look for 17.06.16 update), but I'm not sure what Chart.pluginService.register
is or whether it is patible with React. So far it hasn't worked for me.
I am simply looking to place a label inside the doughnut that is the sum of all data
subsets. I assume this is nested somewhere in the doughnut chart's options, but I haven't found it yet.
- Did you find a solution to this? – LucaSpeedStack Commented Mar 31, 2017 at 5:32
- Negative. I had to make a separate value using the same data on my ponent – Kwhitejr Commented Mar 31, 2017 at 19:37
- Please refer below code. This is perfectly work. https://stackoverflow./questions/54040320/pass-context-to-options-on-react-chartjs-2 – donkey Commented Mar 15, 2023 at 8:23
1 Answer
Reset to default 5In react-chartjs-2
you can access the datasets through chart.config.data.datasets
.
So for:
data = {
labels: [
'Red',
'Green',
'Yellow'
],
datasets: [{
data: [300, 50, 100],
...
Inside the draw
callback in Chart.helpers.extend
you can use:
var sum = 0;
for (var i = 0; i < this.chart.config.data.datasets[0].data.length; i++) {
sum += this.chart.config.data.datasets[0].data[i];
}
Here's an example Codepen: http://codepen.io/anon/pen/xqMQQB?editors=1010
本文标签: javascriptReactChartjs 20 How to put a label inside of a doughnut chartStack Overflow
版权声明:本文标题:javascript - React + Chart.js 2.0: How to put a label inside of a doughnut chart? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744661926a2618293.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论