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

Line chart xAxis cut left or right in iphone 5 #2758

Closed
sergioliip opened this issue Aug 29, 2017 · 3 comments
Closed

Line chart xAxis cut left or right in iphone 5 #2758

sergioliip opened this issue Aug 29, 2017 · 3 comments

Comments

@sergioliip
Copy link

Hello, I have tried to find the solution to my problem, but I have not found anything related. I hope you can help me.

My problem is that, sometimes, the line graph is cut by the beginning or the end, and I do not understand why.

img_0010

I have tried to set the zoom, the maximum and minimum values, I have the granularity the number of fields, etc ...

This is my config:

`viewLineChart.dragEnabled = true
viewLineChart.dragDecelerationFrictionCoef = 0.95
viewLineChart.highlightPerDragEnabled = true
viewLineChart.legend.enabled = false
viewLineChart.rightAxis.enabled = false
viewLineChart.delegate = self
viewLineChart.drawGridBackgroundEnabled = false

    viewLineChart.pinchZoomEnabled = false
    viewLineChart.drawBordersEnabled = false
    viewLineChart.borderLineWidth = CGFloat(1)
    viewLineChart.borderColor = ApplicationConstants.getLiipDarkUIColorFromAlpha(customAlpha: 1)
    viewLineChart.drawBordersEnabled = false

viewLineChart.xAxis.valueFormatter = HourFormatter()
viewLineChart.xAxis.setLabelCount(3, force: true)

    viewLineChart.xAxis.labelCount = 3
    viewLineChart.xAxis.forceLabelsEnabled = true
    viewLineChart.xAxis.drawGridLinesEnabled = false
    viewLineChart.xAxis.drawLabelsEnabled = true
    viewLineChart.xAxis.drawAxisLineEnabled = true
    viewLineChart.xAxis.labelPosition = XAxis.LabelPosition.bottom
    viewLineChart.xAxis.labelTextColor = ApplicationConstants.getLiipDarkUIColorFromAlpha(customAlpha: 1)
    viewLineChart.xAxis.valueFormatter = HourFormatter()
    viewLineChart.xAxis.avoidFirstLastClippingEnabled = true
    viewLineChart.xAxis.granularityEnabled = false
    
    viewLineChart.leftAxis.granularity = Double(5)
    viewLineChart.leftAxis.axisMaximum = getLeftAxisMaximum()
    viewLineChart.leftAxis.axisMinimum = getLeftAxisMinimum()
    viewLineChart.leftAxis.drawZeroLineEnabled = false
    viewLineChart.leftAxis.drawAxisLineEnabled = true
    viewLineChart.leftAxis.drawGridLinesEnabled = false
    viewLineChart.leftAxis.drawLabelsEnabled = true
    viewLineChart.leftAxis.labelPosition = YAxis.LabelPosition.outsideChart
    viewLineChart.leftAxis.labelTextColor = ApplicationConstants.getLiipDarkUIColorFromAlpha(customAlpha: 1)
    
    
    markerView = MarkerView(frame: CGRect(x: -8, y: -8, width: 16, height: 16))
    markerView?.layer.cornerRadius = 8
    markerView?.backgroundColor = ApplicationConstants.getLiipUIColorFromAlpha(customAlpha: 1)
    markerView?.offset = CGPoint(x: -8, y: -8)

viewLineChart.xAxis.axisMaximum = with.getDataSetByIndex(0).xMax
viewLineChart.xAxis.axisMinimum = with.getDataSetByIndex(0).xMin

func formatDataSet(dataSet: LineChartDataSet) -> LineChartData{
dataSet.axisDependency = YAxis.AxisDependency.left

    var colors = getGravityColors(dataSet:dataSet)
    dataSet.circleColors = colors
    if colors.count > 1 {
        colors.remove(at: 0)
    }
    dataSet.colors = colors
    
    
    //Values
    dataSet.drawValuesEnabled = false
    //Circle
    dataSet.drawCirclesEnabled = true
    dataSet.drawCircleHoleEnabled = true
    dataSet.circleRadius = CGFloat(3)
    dataSet.circleHoleRadius = CGFloat(1.5)
    //HighLight
    dataSet.highlightEnabled = true
    dataSet.drawHorizontalHighlightIndicatorEnabled = false
    dataSet.drawVerticalHighlightIndicatorEnabled = false
    
    return LineChartData(dataSet: dataSet)
}`
@sergioliip sergioliip changed the title Line chart xAxis cut Line chart xAxis cut left or right Aug 29, 2017
@sergioliip sergioliip changed the title Line chart xAxis cut left or right Line chart xAxis cut left or right in iphone 5 Aug 29, 2017
@seenoevo
Copy link

what is with.getDataSetByIndex(0).xMax and with.getDataSetByIndex(0).xMin suppose to return?

@sergioliip
Copy link
Author

Hi seenoevo,
The xMin is 10:30 and The xMax is 11:30

@liuxuan30
Copy link
Member

liuxuan30 commented Sep 5, 2017

first

viewLineChart.xAxis.labelCount = 3
    viewLineChart.xAxis.forceLabelsEnabled = true

you should not use like this after viewLineChart.xAxis.setLabelCount(3, force: true). Just call open func setLabelCount(_ count: Int, force: Bool) instead.

This makes your x axis labels like (max - min) / labelCount directly, without more calculations. It starts from min, so you should check if min is within the boundary in XAxisRenderer. Later check if your formatted string are rendered in drawLabels(context: CGContext, pos: CGFloat, anchor: CGPoint)

Just add some break points to see if your first value is rendered. Ideally you should check if viewPortHandler.isInBoundsX(position.x) first. Sometimes it's just oob

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