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