ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.43k stars 5.97k forks source link

Posibility to add Corner Radius for rounded bars in bar chart #5163

Open crash481 opened 3 months ago

crash481 commented 3 months ago

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
gabors commented 3 months ago

@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
crash481 commented 3 months ago

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

gabors commented 3 months ago

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... 😊

crash481 commented 3 months ago

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

gabors commented 3 months ago

@crash481 Works great

gabors commented 3 months ago

@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 commented 3 months ago

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