在使用chartjs绘制柱状图时,默认情况下会有边框,但是有时我们需要控制边框的样式或者去掉边框。针对这个问题,可以通过设置options中的dataset中的borderWidth属性来控制边框宽度,通过设置borderColor属性来控制边框颜色,如果要去掉边框可以将borderWidth设置为0。
代码示例如下:
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1, // 设置边框宽度
borderColor: 'rgba(0,0,0,1)', // 设置边框颜色
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
dataset:{
borderWidth: 0 //