我用的是最新的ChartJS。如何在条形图中实现这种倒边框半径?
const myData = {
labels: ["1 Jan", "2 Jan", "3 Jan", "4 Jan", "5 Jan", "6 Jan", "7 Jan", "8 Jan"],
datasets: [{
label: 'Employee',
backgroundColor: background_1,
data: [12, 59, 5, 56, 58, 12, 59, 87, 45],
borderRadius: 100,
barPercentage: 0.5, // Adjust this value to change the width of the bars
categoryPercentage: 0.3,
borderColor: 'white',
borderWidth: 1
}, {
label: 'Engineer',
backgroundColor: background_2,
data: [12, 59, 5, 56, 58, 12, 59, 85, 23],
borderRadius: 100,
barPercentage: 0.5, // Adjust this value to change the width of the bars
categoryPercentage: 0.3,
borderColor: 'white',
borderWidth: 1,
borderSkipped: 'middle'
}]
}
这是我目前的数据。
1条答案
按热度按时间tct7dpnv1#
chart.js的堆叠条形图已经完成了大部分工作。
创建所述圆形边框的第一步是将
borderRadius
设置为对象,因此内部条也会获得圆角,例如,borderRadius: {topLeft: 100, topRight: 100, bottomLeft: 100, bottomRight: 100}
而不是borderRadius: 100
,请参阅文档中有关堆叠图表的borderRadius的提示。然后,我们将不得不在第一条下延伸第二条(或在相同符号和堆栈的前一条下延伸第n条),这样你就可以在第二条的底部获得“负半径”效果。
这可以通过一个插件来实现,例如在
afterDatasetUpdate
处理程序中进行计算。必须保留关于前一个条形图的信息,区分正域和负域,并通过堆栈ID进行索引。所有这些都是细节,最好在代码中看到。