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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 10:17:17  来源:igfitidea点击:

ChartJS - Donut charts with multiple rings

javascriptchart.jsdonut-chart

提问by Soni Ali

Is it possible to create a donut chart with multiple rings using ChartJS as shown below?

是否可以使用 ChartJS 创建具有多个环的圆环图,如下所示?

multi series donut chart

多系列圆环图

回答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.

希望它有所帮助。

回答by Gorodeckij Dimitrij

I know it was old question, but have stuck yesterday into same, so far best that i have touch is Chart js and this is a pluginwho does exactly that (and even more!)

我知道这是个老问题,但昨天一直坚持下去,到目前为止,我接触到的最好的是 Chart js,这是一个完全可以做到这一点的插件(甚至更多!)