Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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?

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.

None yet

2 participants