4

enter image description here

enter image description here

These two radar charts have the same data points for the orange bit, but different for the gray. However, as you can see it is autoscaling, and the orange bit ends up bigger on the second chart, even though they are the same exact data points. Is there a way to turn autoscaling off? I would like 100% to go right to the edge of the chart also.

-(void)setupRadarChart
{
    self.radarChart.descriptionText = @"";
    self.radarChart.webLineWidth = .75;
    self.radarChart.innerWebLineWidth = 0.375;
    self.radarChart.webAlpha = 1.0;
    self.radarChart.userInteractionEnabled = NO;
    self.radarChart.xAxis.enabled = YES;
    ChartYAxis *yAxis = self.radarChart.yAxis;
    yAxis.enabled = NO;
    ChartLegend *l = self.radarChart.legend;
    l.position = ChartLegendPositionBelowChartLeft;
    l.font = [UIFont systemFontOfSize:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 12 : (headerWidth/40)];
    [self setRadarData];
}

- (void)setRadarData
{
    NSMutableArray *parties = [[NSMutableArray alloc] init];
    for (PillarModel *m in [DataManager sharedData].pillars)
    {
        [parties addObject:m.abbreviation];
    }
    NSMutableArray *yVals2 = [[NSMutableArray alloc] init];
    NSMutableArray *benchMark = [[NSMutableArray alloc] init];
    BOOL shouldAdd = YES;

    for (PillarModel *pillar in [DataManager sharedData].pillars)
    {    int totalPillarScore = (int)[[DataManager sharedData] getTotalScorePossible:[[DataManager sharedData] getIndividualQuestionResultsForPillar:pillar.pillarId]];
        if ((isCompany ? [[DataManager sharedData] getCompanyScoresForCategory:pillar] : [[DataManager sharedData] getIndividualScoreForCategory:pillar.pillarId]) != 0)
        {
            shouldAdd = NO;
        }
        if (pillar.pillarId == numberOfPillars -1 && shouldAdd) {
            [yVals2 addObject:[[ChartDataEntry alloc] initWithValue:0.01 xIndex:pillar.pillarId]];

        }
        else{
            double val = (isCompany ? (double)[[DataManager sharedData] getCompanyScoresForCategory:pillar]/totalPillarScore                                                                                : (double)[[DataManager sharedData] getIndividualScoreForCategory:pillar.pillarId] / totalPillarScore);
            [yVals2 addObject:[[ChartDataEntry alloc] initWithValue:val xIndex:pillar.pillarId]];
        }
        float pillarBenchMark = [[[[[DataManager sharedData].benchmarkJSONDict objectForKey:hightlightedView.lowercaseString] objectForKey:pillar.title] objectForKey:@"pillar"] intValue];
        float ifNoBenchMarkThanCompanyScore = (pillarBenchMark ? pillarBenchMark : (isCompany ? [[DataManager sharedData] getIndividualScoreForCategory:pillar.pillarId]: [[DataManager sharedData] getCompanyScoresForCategory:pillar]));
        [benchMark addObject:[[ChartDataEntry alloc] initWithValue:ifNoBenchMarkThanCompanyScore/totalPillarScore xIndex:pillar.pillarId]];
    }

    NSMutableArray *xVals = [[NSMutableArray alloc] init];

    for (int i = 0; i < numberOfPillars; i++)
    {
        [xVals addObject:parties[i % parties.count]];
    }

    NSString *label = (isCompany ? @"Company score" : @"Your score");
    RadarChartDataSet *set2 = [[RadarChartDataSet alloc] initWithYVals:yVals2 label:label];
    [set2 setColor:[DataManager sharedData].mainColor];
    set2.drawFilledEnabled = YES;
    set2.fillAlpha = 1.0f;
    set2.lineWidth = 2.0;

    RadarChartDataSet *benchMarkSet = [[RadarChartDataSet alloc] initWithYVals:benchMark label:@"Benchmark"];
    [benchMarkSet setColor:[UIColor colorWithRed:125/255.0f green:125/255.0f blue:125/255.0f alpha:0.6f]];
    benchMarkSet.drawFilledEnabled = YES;
    benchMarkSet.fillAlpha = 0.0f;
    benchMarkSet.lineWidth = 2.0;
    benchMarkSet.highlightLineDashLengths = @[[NSNumber numberWithInt:2]];
    benchMarkSet.highlightLineDashPhase = 2;

    RadarChartData *data = [[RadarChartData alloc] initWithXVals:xVals dataSets:@[set2, benchMarkSet]];
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:8.f]];
    [data setDrawValues:NO];

    self.radarChart.data = data;
}
HannahCarney
  • 3,441
  • 2
  • 26
  • 32

2 Answers2

1

The answer that was posted by 孙博弘 wasn't correct, but it led me to realise how easy this was to solve. This solves both the autoscaling problem and also now reaches the edge.

self.radarChart.yAxis.customAxisMin = 0;
self.radarChart.yAxis.customAxisMax = 1;
HannahCarney
  • 3,441
  • 2
  • 26
  • 32
0

i'm afraid that you shouln't use customAxisMax directly as it use a Internal Access Levels.https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html

/// Flag indicating that the axis-max value has been customized
internal var _customAxisMax: Bool = false

Instead, you can use axisMaxValue to control it.

/// The maximum value for this axis.
/// If set, this value will not be calculated automatically depending on the provided data.
/// Use `resetCustomAxisMin()` to undo this.
public var axisMaxValue: Double
{
    get
    {
        return _axisMaximum
    }
    set
    {
        _customAxisMax = true
        _axisMaximum = newValue
    }
}

//2016-06-12 update

public var factor: CGFloat
{
    let content = _viewPortHandler.contentRect
    return min(content.width / 2.0, content.height / 2.0)
            / CGFloat(_yAxis.axisRange)
}

RadarChartView will calculator a factor to transform values into pixels.

Maybe,you can use axisMinValue and axisMaxValue to control autoscale.

酷酷的哀殿
  • 1,021
  • 6
  • 18