核心情节osx没有密谋

时间:2012-12-02 20:03:30

标签: graph plot core-plot

我正在为一个学校项目编写一个简单的可可应用程序,它需要从串口获取一些数据并将其绘制成一个简单的图形。我已选择Core-Plot作为生成和显示数据槽的框架,但我无法使其工作。

我设法绘制轴并且程序运行正常,但没有数据线出现。我使用以下代码:

#import "Controller.h"
#import <CorePlot/CorePlot.h>

@implementation Controller

-(void)dealloc
{
    [plotData release];
    [graph release];
    [super dealloc];
}

-(void)awakeFromNib
{
    [super awakeFromNib];

// Create graph from theme
graph = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[graph applyTheme:theme];
hostView.hostedGraph = graph;

// Setup scatter plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-1) length:CPTDecimalFromDouble(10)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-1) length:CPTDecimalFromDouble(10.0)];


// Axes
// Label x axis with a fixed interval policy
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x          = axisSet.xAxis;
x.majorIntervalLength         = CPTDecimalFromString(@"1");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0.0");
x.minorTicksPerInterval       = 2;

x.title         = @"Tijd (s)";
x.titleOffset   = 30.0;
x.titleLocation = CPTDecimalFromString(@"8.5");

// Label y with an automatic label policy.
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy              = CPTAxisLabelingPolicyAutomatic;
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0.0");
y.minorTicksPerInterval       = 2;
y.preferredNumberOfMajorTicks = 8;
y.labelOffset                 = 10.0;

y.title         = @"Kracht (N)";
y.titleOffset   = 30.0;
y.titleLocation = CPTDecimalFromString(@"8");

// Create a plot that uses the data source method
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = @"Date Plot";

CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth              = 3.f;
lineStyle.lineColor              = [CPTColor greenColor];
dataSourceLinePlot.dataLineStyle = lineStyle;

dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];

// Add some data
NSMutableArray *contentArray = [NSMutableArray array];
for ( NSUInteger i = 0; i < 10; i++ ) {
    id x = [NSDecimalNumber numberWithDouble:i];
    id y = [NSDecimalNumber numberWithDouble:1.2];
    [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
    NSLog(@"waarde %@", contentArray);
}
NSLog(@"plotting");
plotData = [contentArray retain];
}


-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return plotData.count;
}


@end

代码基于其中一个示例。

NSLog(@“waarde%@”,contentArray);返回一个外观漂亮的数组,包含正确的数据点。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

尝试

hostView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
[self.view addSubview:hostView];

是否由于您没有将其添加为视图而未出现?