javascript - How to get rounded corner in c3js bar charts - Stack Overflow

Looks like none of the d3 based charting libraries like nvd3, c3js support rounded corner for bar chart

Looks like none of the d3 based charting libraries like nvd3, c3js support rounded corner for bar charts.

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?

Looks like none of the d3 based charting libraries like nvd3, c3js support rounded corner for bar charts.

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?

Share Improve this question asked Jan 21, 2015 at 14:08 ChetanChetan 2,7562 gold badges17 silver badges21 bronze badges 2
  • If using d3.js families, each bar of bar chart must be a 'rect' element, and rect element has 'rx' and 'ry' attributes. You can set those attributes to create round corner. – toshi Commented Jan 21, 2015 at 14:22
  • No, the svg element used is PATH by c3js – Chetan Commented Jan 21, 2015 at 14:57
Add a ment  | 

1 Answer 1

Reset to default 8

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.

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.

There are still several cases:-

1) rounded corners for stacked bar charts.

2) rounded corners for negative values, bars pointing downwards or opposite direction.

rounded corner bars jsFiddle

rounded corner c3js bar charts snapshot

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
}
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744132575a4559907.html

相关推荐

  • javascript - How to get rounded corner in c3js bar charts - Stack Overflow

    Looks like none of the d3 based charting libraries like nvd3, c3js support rounded corner for bar chart

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信