Chart.js制作了一些令人敬畏的图表,到目前为止,它对我来说一直很好。我想创建这样的东西:
是否可以?
最佳答案
我认为,从Chart.js的2.0版开始,这是可能的。这是一个例子:
var ctx = document.getElementById("myChart");
var chartData = {
labels: [
"Red",
"Blue",
"Yellow"
],
datasets: [{
data: [300, 50, 100],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}, {
data: [200, 100, 25, 25, 66, 34],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56",
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56",
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}]
};
var pieChart = new Chart(ctx, {
type: 'pie',
data: chartData
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
<canvas id="myChart" width="300" height="300"></canvas>
关于javascript - Chartjs嵌套饼图/甜甜圈图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28806808/