Skip to content

Conversation

@crash481
Copy link

@crash481 crash481 commented Mar 28, 2024

Issue 🔗

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
Copy link

gabors commented Mar 29, 2024

@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
Copy link
Author

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 crash481 force-pushed the feature/corner-radius branch 2 times, most recently from 2047fe6 to a29a1a1 Compare March 29, 2024 02:23
@gabors
Copy link

gabors commented Mar 29, 2024

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 crash481 force-pushed the feature/corner-radius branch 2 times, most recently from f527af1 to 1b9bc5b Compare March 29, 2024 02:39
@crash481
Copy link
Author

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
Copy link

gabors commented Mar 29, 2024

@crash481 Works great

@gabors
Copy link

gabors commented Apr 1, 2024

@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
Copy link

gabors commented Apr 4, 2024

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

public var cornerRadius: CGFloat = 0.0

/// array of corners to be rounded
open var roundedCorners: UIRectCorner = [] {
Copy link

@ankushkushwaha ankushkushwaha Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to make roundedCorners open?

@momo88xiaowu
Copy link

@gabors
image
没有合并到master分支成功

@danielgindi danielgindi merged commit 6626a2b into ChartsOrg:master May 13, 2025
@huyparody
Copy link

@crash481 Is there any chances you can support stacked bar charts?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants