Charts icon indicating copy to clipboard operation
Charts copied to clipboard

Posibility to add Corner Radius for rounded bars in bar chart

Open crash481 opened this issue 10 months ago • 7 comments

Issue :link:

Many years people needs to fork this repo to implement rounded bars in bar chart. In pull requests exists also fixing same issue, but my implementation is more configurable

  1. You can add corner radius for specific corners only (for example only for topLeft + topRight corner)
  2. Corner radius works also for highlight when select bars

How to use:

var dataSet = BarChartDataSet(entries: yVals)
dataSet.cornerRadius = 6
dataSet.roundedCorners = .allCorners
       // or
dataSet.roundedCorners = [.topLeft, .topRight]
Screenshot 2024-03-29 at 1 15 25

crash481 avatar Mar 28 '24 22:03 crash481

@crash481 found an interesting "bug" if a chart has both negative and positive values. If you specify topLeft and topRight we end up with this, which is totally expected but makes it less useful on these types of charts. So in these cases we can round all corners. Unless we find a way to add the rounding parameter to the BarChartDataEntry

image

gabors avatar Mar 29 '24 00:03 gabors

Yes, it needs to check if value is negative and invert values. One moment I will check if it is fast - I will push

crash481 avatar Mar 29 '24 01:03 crash481

Thanks so much! I'll try it out.

The highlighting works great btw.

Now if your can also add rounded corners to the pie chart... 😊

gabors avatar Mar 29 '24 02:03 gabors

Okay, it was not so fast, but I did it This is not case for my project, but hope this will help you and others!

Screenshot 2024-03-27 at 5 36 39

Pull request is now even better I would be grateful if you test the work on HorizontalBarChart and send a screenshot of the result here

crash481 avatar Mar 29 '24 02:03 crash481

@crash481 Works great

gabors avatar Mar 29 '24 04:03 gabors

@crash481 Noticed a small bug: when the dataSet.roundedCorners = .allCorners is used the highlighted bottom corners disappear on this chart: image

But they work fine on this chart: image

gabors avatar Apr 01 '24 01:04 gabors

@crash481 were you able to figure out the issue above?

gabors avatar Apr 04 '24 16:04 gabors