简体   繁体   English

如何在c3js条形图中获得圆角

[英]How to get rounded corner in c3js bar charts

Looks like none of the d3 based charting libraries like nvd3, c3js support rounded corner for bar charts. 看起来没有像nvd3这样基于d3的图表库,c3js支持条形图的圆角。

I need bars in the bar charts to look like as shown below, with gradient and rounded corners for my project. 我需要条形图中的条形如下图所示,我的项目有渐变和圆角。

在此输入图像描述

Any hack or config to achieve this in c3js? 在c3js中实现这个的任何hack或配置?

Need to override c3js function generateDrawBar and provide logic to get rounded corner, generally c3js path element consists of four points corresponding to four corners of the bar. 需要覆盖c3js函数generateDrawBar并提供获取圆角的逻辑,一般c3js路径元素由对应于条形四个角的四个点组成。

Now you need to provide logic to have multiple points at the top-left and top-right corners of the par to smoothen the bar corners. 现在,您需要提供逻辑,以便在par的左上角和右上角有多个点,以平滑条形角。

There are still several cases:- 还有几种情况: -

1) rounded corners for stacked bar charts. 1)圆角用于堆积条形图。

2) rounded corners for negative values, bars pointing downwards or opposite direction. 2)圆角为负值,条形指向下方或相反方向。

rounded corner bars jsFiddle 圆角酒吧jsFiddle

rounded corner c3js bar charts snapshot 圆角c3js条形图快照 圆角c3js条形图快照

var chart = c3.generate({
bindto: '#chart',
padding: {
    left: 200,
    right: 100,
    top: 20,
    bottom: 20
},
data: {
    x: 'x',
    labels: true,
    columns: [
        ['data1',40, 30, 200, 100, 400, 150, 250, 50, 100, 250,67,190,48,123,76,54,254],
        ['x','Travel and Hospitality','Life Science and Pharma', 'Saas and Cloud', 'Hi-tech Manufacturing', 'Software', 'Business Services', 'Govt/Public Sector', 'Energy', 'Manufacturing', 'Healthcare','Media','Internet','Retail','Biotech','Automobile','Consumer Goods','Financial Services']
    ],
    type: 'bar'
},
axis: {
    rotated: true,
    x: {
        type: 'category',
        tick:{
            multiline: false
        }
    }
},
legend: {
    show: false
},
tooltip: {
    show: false
},
bar: {
    width: {
        ratio: .7
    },
    spacing: 2
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM