Ios 无法实现JBChartView
我开始变得勇敢起来,尝试在我的应用程序中填充JBChartView(特别是折线图)以进行统计跟踪。我以前从未使用过图形库,但我尽了最大努力研究它们,这一个看起来非常强大。问题是,我很难从测试数据中获得正确的绘图 当我按如下方式运行代码时,我会将Ios 无法实现JBChartView,ios,objective-c,jbchartview,Ios,Objective C,Jbchartview,我开始变得勇敢起来,尝试在我的应用程序中填充JBChartView(特别是折线图)以进行统计跟踪。我以前从未使用过图形库,但我尽了最大努力研究它们,这一个看起来非常强大。问题是,我很难从测试数据中获得正确的绘图 当我按如下方式运行代码时,我会将[\uu NSCFConstantString objectAtIndex:]无法识别的选择器发送到实例。有问题的一行位于垂直值ForHorizontalIndex,但我想不出另一种生成数据的方法。有没有人有这方面的经验,或者有人能帮我弄清楚为什么我在这里
[\uu NSCFConstantString objectAtIndex:]无法识别的选择器发送到实例
。有问题的一行位于垂直值ForHorizontalIndex,但我想不出另一种生成数据的方法。有没有人有这方面的经验,或者有人能帮我弄清楚为什么我在这里会遇到这么多麻烦
实现文件
#import "waterStatsViewController.h"
#import "JBLineChartView.h"
#import "JBChartView.h"
#import "JBBarChartView.h"
#import "JBChartHeaderView.h"
#import "JBLineChartFooterView.h"
typedef NS_ENUM(NSInteger, JBLineChartLine){
JBLineChartLineSolid,
JBLineChartLineDashed,
JBLineChartLineCount
};
@interface waterStatsViewController ()
- (void)initData;
@end
@implementation waterStatsViewController
- (id)init
{
self = [super init];
if (self)
{
[self initData];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self initData];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
[self initData];
}
return self;
}
- (void) initData
{
// DEFINE ARRAYS
testArray1 = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", nil];
testArray2 = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", nil];
// CREATE MUTABLE ARRAY FOR LINES IN CHART
NSMutableArray *mutableLineCharts = [NSMutableArray array];
// AS LONG AS LINEINDEX IS LESS THEN THE LINE COUNT, INCREASE THE LINE COUNT AND EXECUTE CODE
for (int lineIndex = 0; lineIndex<JBLineChartLineCount; lineIndex++)
{
// CREATE MUTABLE ARRAY FOR DATA IN CHART
NSMutableArray *mutableChartData = [NSMutableArray array];
// AS LONG AS INT I IS LESS THEN THE COUNT OF OBJECTS IN TEST ARRAY 2; INCREASE COUNT AND EXECUTE CODE
for (int i = 0; i < testArray2.count; i++)
{
// ADD OBJECTS FROM TEST ARRAY 2 TO CHART DATA
[mutableChartData addObjectsFromArray:testArray2];
}
// TAKE OBJECTS FROM MUTABLE CHART DATA AND ADD THEM TO OHHHHHH FOR EACH ITEM YOU ADD ANOTHER LINE
[mutableLineCharts addObjectsFromArray:mutableChartData];
}
}
- (void)viewDidLoad
{
self.title = @"Water Quality";
_chartView = [[JBLineChartView alloc] init];
_chartView.delegate = self;
_chartView.dataSource = self;
_chartView.state = 0;
_chartView.backgroundColor = [UIColor blackColor];
_chartView.showsLineSelection = YES;
_chartView.showsVerticalSelection = YES;
_headerView = [[JBChartHeaderView alloc] initWithFrame:CGRectMake(0, 64, 320, 30)];
_chartView.frame = CGRectMake(0, 94, 320, 300);
_footerView = [[JBLineChartFooterView alloc] initWithFrame:CGRectMake(0, 404, 320, 30)];
_headerView.titleLabel.text = @"Alkalinity";
_headerView.titleLabel.textColor = [UIColor whiteColor];
_footerView.leftLabel.text = [testArray1 firstObject];
_footerView.rightLabel.text = [testArray1 lastObject];
_footerView.leftLabel.textColor = [UIColor whiteColor];
_footerView.rightLabel.textColor = [UIColor whiteColor];
_footerView.backgroundColor = [UIColor blackColor];
_footerView.sectionCount = [testArray1 count];
// THIS IS THE VIEW WHEN THE USER INTERACTS WITH THE CHART
/*
_informationView = [[JBChartInformationView alloc] initWithFrame:CGRectMake(0, 0, 40, 300)];
[_informationView setBackgroundColor:[UIColor grayColor]];*/
[_chartView setMinimumValue:1.0f];
[_chartView setMaximumValue:20.0f];
[self.view addSubview:_footerView];
[self.view addSubview:_headerView];
[self.view addSubview:_chartView];
// [self.view addSubview:_informationView];
[_chartView reloadData];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
{
return YES;
}
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return 1;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
return 1;
}
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
return [[[testArray2 objectAtIndex:lineIndex] objectAtIndex:horizontalIndex] floatValue];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#导入“waterStatsViewController.h”
#导入“JBLineChartView.h”
#导入“JBChartView.h”
#导入“JBBarChartView.h”
#导入“JBChartHeaderView.h”
#导入“JBLineChartFooterView.h”
typedef NS_枚举(NSInteger、JBLineChartLine){
JBLineChartLineSolid,
JBLineChartLineDash,
JBLineChartLineCount
};
@接口waterStatsViewController()
-(无效)初始数据;
@结束
@waterStatsViewController的实现
-(id)init
{
self=[super init];
如果(自我)
{
[自初始化数据];
}
回归自我;
}
-(id)initWithCoder:(NSCoder*)aDecoder
{
self=[super initWithCoder:aDecoder];
如果(自我)
{
[自初始化数据];
}
回归自我;
}
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我)
{
[自初始化数据];
}
回归自我;
}
-(void)初始化数据
{
//定义数组
testArray1=[[NSArray alloc]initWithObjects:@“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,nil];
testArray2=[[NSArray alloc]initWithObjects:@“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,nil];
//为图表中的线条创建可变数组
NSMutableArray*mutableLineCharts=[NSMutableArray];
//只要LINEINDEX小于行数,就增加行数并执行代码
对于(int lineIndex=0;lineIndex一些问题:
- 不要将数值作为字符串存储在测试数组中
- 删除mutableLineCharts代码;这是演示中的遗留代码,不需要用于您的目的
- 我假设您需要两条线?一条虚线和一条实线?如果需要,请返回JBLineChartLineCount,而不是LineChartView中的NumberOfLines返回1
- 在verticalValueForHorizontalIndex中返回testArray1或testArray2的数值
初始化数据
- (void) initData
{
testArray1 = @[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)];
testArray2 = @[@(11), @(12), @(13), @(14), @(15), @(16), @(17), @(18), @(19), @(20)];
}
行计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据值
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
NSNumber *value = (NSNumber *)[self.testArray1 objectAtIndex:horizontalIndex];
return [value floatValue];
}
else
{
NSNumber *value = (NSNumber *)[self.testArray2 objectAtIndex:horizontalIndex];
return [value floatValue];
}
return 0;
}
希望这有帮助。一些问题:
- 不要将数值作为字符串存储在测试数组中
- 删除mutableLineCharts代码;这是演示中的遗留代码,不需要用于您的目的
- 我假设您需要两条线?一条虚线和一条实线?如果需要,请返回JBLineChartLineCount,而不是LineChartView中的NumberOfLines返回1
- 在verticalValueForHorizontalIndex中返回testArray1或testArray2的数值
初始化数据
- (void) initData
{
testArray1 = @[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)];
testArray2 = @[@(11), @(12), @(13), @(14), @(15), @(16), @(17), @(18), @(19), @(20)];
}
行计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据值
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
NSNumber *value = (NSNumber *)[self.testArray1 objectAtIndex:horizontalIndex];
return [value floatValue];
}
else
{
NSNumber *value = (NSNumber *)[self.testArray2 objectAtIndex:horizontalIndex];
return [value floatValue];
}
return 0;
}
希望这有帮助。一些问题:
- 不要将数值作为字符串存储在测试数组中
- 删除mutableLineCharts代码;这是演示中的遗留代码,不需要用于您的目的
- 我假设您需要两条线?一条虚线和一条实线?如果需要,请返回JBLineChartLineCount,而不是LineChartView中的NumberOfLines返回1
- 在verticalValueForHorizontalIndex中返回testArray1或testArray2的数值
初始化数据
- (void) initData
{
testArray1 = @[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)];
testArray2 = @[@(11), @(12), @(13), @(14), @(15), @(16), @(17), @(18), @(19), @(20)];
}
行计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据值
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
NSNumber *value = (NSNumber *)[self.testArray1 objectAtIndex:horizontalIndex];
return [value floatValue];
}
else
{
NSNumber *value = (NSNumber *)[self.testArray2 objectAtIndex:horizontalIndex];
return [value floatValue];
}
return 0;
}
希望这有帮助。一些问题:
- 不要将数值作为字符串存储在测试数组中
- 删除mutableLineCharts代码;这是演示中的遗留代码,不需要用于您的目的
- 我假设您需要两条线?一条虚线和一条实线?如果需要,请返回JBLineChartLineCount,而不是LineChartView中的NumberOfLines返回1
- 在verticalValueForHorizontalIndex中返回testArray1或testArray2的数值
初始化数据
- (void) initData
{
testArray1 = @[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)];
testArray2 = @[@(11), @(12), @(13), @(14), @(15), @(16), @(17), @(18), @(19), @(20)];
}
行计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据计数
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
数据值
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
NSNumber *value = (NSNumber *)[self.testArray1 objectAtIndex:horizontalIndex];
return [value floatValue];
}
else
{
NSNumber *value = (NSNumber *)[self.testArray2 objectAtIndex:horizontalIndex];
return [value floatValue];
}
return 0;
}
希望这能有所帮助。是的。这样做了;除了我的数组的原始布局被接受,但是你列出它的方式抛出了一个错误。这是巨大的。谢谢。是的。这样做了;除了我的数组的原始布局被接受,但是你列出它的方式抛出了一个错误。这是巨大的。谢谢。是的。这样做了;例外我的阵列的原始布局的pt被接受,但是你列出它的方式抛出了一个错误。这是巨大的。谢谢。是的。这样做了;除了我的阵列的原始布局被接受之外,但是你列出它的方式抛出了一个错误。这是巨大的。谢谢。