如何在Core Plot CPTScatterPlot中绘制不同的线条颜色

时间:2016-03-23 06:41:45

标签: ios objective-c core-plot

enter image description here

目前,我可以使用CPTScatterPlot绘制这样的趋势图 30个点,红线相互连接。

但我想在每个点之间使用不同的线条颜色。

这是我的代码我试试

    CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.frame];
    self.hostedGraph = graph;

    CPTScatterPlot *scatterPlot = [[CPTScatterPlot alloc] initWithFrame:graph.bounds];
    scatterPlot.dataSource = self;
    [graph addPlot:scatterPlot];

    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineWidth = 1.0f;
    lineStyle.lineColor = [CPTColor redColor];
    scatterPlot.dataLineStyle = lineStyle;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) scatterPlot.plotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:@0 length:@(self.dataModel.data.count -1)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:d length:@([c integerValue] - [d integerValue])];

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
    CPTXYAxis *x = axisSet.xAxis;
    CPTXYAxis *y = axisSet.yAxis;
    x.orthogonalPosition = z;
    x.labelingPolicy = CPTAxisLabelingPolicyNone;
    y.orthogonalPosition = @0;
    y.labelingPolicy = CPTAxisLabelingPolicyNone;

    CPTMutableLineStyle *symbolLineStyle = [CPTMutableLineStyle lineStyle];
    symbolLineStyle.lineColor = [CPTColor blackColor];
    symbolLineStyle.lineWidth = 1.0;

    CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    plotSymbol.fill = [CPTFill fillWithColor:[CPTColor redColor]];
    plotSymbol.lineStyle = symbolLineStyle;
    plotSymbol.size = CGSizeMake(5.0, 5.0);
    scatterPlot.plotSymbol = plotSymbol;

1 个答案:

答案 0 :(得分:1)

您必须为此使用多个散点图。每种颜色使用一种。