我刚试过Chartjs并面临两个问题。我愿意展示一个双饼(一个在另一个上面),以便将一个细节显示在另一个中。
问题:对于值和子值,我有不同的标签。但是,在构建第二张图表时,chartjs会再次进行交互,导致前三个标签翻倍。我想要的是在小馅饼上放置3个第一个标签,在大馅饼上放置其他标签。
感谢您帮我解决这个问题。
let values = [309, 42, 3]
let subvalues = [74, 156, 79, 12, 22, 8, 0, 2, 1]
let labels = ["visits", "drafts", "contact", "T2", "T3", "T4", "T2", "T3", "T4", "T2", "T3", "T4"]
let chartjsWorkflowPieCtx = document.getElementById('chartjs-workflow-pie')
let chartjsWorkflowPie = new Chart(chartjsWorkflowPieCtx, {
type: 'pie',
data: {
labels: labels,
datasets: [
{
label: 'Details',
backgroundColor: [
shadeBlend(0.2, '#5782BB'),
shadeBlend(0.4, '#5782BB'),
shadeBlend(0.6, '#5782BB'),
shadeBlend(0.2, '#64D7D6'),
shadeBlend(0.4, '#64D7D6'),
shadeBlend(0.6, '#64D7D6'),
shadeBlend(0.2, '#f07dd8'),
shadeBlend(0.4, '#f07dd8'),
shadeBlend(0.6, '#f07dd8'),
],
borderSize: 0,
borderColor: 'rgba(255, 255, 255, 0)',
data: subvalues
},
{
label: "Global",
backgroundColor: [
'#7487bb',
'#64D7D6',
'#C4AFF0'
],
borderSize: 0,
borderColor: 'rgba(255, 255, 255, 0)',
data: values
},
]
}
})
function shadeBlend(p, c0, c1) {
var n = p < 0 ? p * -1 : p, u = Math.round, w = parseInt;
if (c0.length > 7) {
var f = c0.split(","), t = (c1 ? c1 : p < 0 ? "rgb(0,0,0)" : "rgb(255,255,255)").split(","), R = w(f[0].slice(4)),
G = w(f[1]), B = w(f[2]);
return "rgb(" + (u((w(t[0].slice(4)) - R) * n) + R) + "," + (u((w(t[1]) - G) * n) + G) + "," + (u((w(t[2]) - B) * n) + B) + ")"
} else {
var f = w(c0.slice(1), 16), t = w((c1 ? c1 : p < 0 ? "#000000" : "#FFFFFF").slice(1), 16), R1 = f >> 16,
G1 = f >> 8 & 0x00FF, B1 = f & 0x0000FF;
return "#" + (0x1000000 + (u(((t >> 16) - R1) * n) + R1) * 0x10000 + (u(((t >> 8 & 0x00FF) - G1) * n) + G1) * 0x100 + (u(((t & 0x0000FF) - B1) * n) + B1)).toString(16).slice(1)
}
}
&#13;
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="chartjs-workflow-pie"></canvas>
</body>
</html>
&#13;