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

Chart Clipping #1149

Closed
ziadtamim opened this issue Jun 16, 2016 · 9 comments
Closed

Chart Clipping #1149

ziadtamim opened this issue Jun 16, 2016 · 9 comments

Comments

@ziadtamim
Copy link

The chart is clipping from top:

screen shot 2016-06-16 at 2 21 19 pm

@liuxuan30
Copy link
Member

what did you do then? By default, it should not happen. We need more info. Take a look at ChartDemo, and seee if you are not following the correct workflow first

@ziadtamim
Copy link
Author

ziadtamim commented Jun 16, 2016

@liuxuan30 I guess that I am following the same workflow as on the ChartDemo

func configure() {
        self.xAxis.gridColor = UIColor.whiteColor().colorWithAlphaComponent(0.2)
        self.xAxis.drawAxisLineEnabled = false
        self.xAxis.drawLabelsEnabled = false
        self.xAxis.drawGridLinesEnabled = false

        self.leftAxis.drawZeroLineEnabled = true
        self.leftAxis.drawGridLinesEnabled = false
        self.leftAxis.zeroLineColor = UIColor.whiteColor().colorWithAlphaComponent(0.2)
        self.rightAxis.drawGridLinesEnabled = false

        self.leftAxis.axisMinValue = 0
        self.rightAxis.axisMinValue = 0

        self.legend.enabled = false
        self.doubleTapToZoomEnabled = false
}

func setChart(dataPoints: [NSTimeInterval], values: [[Double]]) {
        var dataSets = [LineChartDataSet]()
        for (index,value) in values.enumerate() {
            let lineChartDataSet = dataSetForValue(value, color: colors[index], alpha: CGFloat(1-(Float(index)/7.0)))
            dataSets.append(lineChartDataSet)
        }

        self.data = LineChartData(xVals: dataPoints, dataSets: dataSets)
        self.notifyDataSetChanged()
    }

func dataSetForValue(value: [Double], color: UIColor, alpha: CGFloat) -> LineChartDataSet {

        var entries = [ChartDataEntry]()
        for (index,currentValue) in value.enumerate() {
            let entry = ChartDataEntry(value: currentValue, xIndex: index)
            entries.append(entry)
        }
        return dataSetForEntries(entries, color: color, alpha: alpha)
}

func dataSetForEntries(entries: [ChartDataEntry]?, color: UIColor, alpha: CGFloat) -> LineChartDataSet {
        let dataSet = LineChartDataSet(yVals: entries, label: nil)
        dataSet.mode = .CubicBezier
        dataSet.drawValuesEnabled = false
        dataSet.drawCirclesEnabled = false
        dataSet.drawFilledEnabled = true

        dataSet.setColor(UIColor.clearColor())
        dataSet.fillColor = color
        dataSet.fillAlpha = alpha
        dataSet.highlightEnabled = false

        return dataSet
}

screen shot 2016-06-16 at 4 27 08 pm

Do you think that is related the high values?

@liuxuan30
Copy link
Member

where do you call configure()? One common mistake is if you first set chart data, then configure chart property, you have to call notifyDataSetChanged, so normally configure chart first, and set chart data, because it will call notifyDataSetChanged in the data setter.

However I am not sure if this is the case. You can try it out.

On the other hand, if you use ChartsDemo, and just set axisMinValue, will it cut the highest value? I am thinking if you touches axisMaxValue

@ziadtamim
Copy link
Author

@liuxuan30 I am calling configure() first. I still experience the same issue on my end.

@liuxuan30
Copy link
Member

Also, have you set the axis dependency? I see you are having two axises, and different range.

@ziadtamim
Copy link
Author

Yes, I am using it.

@ziadtamim
Copy link
Author

@liuxuan30 Do you have an idea from where this can come from?

@liuxuan30
Copy link
Member

liuxuan30 commented Jun 21, 2016

not yet, just com back from WWDC, so lots of things left behind..
BTW, I have been using line chart for a long time and never see this happen.
It could be range calculation is wrong, but I am not sure.

Normally, the y axis range will calculate a range that can contains your min and max data value, so it will not be clipped.

Also, you have to specify which axis you are using by axisDependency. I didn't see you set any axis dependency in your code! How did you do it?

Would you be able to debug the y axis range? It's in computeAxisValues, you can add a breakpoint to see if the range covers your data range, if not, that's the problem.

That's much easier to debug on your side. But if you are not sure, try ChartsDemo first.

@danielgindi
Copy link
Collaborator

I think that it is related to this issue #407. Please use horizontal-bezier instead of the normal cubic bezier, it will better suit your needs if you don't understand beziers :-)

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

3 participants