• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 核心情节线未显示

[复制链接]
菜鸟教程小白 发表于 2022-12-13 11:37:24 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

头文件:

#import <UIKit/UIKit.h>
#import "resentedViewControllerDelegate.h"
#import "CorePlot-CocoaTouch.h"

#define NUM_SAMPLES 30

@interface DeviceDetailModal : UIViewController <resentedViewControllerDelegate, 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 <resentedViewControllerDelegate> delegate;


@end

主文件

#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 actionselector(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(@"LOT: %@",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)numberOfRecordsForPlotCPTPlot *)plot{
return NUM_SAMPLES;
}

-(NSNumber *)numberForPlotCPTPlot *)plot fieldNSUInteger)fieldEnum recordIndexNSUInteger)index{
NSDictionary *sample = [samples objectAtIndex:index];

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



Best Answer-推荐答案


发现问题了!未设置绘图的数据源,我必须这样做:

dataSourceLinePlot.dataSource = self;

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

关于ios - 核心情节线未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33357328/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap