Search code examples
mpandroidchartios-charts

How to draw additional absciss on grid?


I'm using MPAndroidCharts and ios-charts for my apps. I need additional absciss at custom y!=0 to be drawed. And it would be great if points above that level will painted to custom color.

How to realize that?


Solution

  • You can use limit line as additional line, smth like this:

    ChartLimitLine *ll1 = [[ChartLimitLine alloc] initWithLimit:YOUR_NUMBER label:@""];
    ll1.lineColor = [UIColor greenColor];
    ll1.lineWidth = 1.0;
    

    To change circle colors, you need to modify private func drawCircles(context context: CGContext) method in LineChartRenderer.

    There's a for-loop with line:

    CGContextSetFillColorWithColor(context, dataSet.getCircleColor(j)!.CGColor)
    

    You can change it to smth like:

    if e.value > YOUR_VALUE {
        CGContextSetFillColorWithColor(context, UIColor.greenColor().CGColor)
    }
    else {
        CGContextSetFillColorWithColor(context, dataSet.getCircleColor(j)!.CGColor)
    }
    

    And will be smth like this: