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

LineChart. Custom LineChartRenderer does not cross chart border #1480

Closed
bizibizi opened this issue Sep 19, 2016 · 9 comments
Closed

LineChart. Custom LineChartRenderer does not cross chart border #1480

bizibizi opened this issue Sep 19, 2016 · 9 comments

Comments

@bizibizi
Copy link

bizibizi commented Sep 19, 2016

I implemented custom LineChartRenderer by subclassing it. I use bold to as a custom highlighting. My issue is that first and last dots are cropped by the chart borders. Is it possible to fix that?

screen shot 2016-09-19 at 17 20 17

@Huang-Libo
Copy link

Huang-Libo commented Sep 19, 2016

I have similar problem: my line chart is cropped on the top and bottom, this happens when I update to v3.0 with swift 3.0

top:
2016-09-19 11 24 00

bottom:
2016-09-19 11 55 27

@bizibizi
Copy link
Author

thanks, but I need dots

@bizibizi
Copy link
Author

Try this:

    let min = Double(Int(yValues.minElement()!) - 5)
    let max = Double(Int(yValues.maxElement()!) + 5)

    chartView.leftAxis.startAtZeroEnabled = false
    chartView.leftAxis.customAxisMax = max
    chartView.leftAxis.customAxisMin = min

@danielgindi
Copy link
Collaborator

If you want- you can make a PR with a feature to turn off clipping

@liuxuan30
Copy link
Member

turn off clipping may have side effects showing additional dots. I tried to implement this but complicated than I first thought

@bizibizi
Copy link
Author

I find out that to do it, I need to comment line:
CGContextClipToRect(context, _viewPortHandler.contentRect)

from BarLineChartViewBase class, public override func drawRect(rect: CGRect) method

@bizibizi
Copy link
Author

but I can not cancel it.

CGContextClipToRect:
"This function sets the specified graphics context’s clipping region to the area which intersects both the current clipping path and the specified rectangle."

@bizibizi
Copy link
Author

bizibizi commented Sep 20, 2016

Well, here is my solution.

 class HighlightedDotLineChartRenderer: LineChartRenderer {

internal var _indicesToHighlight = [ChartHighlight]()

override func drawExtras(context context: CGContext) {
    super.drawExtras(context: context)

    drawHighlightedAfterClipping(context: context, indices: _indicesToHighlight)
}

override func drawHighlighted(context context: CGContext, indices: [ChartHighlight]) {
    _indicesToHighlight = indices
}

func drawHighlightedAfterClipping(context context: CGContext, indices: [ChartHighlight]) {
  ...custom drawing 
 } 

@gklka
Copy link

gklka commented Aug 6, 2018

For later reference: chart.clipDataToContentEnabled = NO; solved me the same issue.

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

No branches or pull requests

5 participants