核心图中的多函数曲线

multiple function curves in core-plot

我目前正在尝试添加不止一条数学函数曲线。以下是我的部分代码。

// draw all expression curves (in viewDidLoad)
for ( j=0; j<self.expNum; j++ ) {

        [self getDataForPlot1:self.plotIndex]; // get DataForPlot of one selected expression
        [self addCurve:self.plotIndex];
}

我试图在绘制轴后添加所有曲线,但它只绘制了最后一条输入曲线。如何为每个函数分隔 dataForPlot

-(void)getDataForPlot1:(int)index
{
    int i;
    NSString *exp;

    int bound, plotNum;
    double interval;

    bound = 3 * scaleX;
    plotNum = 3 * 60;
    interval = (double)bound / plotNum;

    NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:2*plotNum];

    for ( i = -plotNum; i < plotNum; i++ ) {
        id x;

        x = [NSNumber numberWithFloat: i * interval];

        // get one expression
            .......

        id y = [exp numberByEvaluatingString]; // get y values from the expression
        [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
    }
    dataForPlot = contentArray;

}


-(void)addCurve:(int)index {

    CPTScatterPlot *boundLinePlot  = [[CPTScatterPlot alloc] init];
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.miterLimit        = 1.0f;
    lineStyle.lineWidth         = 3.0f;
    lineStyle.lineColor         = [CPTColor blueColor];
    boundLinePlot.dataLineStyle = lineStyle;
    boundLinePlot.identifier    = @"Blue Plot";
    boundLinePlot.dataSource    = self;

    [graph addPlot:boundLinePlot toPlotSpace:plotSpace];

    boundLinePlot.interpolation = CPTScatterPlotInterpolationCurved;
}

(根据以上评论回答问题)

分别保存每个数据集的副本。看起来每次调用 -getDataForPlot1:.

时计算出的绘图数据都会被覆盖

此外,为每个图设置一个唯一的 identifier,这样数据源就可以知道哪个图正在请求数据。