gpt4 book ai didi

javascript - 如何在 chart.js 中为极坐标图区域添加标签

转载 作者:行者123 更新时间:2023-12-05 08:09:00 24 4
gpt4 key购买 nike

我正在显示极坐标图。但是如何在如下屏幕的饼图中显示标签

Chart

这是我的代码: Code

<canvas id="myChart"></canvas>
<script>

var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'polarArea',
data: {
labels: ["Harmonia wewnetrzna", "Relacje towarzyskie", "Relacje damsko-meskie", "Finanse", "Zdrowie", "Hobby i czas wolny"],
datasets: [{
backgroundColor: [
"rgba(46, 204, 113, 0.7)",
"rgba(52, 152, 219, 0.7)",
"rgba(149, 165, 166, 0.7)",
"rgba(155, 89, 182, 0.7)",
"rgba(241, 196, 15, 0.7)",
"rgba(231, 76, 60, 0.7)"

],
data: [50, 70, 20, 45, 90, 70],
pointBackgroundColor: "rgba(255,99,132,1)",
pointBorderColor: "red",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(255,99,132,1)"
}]

},
options:{
legend: {
display: true,
position: 'bottom'
},
animation : false,
scale:{
lineArc: true,
angleLines: {
color: "rgba(204, 255, 51, 0.5)"
},
pointLabels: {
fontColor: "ff6666"
},
gridLines : {
color : "pink"
},
ticks: {
min: 0,
max: 100
}
}

}
});
</script>

最佳答案

您可以在图表的选项部分添加工具提示,它们会在悬停时显示,希望这段代码有所帮助(我知道这不是要求的部分内的显示,但在问题解决之前可能会有所帮助)。

    options: {
responsive: true,
legend: {
display: false,
},
layout: {
padding: 5
},
hover: {
mode: 'nearest'
},
animation: {
duration: 2000
},
tooltips: {
titleFontSize: 0,
bodyFontSize: 12,
bodySpacing: 12,
displayColors: false,
callbacks: {
label: function (tooltipItem, data) {
var dataset = data.datasets[tooltipItem.datasetIndex];
var tooltip = dataset.tooltip[tooltipItem.index];
return items;
},
}
},
}

关于javascript - 如何在 chart.js 中为极坐标图区域添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42977295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com