2016-08-21 74 views
0

我有一個iPhone應用程序,在這個應用程序中,我必須計算x軸和y軸的值,並將xaxis數組和yaxis數組的間隔值作爲固定值。iOS中具有不同X,Y值的iOS圖表?

然後我需要在x值和Y 繪製3線圖與它們values.then我需要在該圖形本身與 不同(X,Y)繪製散點座標。

我使用的是iOS圖表library.But給予不同的x值時 圖的X軸值也在發生變化,我這樣

` chartview.descriptionText = @""; 
    chartview.noDataTextDescription = @"You need to provide data for the chart."; 

    chartview.drawGridBackgroundEnabled = NO; 
    chartview.drawBarShadowEnabled = NO; 
    chartview.highlightFullBarEnabled = NO; 
    chartview.rightAxis.enabled=NO; 


    chartview.drawOrder = @[@(CombinedChartDrawOrderLine), 
          @(CombinedChartDrawOrderScatter), 
          ]; 

    ChartLegend *l = chartview.legend; 
    l.enabled = false; 
    //chartview.xAxisRenderer 

    ChartYAxis *leftAxis = chartview.leftAxis; 
    leftAxis.axisLineWidth=2.0f; 

    leftAxis.axisLineColor =[UIColor whiteColor]; 
    leftAxis.drawGridLinesEnabled = YES; 
    leftAxis.gridColor=[UIColor whiteColor]; 
    leftAxis.gridLineDashLengths = @[@5.f, @5.f]; 
    NSLog(@"%@",yaxispoints); 
    NSLog(@"%f",[[yaxispoints firstObject] floatValue]); 
     NSLog(@"%f",[[yaxispoints lastObject] floatValue]); 
    leftAxis.axisMinimum = [[yaxispoints firstObject] floatValue]; // this replaces startAtZero = YES 
    leftAxis.axisMaximum = [[yaxispoints lastObject] floatValue]; 

    leftAxis.labelCount = [yaxispoints count]; 
    leftAxis.spaceTop = 40.0; 
    leftAxis.labelTextColor=[UIColor whiteColor]; 

    ChartXAxis *xAxis = chartview.xAxis; 
    [xAxis setDrawAxisLineEnabled:YES]; 
    xAxis.axisLineWidth=2.0f; 
    xAxis.granularityEnabled=YES; 

    xAxis.axisLineColor =[UIColor whiteColor]; 
    xAxis.labelPosition = XAxisLabelPositionBottom; 
    xAxis.axisMinimum = [[months firstObject] floatValue]; // this replaces startAtZero = YES 
    xAxis.axisMaximum = [[months lastObject] floatValue]; 
    xAxis.labelCount = [months count]; 

    xAxis.forceLabelsEnabled=YES; 
    xAxis.drawGridLinesEnabled = YES; 
    xAxis.gridColor=[UIColor whiteColor]; 

    xAxis.gridLineDashLengths = @[@5.f, @5.f]; 
    xAxis.valueFormatter = self; 
    xAxis.labelTextColor=[UIColor whiteColor]; 
    [self updateChartData]; 
    [chartview animateWithXAxisDuration:1.5 yAxisDuration:1.5];` 


    - (void)updateChartData 
{ 


    [self setChartData]; 

} 

- (void)setChartData 
{ 
    CombinedChartData *data = [[CombinedChartData alloc] init]; 
    data.lineData = [self generateLineData]; 

    data.scatterData = [self generateScatterData]; 
    chartview.xAxis.axisMaximum = data.xMax + 5.0; 

    chartview.data = data; 

} 

- (LineChartData *)generateLineData 
{ 
    LineChartData *d = [[LineChartData alloc] init]; 

    NSMutableArray *entries = [[NSMutableArray alloc] init]; 
    NSArray *scxaxis = @[@"55.987", @"75.976", @"85.976" 
          ]; 
    NSArray *scyaxis = @[@"85.987", @"25.976", @"95.976" 
          ]; 

    for (int index = 0; index < [scxaxis count]; index++) 
    { 
     [entries addObject:[[ChartDataEntry alloc] initWithX:[[scxaxis objectAtIndex:index] doubleValue] y:[[scyaxis objectAtIndex:index] doubleValue]]]; 
    } 

    LineChartDataSet *set = [[LineChartDataSet alloc] initWithValues:entries label:@"Line DataSet"]; 
    [set setColor:[UIColor greenColor]]; 
    set.lineWidth = 3.0; 
    // [set setCircleColor:[UIColor redColor]]; 
    //set.circleRadius = 0.0; 
    // set.circleHoleRadius = 0.0; 
    set .drawCirclesEnabled=NO; 
    set.fillColor = [UIColor clearColor]; 
    set.mode = LineChartModeLinear; 
    set.drawValuesEnabled = NO; 

    set.valueFont = [UIFont systemFontOfSize:14.f]; 
    set.valueTextColor = [UIColor whiteColor]; 

    set.axisDependency = AxisDependencyLeft; 

    [d addDataSet:set]; 

    return d; 
} 

我想就像試圖在 行這個,但是當給線形圖中的每個數據集賦予不同的x值時,x軸會根據它完全錯誤。我想從不同的數組中獲取x軸,並且線圖的x,y點來自不同的數組,任何人都可以幫助我實現這個目標?

回答

0

也許問題是

chartview.xAxis.axisMaximum = data.xMax + 5.0; 

因爲你正在使用CombinedChartData,如果你應該首先調用calcMinMax()

根據你的代碼,x軸應該在[0,90.976]。你的圖表顯示了什麼?