Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 核心绘图线未显示_Ios_Objective C_Core Plot - Fatal编程技术网

Ios 核心绘图线未显示

Ios 核心绘图线未显示,ios,objective-c,core-plot,Ios,Objective C,Core Plot,我创建了CorePlot框架的一个简单实现。图表显示得很好,但没有绘制线条。我已经尝试注销我的示例值,并且确实有数据。任何和所有关于为什么绘制数据行不显示的输入都将不胜感激 头文件: #import <UIKit/UIKit.h> #import "PresentedViewControllerDelegate.h" #import "CorePlot-CocoaTouch.h" #define NUM_SAMPLES 30 @interface DeviceDetailModa

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

头文件:

#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
#导入
#导入“PresentedViewController delegate.h”
#导入“CorePlot CoCoCoTouch.h”
#定义NUM_样本30
@接口设备详细模式:UIViewController{
CPTXYGraph*图;
NSMutableArray*样本;
双xxx[样本数];
双yyy1[NUM_SAMPLES];
}
@属性(弱、非原子)IBUITableView*tableView;
@属性(非原子,弱)id委托;
@结束
主文件

#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];
}
}
#导入
#导入“DeviceDetailModal.h”
#导入“DetailCell.h”
#导入“CorePlot CoCoCoTouch.h”
#定义起点0//从原点开始
#定义结束点15.0//TODO时间为15秒
#定义X_VAL@“X_VAL”
#定义Y_VAL@“Y_VAL”
@实现设备细节模型
-(无效)viewDidLoad{
UIBarButtonItem*closeButton=[[UIBarButtonItem alloc]initWithTitle:@“关闭”样式:UIBarButtonItemStylePlain目标:自我操作:@selector(closeView)];
self.navigationItem.leftBarButtonItem=closeButton;
[[UIBarButtonItem外观]setTintColor:[UIColor lightGrayColor]];
[[UINavigationBar外观]SetPartIntColor:[UIColor blackColor]];
self.tableView.layer.cornerRadius=10.0;
self.tableView.layer.borderWidth=0.7;
self.tableView.layer.borderColor=[UIColor whiteColor].CGColor;
[自生样本];
NSNumber*xAxisStart=[NSNumber numberWithDouble:起始点];
NSNumber*xAxisLength=[NSNumber numberWithDouble:结束点-开始点];
double maxY=[[samples valueForKeyPath:@“@max.Y_VAL”]double Value];
NSNumber*yAxisStart=[NSNumber numberWithDouble:-maxY];
NSNumber*yAxisLength=[NSNumber numberWithDouble:2*maxY];
CGRect hostingRect=CGRectMake(2033033547);
CPTGraphHostingView*hostingView=[[CPTGraphHostingView alloc]initWithFrame:hostingRect];
[self.view addSubview:hostingView];
graph=[[CPTXYGraph alloc]initWithFrame:hostingView.bounds];
hostingView.hostedGraph=图形;
CPTXYPlotSpace*plotSpace=(CPTXYPlotSpace*)graph.defaultPlotSpace;
plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:xAxisStart
长度:xAxisLength];
plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:yAxisStart
长度:yAxisLength];
CPTSatterPlot*数据源线性图=[[CPTSatterPlot alloc]init];
dataSourceLinePlot.delegate=self;
//线型
CPTMutableLineStyle*mainPlotLineStyle=[[dataSourceLinePlot dataLineStyle]可变表复制];
[mainPlotLineStyle设置线宽:2.0f];
[mainPlotLineStyle setLineColor:[CPTColor color with CGColor:[[UIColor whiteColor]CGColor]];
[dataSourceLinePlot setDataLineStyle:mainPlotLineStyle];
//轴样式
CPTXAxisSet*axisSet=(CPTXAxisSet*)[图形axisSet];
CPTXYAxis*xAxis=[axisSet xAxis];
CPTXYAxis*yAxis=[axisSet yAxis];
CPTMutableLineStyle*axisLineStyle=[CPTMutableLineStyle];
[axisLineStyle设置线宽:1];
[axisLineStyle setLineColor:[CPTColor colorWithCGColor:[[UIColor whiteColor]CGColor]];
[xAxis setAxisLineStyle:axisLineStyle];
[xAxis setMajorTickLineStyle:axisLineStyle];
[yAxis setAxisLineStyle:axisLineStyle];
[yAxis setMajorTickLineStyle:axisLineStyle];
[graph addPlot:dataSourceLinePlot];
NSLog(@“绘图:%@”,数据源线性绘图);
[图形重新加载数据];
}
-(无效)生成的数据样本{
双倍长度=(终点-起点);
双增量=长度/(样本数-1);
samples=[[NSMutableArray alloc]initWithCapacity:NUM_samples];
对于(int i=0;i
默认背景填充为白色,看起来您没有更改。绘图线是用白色绘制的,因此不会显示在白色背景上。尝试使用默认线条样式或以下选项:

mainPlotLineStyle.lineColor = [CPTColor blackColor];

发现问题了!未设置绘图的数据源,我必须执行以下操作:

dataSourceLinePlot.dataSource = self;

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

对不起,我的背景是黑色的。我确实将情节线的颜色设置为白色,但仍然无法让它显示出来。我还更改了视图的颜色,以查看该行是否以另一种颜色显示,但没有效果。请检查
maxY
计算并确保其正确。