代码之家  ›  专栏  ›  技术社区  ›  Vinodha Sundaramoorthy

iOS图表中的组合图表-不呈现折线图的负值

  •  0
  • Vinodha Sundaramoorthy  · 技术社区  · 8 年前

    我正在使用io图表( https://github.com/danielgindi/Charts/ ). 我必须在组合图中显示条形图和折线图。 x轴将反映从-12到12的值,y值范围在-3000到3000之间。虽然条形图对于负y轴和x轴是正确呈现的,但对于小于0的值,不会显示折线图。如以下链接所示,

    Negative values not displayed in line charts using ios-charts using Swift

    我已经设置了_chartView.xAxis。轴最小值=-12;//从-12开始,而不是0。

    请在当前图表下方找到, enter image description here

    图表视图的设置和折线图的数据集,

        - (LineChartData *)generateLineData
    

    { LineChartData*d=[[LineChartDataAlloc]init];

    NSMutableArray *entries = [[NSMutableArray alloc] init];
    
    [entries addObject:[[ChartDataEntry alloc] initWithX:0 y:-3000]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:0.5 y:-999]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:1 y:-1000]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:2 y:-1000]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:3.5 y:-1300]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:4 y:-900]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:5 y:-1200]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:6 y:-2500]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:8 y:-1300]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:9 y:1400]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:11 y:-900]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:12 y:-3000]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-1 y:-1000]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-2 y:-1300]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-4 y:-1100]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-5 y:-1500]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-6 y:-1500]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-8 y:-1100]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-9 y:-1000]];
    [entries addObject:[[ChartDataEntry alloc] initWithX:-11 y:-1500]];
    
    LineChartDataSet *set = [[LineChartDataSet alloc] initWithValues:entries label:@"Line DataSet"];
    [set setColor:[UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f]];
    set.lineWidth = 2.5;
    set.fillColor = [UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f];
    set.mode = LineChartModeHorizontalBezier;
    set.drawValuesEnabled = NO;
    set.drawCirclesEnabled = NO;
    set.axisDependency = AxisDependencyLeft;
    
    [d addDataSet:set];
    
    return d;
    

    }

    我不确定是否缺少图表视图的某些设置。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Vinodha Sundaramoorthy    8 年前

    修复了这一问题,方法是用x值从-12到12对折线图数据集重新排序,在我最初的问题中,数据集是混合的,并且对于折线图的顺序不正确。