Hug*_*sey 5 javascript reactjs chart.js
我已经通过网络搜索了如何解决这个问题,但没有成功。我见过人们使用背景图片,但这似乎很懒惰且无济于事。我想将标签移动到 45 度角,这样看起来更专业。
我的图表目前看起来像这样 -
但我希望它看起来像这样 -
有人对我如何做到这一点有任何想法吗?
我的代码副本在下面。
new Chart(DummyChart, {
type: "polarArea",
data: {
labels: ["Dummy1", "Dummy 2", "Dummy 3", "Dummy 4"],
datasets: [
{
data: [125, 375, 300, 240],
backgroundColor: "#57C5C8",
borderWidth: 4,
hoverBorderColor: "white",
label: "Dummy Dummy "
}
]
},
options: {
cutoutPercentage: 20,
legend: {
display: false
},
layout: {
padding: 0
},
scale: {
ticks: {
max: 450,
maxTicksLimit: 1,
display: false
},
angleLines: {
display: true
},
pointLabels: {
display: true
}
},
plugins: {
datalabels: {
display: false
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我使用 datalables 插件的解决方案。
https://jsbin.com/bigedugasi/1/edit?html,js,输出
我更新了以前的解决方案以使图表具有响应能力。
plugins: {
datalabels: {
formatter: function(value, context) {
return context.chart.data.labels[context.dataIndex];
},
anchor: 'start',
align: 'end',
offset: 0 // Gets updated
}
},
onResize: function() {
let width = document.getElementById("pie-chart").width
let padding = myChart.options.layout.padding
myChart.options.plugins.datalabels.offset = width/2-padding
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
652 次 |
| 最近记录: |