gpt4 book ai didi

charts - Chartjs 数据标签更改饼图中显示的文本的字体和颜色

转载 作者:行者123 更新时间:2023-12-02 06:41:03 24 4
gpt4 key购买 nike

我正在使用chartjs

datalabels

我已经从 ChartJS 及其插件中实现了我需要的一切。这是我的最终结果enter image description here

这是我的代码

  ( function ( $ ) {
"use strict";
/////////////Pie chart START here//////////////////////////////
var ctx = document.getElementById( "pieChart" );
ctx.height = 130;
var myChart = new Chart( ctx, {
type: 'pie',
data: {
datasets: [ {
data: [ 40, 20, 10, 3, 7, 15, 4, 52 ],
backgroundColor: [
"rgba(0,128,128)",
"rgba(255,20,147)",
"rgba(0,0,128)",
"rgba(0,128,0)",
"rgba(128,0,0)",
"rgba(255,0,0)",
"rgba(218,112,214)",
"rgba(70,130,180)"
],
hoverBackgroundColor: [
"rgba(0,128,128)",
"rgba(255,20,147)",
"rgba(0,0,128)",
"rgba(0,128,0)",
"rgba(128,0,0)",
"rgba(255,0,0)",
"rgba(218,112,214)",
"rgba(70,130,180)"
]
} ],
labels: [
"Open",
"On-Hold (Need Spares)",
"In-Process",
"Closed",
"Re-Open",
"On-Hold (Condemnation)",
"On-Hold (For Decision)",
"On-Hold (For Revision)"
]
},
options: {
responsive: true,
legend: {
position: 'left',
labels: {
fontSize:17,
}
}
}

} );
/////////////Pie chart END here//////////////////////////////

} )( jQuery );

现在我需要更改饼图每个切片内显示的文本(数据)的字体大小和颜色。有什么帮助吗?

P.s:我使用的是chart.js v2.7.2

最佳答案

我使用 Chart js 和 datalebels 来,并且可以这样做:

plugins: {
datalabels: {
color: #ffffff,
formatter: function (value) {
return Math.round(value) + '%';
},
font: {
weight: 'bold',
size: 16,
}
}
}

当然,在我的示例中,我添加了“%”,这就是我在格式化程序中使用该函数的原因。

请记住,“插件”是图表中“选项”的一部分。

Here是插件数据标签的页面,其中包含您可以执行的更多操作

关于charts - Chartjs 数据标签更改饼图中显示的文本的字体和颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52797964/

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