3

我想让我的图表的 xAxis 看起来像这样:

一月,二月,三月,四月,.....十一月,十二月

现在它遵循默认设置,根据数据点的数量对 xAxis 进行编号。

我怎样才能实现对这个轴的这种改变?

我尝试使用 Category Axis 并将包含这些字符串(“Jan”、“Feb”...)的 NSMutableArray 设置为类别,并且 numberRange 从 1 到 12,但它不起作用。

chart = [[ShinobiChart alloc] initWithFrame:chartEmbaixo.frame withPrimaryXAxisType:SChartAxisTypeCategory withPrimaryYAxisType:SChartAxisTypeNumber];

NSMutableArray * monthNames = [[NSMutableArray alloc] initWithObjects:@"Jan", @"Fev", @"Mar", @"Abr", @"Mai", @"Jun", @"Jul", @"Ago", @"Set", @"Out", @"Nov", @"Dez", nil];

SChartNumberRange * numberRange = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithInt:1]andMaximum:[NSNumber numberWithInt:12]];
SChartCategoryAxis *xAxis = [[SChartCategoryAxis alloc] initWithRange:numberRange];
xAxis.categories = monthNames;

chart.xAxis = xAxis;
4

1 回答 1

4

首先我用作我的 x 轴

编辑我如何制作我的 x 轴:

SChartNumberRange *r1 = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithInt:0] andMaximum:[NSNumber numberWithInt:2]];
SChartCategoryAxis *xAxis = [[SChartCategoryAxis alloc] initWithRange:r1];
xAxis.title = @"";
//xAxis.enableGesturePanning = YES;
xAxis.enableGesturePanning = YES;
xAxis.style.gridStripeStyle.showGridStripes = NO;
xAxis.style.majorGridLineStyle.showMajorGridLines = NO;

当你制作数据点时,它应该使用 xValue 作为 x 轴点。像这样:

dp.yValue = 1000;
dp.xValue = @"Jan";

xValue 应设置为该特定数据点的 x 点。这应该可行,但如果它不可行,或者你想做更复杂的事情,你可以从 SChartDelegate协议扩展这个方法:

-(void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis

在这种方法中,您拥有的tickMark.tickLabel是可以进行编辑的给定点的轴标签。不要忘记验证您在哪个轴上。

希望这可以帮助。如果不是明天,我可以从我的项目中向您发布一些代码(目前我无法从我所在的位置访问它)

编辑:目前我有这个代码:

- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis {
    if (chart.yAxis == axis ) return;
    for (UIView *i in tickMark.tickMarkView.subviews)
        [i removeFromSuperview];

    tickMark.tickMarkView.frame = CGRectMake(0, 0, 170, 75);
    //center the marker at the right place because the size was changed
    tickMark.tickMarkX = tickMark.tickMarkX - (tickMark.tickMarkView.frame.size.width/2) ;
    tickMark.tickMarkY = 10;

    //img
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"graph_bar_tag_2@2x.png"]];
    img.frame = CGRectMake( 0, 0, tickMark.tickMarkView.frame.size.width, tickMark.tickMarkView.frame.size.height);
    [tickMark.tickMarkView addSubview:img];

    //label with the markView's size with 7px padding on the left and on the right
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake( 7, 5, tickMark.tickMarkView.frame.size.width-14, 15)];
    label.backgroundColor = [UIColor clearColor];
    //tikMark.tickLabel has an pair of indexes so that i can easily find the data for this particular data point and series.
    label.text = [_dataSource getNameFor: tickMark.tickLabel.text];
    label.textAlignment = UITextAlignmentCenter;
    //color_other_light is a UIColor var
    [label setTextColor: color_other_light];

    [tickMark.tickMarkView addSubview:label];
...
}
于 2012-12-03T21:05:22.657 回答