gpt4 book ai didi

ios:Coreplot,无法在一张图表上绘制多个图

转载 作者:行者123 更新时间:2023-11-29 13:13:17 26 4
gpt4 key购买 nike

我整天都在研究这个,但仍然毫 headless 绪。我制作了两个数据集并将它们放入字典中,然后将其用作绘图的数据源。一切都应该工作,但它仍然只显示一个图表。

有趣的是,如果我更改 PLOT_IDENTIFIER 的顺序,显示的是该图的数据,而不是另一个。

这里是我制作数据和字典的地方:

- (void)viewDidLoad
{
[super viewDidLoad];

//This is just so the graph has data without the buttons before them.
data1 = [NSMutableArray array];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-10.5, 8.5)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-10, 29.2)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-9.5, 39.6)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-9, 48.6)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-8.5, 47.8)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-8, 51.5)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-7.5, 59.5)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-7, 59.4)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-6.5, 83.4)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-6, 78.4)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-5.5, 120.7)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-5, 109.1)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-4.5, 112.4)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-4, 115.3)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-3.5, 111.8)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-3, 108.8)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-2.5, 131.5)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-2, 152.2)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-1.5, 150.2)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-1, 172)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(-0.5, 186.4)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(0, 175.1)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(0.5, 164.3)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(1, 165)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(1.5, 159.2)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(2, 146.8)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(2.5, 147.4)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(3, 143.2)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(3.5, 153.8)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(4, 156.7)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(4.5, 159.8)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(5, 144.5)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(5.5, 136.1)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(6, 107.3)]];
[data1 addObject:[NSValue valueWithCGPoint:CGPointMake(6.5, 78.7)]];

//same here
data2 = [NSMutableArray array];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-6, 1.5)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-5.5, 15.6)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-5, 19.5)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-4.5, 20.2)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-4, 16.5)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-3.5, 15.1)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-3, 16.6)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-2.5, 19.9)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-2, 19.9)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-1.5, 20)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-1, 23.6)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(-0.5, 28.7)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(0, 30.6)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(0.5, 28)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(1, 27.2)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(1.5, 26.7)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(2, 24.5)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(2.5, 23.5)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(3, 21.7)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(3.5, 25.5)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(4, 23.2)]];
[data2 addObject:[NSValue valueWithCGPoint:CGPointMake(4.5, 21.2)]];

NSDictionary *firstLineDic = [NSDictionary dictionaryWithObjectsAndKeys:@"firstLine", @"PLOT_IDENTIFIER", data1, @"PLOT_DATA", nil];
NSDictionary *secondLineDic = [NSDictionary dictionaryWithObjectsAndKeys:@"secondLine", @"PLOT_IDENTIFIER", data2, @"PLOT_DATA", nil];
NSMutableArray *dictionarydata = [NSMutableArray arrayWithObjects:firstLineDic, secondLineDic, nil];
self.scatterPlot = [[psuScatterSimpleScatterPlot alloc] initWithHostingView:_graphHostingView andData:dictionarydata];
[self.scatterPlot initialisePlot];

这是我制作图表的地方:

NSArray* data = [[NSArray alloc] initWithArray:_graphData];


for (NSDictionary *dic in data) {
CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease];
plot.dataSource = self;
plot.identifier = [dic objectForKey:@"PLOT_IDENTIFIER"];
plot.plotSymbol = plotSymbol;
plot.dataLineStyle = lineStyle;

[self.graph addPlot:plot];

}



}

// Delegate method that returns the number of points on the plot




-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
NSArray* data = [[NSArray alloc] initWithArray:_graphData];

for (NSDictionary *dic in data) {
NSString *identity = [dic objectForKey:@"PLOT_IDENTIFIER"];

if([plot.identifier isEqual:identity]){
NSArray *arr = [dic objectForKey:@"PLOT_DATA"];
return [arr count];
}
}
return 0;
}


// Delegate method that returns a single X or Y value for a given plot.
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if ([plot.identifier isEqual:@"firstLine"] || [plot.identifier isEqual:@"secondLine"])
{
NSDictionary*jay = [_graphData objectAtIndex:0];

NSArray *jay2 = [jay objectForKey:@"PLOT_DATA"];
NSValue *value = [jay2 objectAtIndex:index];
CGPoint point = [value CGPointValue];

// FieldEnum determines if we return an X or Y value.
if ( fieldEnum == CPTScatterPlotFieldX )
{
return [NSNumber numberWithFloat:point.x];
}
else // Y-Axis
{
return [NSNumber numberWithFloat:point.y];
}
}

return [NSNumber numberWithFloat:0];

}

最佳答案

在数据源方法中,您指定了“_graphData”数组的第一个对象。这是 pblm。更改代码如下:

 -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:  (NSUInteger)index
{

if ([plot.identifier isEqual:@"firstLine"])
{
NSDictionary *firstDataSet = [_graphData objectAtIndex:0];
//Code for processing the points here

}
else if([plot.identifier isEqual:@"secondLine"])
{
NSDictionary *secondDataSet = [_graphData objectAtIndex:1];
//Code for processing the points here
}
}

希望对你有帮助

关于ios:Coreplot,无法在一张图表上绘制多个图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16600682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com