首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心情节线未出现

核心情节线未出现
EN

Stack Overflow用户
提问于 2015-10-26 23:24:26
回答 2查看 129关注 0票数 2

我已经创建了一个CorePlot框架的简单实现。图表显示得很好,但没有绘制线。我尝试过注销我的样本值,而且确实有数据。任何和所有的输入,为什么线的绘制数据没有显示,将不胜感激!

头文件:

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import "PresentedViewControllerDelegate.h"
#import "CorePlot-CocoaTouch.h"

#define NUM_SAMPLES 30

@interface DeviceDetailModal : UIViewController <PresentedViewControllerDelegate, UIWebViewDelegate, UITableViewDataSource, UITableViewDelegate, CPTPlotDataSource>{
CPTXYGraph *graph;
NSMutableArray *samples;

double xxx[NUM_SAMPLES];
double yyy1[NUM_SAMPLES];

}

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, weak) id <PresentedViewControllerDelegate> delegate;


@end

主文件

代码语言:javascript
复制
#import <Foundation/Foundation.h>
#import "DeviceDetailModal.h"
#import "DetailCell.h"
#import "CorePlot-CocoaTouch.h"

#define START_POINT 0 // Start at origin
#define END_POINT 15.0 // TODO time is 15 seconds

#define X_VAL @"X_VAL"
#define Y_VAL @"Y_VAL"

@implementation DeviceDetailModal


-(void)viewDidLoad{
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(closeView)];
self.navigationItem.leftBarButtonItem = closeButton;

[[UIBarButtonItem appearance] setTintColor:[UIColor lightGrayColor]];

[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];


self.tableView.layer.cornerRadius = 10.0;
self.tableView.layer.borderWidth = 0.7;
self.tableView.layer.borderColor = [UIColor whiteColor].CGColor;

[self generateDataSamples];

NSNumber *xAxisStart = [NSNumber numberWithDouble:START_POINT];
NSNumber *xAxisLength = [NSNumber numberWithDouble:END_POINT - START_POINT];

double maxY = [[samples valueForKeyPath:@"@max.Y_VAL"] doubleValue];
NSNumber *yAxisStart = [NSNumber numberWithDouble:-maxY];
NSNumber *yAxisLength = [NSNumber numberWithDouble:2 *maxY];

CGRect hostingRect = CGRectMake(20, 330, 335, 347);


CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:hostingRect];

[self.view addSubview:hostingView];

graph = [[CPTXYGraph alloc] initWithFrame:hostingView.bounds];

hostingView.hostedGraph = graph;

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:xAxisStart
                                                length:xAxisLength];

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:yAxisStart
                                                length:yAxisLength];

CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init];
dataSourceLinePlot.delegate = self;

// LINE STYLE
CPTMutableLineStyle *mainPlotLineStyle = [[dataSourceLinePlot dataLineStyle] mutableCopy];
[mainPlotLineStyle setLineWidth:2.0f];
[mainPlotLineStyle setLineColor:[CPTColor colorWithCGColor:[[UIColor whiteColor] CGColor]]];

[dataSourceLinePlot setDataLineStyle:mainPlotLineStyle];

// AXIS STYLE

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)[graph axisSet];

CPTXYAxis *xAxis = [axisSet xAxis];
CPTXYAxis *yAxis = [axisSet yAxis];
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
[axisLineStyle setLineWidth:1];
[axisLineStyle setLineColor:[CPTColor colorWithCGColor:[[UIColor whiteColor] CGColor]]];

[xAxis setAxisLineStyle:axisLineStyle];
[xAxis setMajorTickLineStyle:axisLineStyle];
[yAxis setAxisLineStyle:axisLineStyle];
[yAxis setMajorTickLineStyle:axisLineStyle];


[graph addPlot:dataSourceLinePlot];
NSLog(@"PLOT: %@",dataSourceLinePlot);
[graph reloadData];

}


-(void)generateDataSamples{
double length = (END_POINT - START_POINT);
double delta = length / (NUM_SAMPLES -1);

samples = [[NSMutableArray alloc] initWithCapacity:NUM_SAMPLES];

for (int i = 0; i < NUM_SAMPLES; i++) {
    double x = START_POINT + (delta * i);

    //X^2
    double y = x * x;

    NSDictionary *sample = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithDouble:x],X_VAL,
                            [NSNumber numberWithDouble:y],Y_VAL,
                            nil];
    NSLog(@"SAMPLE: %@", sample);
    [samples addObject:sample];
}

[graph reloadData];


}

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{
return NUM_SAMPLES;
}

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{
NSDictionary *sample = [samples objectAtIndex:index];

if (fieldEnum == CPTScatterPlotFieldX) {
    return [sample valueForKey:X_VAL];
}else{
    return [sample valueForKey:Y_VAL];
}
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-27 19:09:25

发现问题了!没有设置该地块的数据源,我不得不这样做:

代码语言:javascript
复制
dataSourceLinePlot.dataSource = self;

当我的numberOfRecordsPerPlot方法从未被调用时,我发现了这一点。

票数 1
EN

Stack Overflow用户

发布于 2015-10-27 00:15:17

默认的背景填充是白色的,它看起来不像是你改变了它。情节线是用白色绘制的,所以它不会出现在白色的背景上。尝试使用默认的行样式或如下:

代码语言:javascript
复制
mainPlotLineStyle.lineColor = [CPTColor blackColor];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33357328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档