我想让图表的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;

最佳答案

首先我用我的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: @"[email protected]"]];
    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];
...
}

关于iphone - 如何更改我的图表中使用的X轴ShinobiCharts,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13688920/

10-09 08:28