我是下面的代码生成散点图:

- (void)viewDidLoad
{
    [super viewDidLoad];
      [self generateDataSamples];

    CPTGraphHostingView *hostingview=[[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:hostingview];

    graph=[[CPTXYGraph alloc] initWithFrame:self.view.bounds];
    hostingview.hostedGraph =graph;

    CPTScatterPlot *datasourceLinePlot =[[CPTScatterPlot alloc] init];
    datasourceLinePlot.dataSource =self;

    [graph addPlot:datasourceLinePlot];

    [datasourceLinePlot release];
    [graph release];
    [hostingview release];

}


输出如下:



但是,我需要显示x和yaxis的主线和辅线...!

像这样的y-0.5,1.0,1.5 ....!和x-0.5,1.0,1.5 ...!

我想在图像下方输出:



有人帮我....!

谢谢...!

最佳答案

您只需要设置主要和次要的刻度信息(x轴下面显示的示例):

CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromString(@"5");
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.majorTickLength = 7.0f;

10-08 09:07