Search code examples
xcodeios-charts

How can I upside down and limitLine in charts in Xcode


I made a android app and I'm making iOS app now.

I need a graph that upside down and has limit line.

In Android, I used MPAndroidChart.

In Xcode, I used Charts because it is almost same likes MPAndroidChart.

I have found I can use isInverted instead of setInverted

and ChartLimitLine instead of LimitLine.

This is codes what I wrote.

mChart.isInverted(axis: <#T##YAxis.AxisDependency#>)
mChart.ChartLimitLine(limit: 0.2, label: "")

I have no any idea that What is YAxis.AxisDependency.

And there is an error in limit line

"alue of type 'ScatterChartView?' has no member 'ChartLimitLine'"

I an new in iOS, so I don't know how to solve it.


Solution

  • You can use the below code to add the limit line in XAxis & YAxis.

    XAxis:

    let xAxis = chartView.xAxis
    var limitLineX = ChartLimitLine()
    limitLineX = ChartLimitLine(limit:5, label: "Limit Line average")
    xAxis.addLimitLine(limitLineX)
    

    YAxis:

    let leftAxis = chartView.leftAxis
    var limitLine = ChartLimitLine()
    limitLine = ChartLimitLine(limit:50, label: "Limit line average")
    leftAxis.addLimitLine(limitLine)
    

    For Invert property, it's still not supported on Charts iOS library. Maybe they will add soon to the newer version.

    Hope this will helps!