彻底阅读了图表。JS文档后,我找不到任何方法来获取甜甜圈图的 Innerradius
。
这是我从Chart.js 2.x到
Chart.js 2.x中发现的众多问题之一,为了获得甜甜圈图的内部半径,我会做:
beforeDatasetsUpdate: c => {
const radius = c.innerRadius;
}
现在,在Chart.js中3.x,我发现它深深地嵌套了:
beforeDatasetsUpdate: c => {
const radius = c._metasets[0].data[0].innerRadius;
}
官方说:
图表。Innerradius现在居住在甜甜圈,派和北极星控制器
但是有什么方法可以直接访问它吗?我上面提到的方式似乎是一个黑客。
After thoroughly reading the Chart.js documentation, I didn't find any method to get the innerRadius
of a doughnut chart.
This is one of the many issues I found after migrating from Chart.js 2.x to 3.x
In Chart.js 2.x, to get the inner radius of a doughnut chart, I would do:
beforeDatasetsUpdate: c => {
const radius = c.innerRadius;
}
Now, in Chart.js 3.x, I found it deeply nested in :
beforeDatasetsUpdate: c => {
const radius = c._metasets[0].data[0].innerRadius;
}
The official migration guide says:
Chart.innerRadius now lives on doughnut, pie, and polarArea controllers
But is there any way to directly access it? The way I mentioned above seems like a hack.
发布评论
评论(1)
每个数据集都有自己的控制器,因此没有全局单一的甜甜圈控制器。因此,如果您想获得控制器,则需要从数据集的元数据中获取它:
Each dataset has its own controller so there is no global single doughnut controller. So if you want to get the controller you need to get it from the meta of the dataset: