gpt4 book ai didi

javascript - Chart.js 条形图 : Grid color and hide label

转载 作者:太空狗 更新时间:2023-10-29 14:09:28 27 4
gpt4 key购买 nike

我正在尝试在 chart.js 中更改为我的网格的背景颜色,我已经尝试按照文档进行操作并且做了很多研究,但我似乎无法弄清楚。我也想摆脱 top 标签,也找不到简单的方法。我所说的标签是在此处的演示中显示“我的第一个数据集”的标签:http://www.chartjs.org/docs/#bar-chart

解决方法:

<canvas id="myChart"></canvas>
<script>
var ctx = document.getElementById("myChart");

var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
datasets: [{
label: "",
data: [12, 19, 3, 5, 2, 3, 4],
backgroundColor: "rgba(3, 118, 195, 0.5)",
borderColor: "rgba(0, 158, 219, 1)",
borderWidth: "2",
}]
},
options: {
legend:{
display: false
},
scales: {
xAxes: [{
gridLines: {
show: true,
color: "F3F3F3",
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},

}
});

</script>

谢谢!

最佳答案

要隐藏标签,即只是图例:在 options 中使用以下配置:

legend:{
display:false
}

因此在您的代码中:

options: {
legend:{
display:false
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}

并且,对于背景颜色,请为 Canvas 元素使用 css:

<canvas id="myChart" style="background-color: grey;">

希望这对你有用!

关于javascript - Chart.js 条形图 : Grid color and hide label,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37198527/

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