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

Rounding the corners of bars #1066

Open
ricburton opened this issue May 24, 2016 · 25 comments
Open

Rounding the corners of bars #1066

ricburton opened this issue May 24, 2016 · 25 comments
Labels

Comments

@ricburton
Copy link

screen shot 2016-05-23 at 17 58 03

What would be the best way to achieve this effect? I’m guessing I’ll need to modify the way Charts draws in some way.

@liuxuan30
Copy link
Member

liuxuan30 commented Jun 2, 2016

I have been investigated on this a few months ago. It's possible, however, we need to change how we create the bar rect. Not so hard, but some decent work is needed

@liuxuan30
Copy link
Member

That's what I investigated before, you can try first. I am still looking for other options.

in public func drawDataSet: of bar chart renderer

                let cornerRadius: CGFloat = CGRectGetWidth(barRect) <= 5 ? 1.0 : 2.0
                let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: UIRectCorner.AllCorners, cornerRadii: CGSizeMake(cornerRadius, cornerRadius))

                let roundedPath = bezierPath.CGPath

                // if drawing the bar shadow is enabled
                if (drawBarShadowEnabled)
                {
                    barShadow.origin.x = barRect.origin.x
                    barShadow.origin.y = viewPortHandler.contentTop
                    barShadow.size.width = barRect.size.width
                    barShadow.size.height = viewPortHandler.contentHeight

                    CGContextSetFillColorWithColor(context, dataSet.barShadowColor.CGColor)
//                    CGContextFillRect(context, barShadow)
                    CGContextAddPath(context, roundedPath)
                    CGContextFillPath(context)
                }

                // Set the color for the currently drawn value. If the index is out of bounds, reuse colors.
                CGContextSetFillColorWithColor(context, dataSet.colorAt(j).CGColor)
//                CGContextFillRect(context, barRect)
                CGContextAddPath(context, roundedPath)
                CGContextFillPath(context)

@ricburton
Copy link
Author

Thanks so much for the feedback! I’ll play with this.

@liuxuan30
Copy link
Member

yeah I don't think it's a great one, especially your bars are very thin

@FahadIqbal
Copy link

its not working can anyone help me to do it ?

@CoderZyc
Copy link

@liuxuan30请问下,这个在最新的版本还可以?

@FahadIqbal
Copy link

FahadIqbal commented Dec 27, 2016 via email

@liuxuan30
Copy link
Member

@CoderZyc not merged yet. there is a PR for it.

@acegreen
Copy link

Hey @liuxuan30 this looks awesome, any ETA on this?

@liuxuan30
Copy link
Member

not really. I don't think it's perfect, and not having time to investigate other options.

@acegreen
Copy link

@liuxuan30 no worries, there is another solution that worked out nicely #1917

@liuxuan30
Copy link
Member

@acegreen basically they work the same way. Just wrap up nicely. Since more people asking, I am reopening this topic

@kirti0525
Copy link

Hi,
Can you please help me with adding vertical dashed lines in between bars in bar graph and making the top corner of the bar slightly curvy . I am uploading the screenshot for the sample.
screenshot_2018-09-06 zeplin - project

tigloo added a commit to tigloo/Charts that referenced this issue Nov 6, 2019
https://github.com/life360/Charts/pull/1/files (Pull request into forked repository)
ChartsOrg#3754 (Pull request into original repository)
ChartsOrg#1066 (Feature request in original repository)
tigloo added a commit to tigloo/Charts that referenced this issue Nov 6, 2019
https://github.com/life360/Charts/pull/1/files (Pull request into forked repository)
ChartsOrg#3754 (Pull request into original repository)
ChartsOrg#1066 (Feature request in original repository)
@lalkrishna
Copy link

Any update on this?

@jacobsapps
Copy link

It looks like this and a similar pull request - #1917 - have been dead for at least 2 years. Is it worth throwing away all the work they took?

@kelvinofula
Copy link

Is there a way to achieve the same with the slices of a piechart?

@scinfu
Copy link

scinfu commented Jan 22, 2021

+1

1 similar comment
@JanC
Copy link

JanC commented Jan 25, 2021

+1

@4np
Copy link
Contributor

4np commented Jan 29, 2021

If #4297 was merged, you could just override the renderer.

@scinfu
Copy link

scinfu commented Feb 12, 2021

Not merged :/

@AppCodeZip
Copy link

Recently I have been working on a project, to which I have added a chart library and display a beautiful rounded bar chart in swift. We can achieve this functionality easily. Please check this demo.
Screenshot 2021-03-27 at 7 42 42 PM

@nunocaseiro
Copy link

+1

@Eramirez06
Copy link

when this will be merge?

@iOSLeadGautam
Copy link

Hi All,

I want to get a Barchart with rounded bar corners and pie having rounded corners for every section.
Waiting for this PR to be merged.

Any advise would be appreciated.

Also can someone suggest me how to get pie chart like added image.

PieChart_Requirement

@BenjaminAlbrectsen
Copy link

Is it still not possible to round the corners? #1066 (comment) does not work for me, since I'm using SPM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests