在iOS中的CorePlot图上画一条虚线

时间:2014-06-25 09:20:26

标签: ios core-plot

如何使用核心绘图绘制图表上的虚线,该行用于轴的最大和最小范围。

在AndroidPlot中,ValueMarker用于在图形上绘制最大和最小水平线。

请帮我解决这个问题。

由于

1 个答案:

答案 0 :(得分:3)

这就是我用于这种情况的原因:

@property (nonatomic, retain) CPTScatterPlot *myLine;
@property (nonatomic, retain) CPTGraph *graph;

    -(void) configureHorizontalLine
    {
        // 1 - Create plot space
        CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) self.graph.defaultPlotSpace;

        // 2 - Create the plot
        self.myLine = [[CPTScatterPlot alloc] init];
        self.myLine.dataSource = self;
        self.myLine.identifier = @"myLine";

        CPTColor *myPlotColor = [CPTColor redColor];
        [self.graph addPlot:self.myLine toPlotSpace:plotSpace];

        // 3 - Create styles
        CPTMutableLineStyle *myPlotLineStyle = [self.myLine.dataLineStyle mutableCopy];

        myPlotLineStyle.dashPattern=[NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:3],[NSDecimalNumber numberWithInt:3],nil];  //dashed line

        myPlotLineStyle.lineWidth = 1;
        myPlotLineStyle.lineColor = myPlotColor;
        self.myLine.dataLineStyle = myPlotLineStyle;
    }

同样在CPTPlotDataSource方法中,您必须执行以下检查以识别线图:

if ([[plot identifier] isEqual:@"myLine"])