chart.js 饼图中的两种色调
Two tone colours in chart.js pie chart
有没有人在 chart.js 饼图的一部分中遇到过两种色调的效果,如屏幕截图所示?
知道如何解决这个问题吗?它不会一直出现。这是一个显示性别百分比的简单饼图。
抱歉,我忘了包含代码。
var xitems = ['male','female'];
var yitems = [478,522];
new Chart(document.getElementById("chartcanvas"), {
type: 'pie',
data: {
labels: xitems,
datasets: [
{
data: yitems,
backgroundColor: ["#8DB6CD","#FFB6C1","#DC143C","#800080","#0000FF","#00C5CD","#00EE00","#FFFF00","#FFD700","#FFA500","#8B5A00","#FF4500","#FA8072","#FF3E96",
"#BA55D3","#191970","#00FF7F","#B7B7B7","#000000","#006400","#ADFF2F","#EEEE00","#3D59AB","#AB82FF","#CDB5CD","#FF69B4",
"#FF0000"],
fill: false
}
]
},
options: {
tooltips: {
enabled: false,
},
showPercentage: true, //Enables percentages on the pie
}
});
我刚刚查看了 JS Fiddle 并替换了对我有用的 Chart JS 脚本链接。我使用的是 CDNJS.
中的 2.7.0 版而不是 2.4.0 版
我不确定您是否也需要这两个库。只需使用 https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.bundle.min.js
就足够了。
希望对您有所帮助。
有没有人在 chart.js 饼图的一部分中遇到过两种色调的效果,如屏幕截图所示?
知道如何解决这个问题吗?它不会一直出现。这是一个显示性别百分比的简单饼图。
抱歉,我忘了包含代码。
var xitems = ['male','female'];
var yitems = [478,522];
new Chart(document.getElementById("chartcanvas"), {
type: 'pie',
data: {
labels: xitems,
datasets: [
{
data: yitems,
backgroundColor: ["#8DB6CD","#FFB6C1","#DC143C","#800080","#0000FF","#00C5CD","#00EE00","#FFFF00","#FFD700","#FFA500","#8B5A00","#FF4500","#FA8072","#FF3E96",
"#BA55D3","#191970","#00FF7F","#B7B7B7","#000000","#006400","#ADFF2F","#EEEE00","#3D59AB","#AB82FF","#CDB5CD","#FF69B4",
"#FF0000"],
fill: false
}
]
},
options: {
tooltips: {
enabled: false,
},
showPercentage: true, //Enables percentages on the pie
}
});
我刚刚查看了 JS Fiddle 并替换了对我有用的 Chart JS 脚本链接。我使用的是 CDNJS.
中的 2.7.0 版而不是 2.4.0 版我不确定您是否也需要这两个库。只需使用 https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.bundle.min.js
就足够了。
希望对您有所帮助。