【问题标题】:How to change the XAxis used on my chart ShinobiCharts如何更改我的图表上使用的 X 轴 Shinobi Charts
【发布时间】:2012-12-03 17:52:07
【问题描述】:

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

【问题讨论】:

  • 有这方面的消息吗?我想达到同样的效果...
  • 你搞定了吗?甚至我也在寻找类似的东西

标签: iphone objective-c ios charts


【解决方案1】:

首先我用作我的 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];
...
}

【讨论】:

  • 嗯,我现在正在尝试或编码。我已经尝试使用 xValue 为我的 xAxis 设置标签,但是如果我这样做,图表将无法将所述月份识别为 xAxis 上应该放置 Column 的点
  • 看起来图表期待“1, 2, 3, 4... 12”,当我将 xValue 设置为 @"Jan", @"Feb".... @" Dec" 它无法将列放置在正确的位置..
  • 我做dp.xValue = [NSString stringWithFormat:@"%d/%d", seriesIndex,dataIndex ];,如果我不做任何其他事情,它会向我显示那个字符串。我将编辑上面的答案以显示我如何创建 x 轴
  • 你不必设置它的类别?
  • 我不使用分类。我还查看了 shinobi 图表附带的试用包中的演示,并且有一个名为 ColumnChart 的示例,如果您看那里,它们也不使用类别。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多