OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 Core Plot CPT ScatterPlot 中绘制不同的线条颜色 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:28
标题: ios - 如何在 Core Plot CPT ScatterPlot 中绘制不同的线条颜色

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 plotRangeWithLocation0 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;



Best Answer-推荐答案


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

关于ios - 如何在 Core Plot CPT ScatterPlot 中绘制不同的线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36171384/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4