javascript ChartJS - 多环圆环图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29254121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ChartJS - Donut charts with multiple rings
提问by Soni Ali
Is it possible to create a donut chart with multiple rings using ChartJS as shown below?
是否可以使用 ChartJS 创建具有多个环的圆环图,如下所示?
回答by Varun Mittal
You can find out the solution at fiddle link
您可以在小提琴链接中找到解决方案
var ctx = document.getElementById("chart-area").getContext("2d");
var myDoughnut = new Chart(ctx, config);
var config = {
type: 'doughnut',
data: {
datasets: [{
data: [
10,20,30
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C"
],
}, {
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C"
],
}],
labels: [
"Red",
"Green",
"Yellow"
]
},
options: {
responsive: true
}
};
回答by Matvei Nazaruk
You need to add multiple datasets into chart. they will be displayed as you need. Please look into their own sampleof pie chart. You can download and open it locally as example. There they have multiple datasets, that makes chart look like you need.
您需要将多个数据集添加到图表中。它们将根据您的需要显示。请查看他们自己的饼图示例。例如,您可以在本地下载并打开它。他们有多个数据集,这使图表看起来像您需要的。
Hope that it helped.
希望它有所帮助。