如有技术问题可扣扣交流:907392876
股票类K线图现在网上好多代码不全,本人最近仿写了一个项目,废话不多说直接上图上代码
1.简单图:
2.代码如下:
//画图
- (void)setupP{
NSString* path =[[NSBundlemainBundle]pathForResource:@"data.plist"ofType:nil];
NSArray* sourceArray = [[NSDictionarydictionaryWithContentsOfFile:path]objectForKey:@"data"];
NSMutableArray* array = [NSMutableArrayarray];
for(NSDictionary* dicinsourceArray) {
YKLineEntity* entity = [[YKLineEntityalloc]init];
entity.high= [dic[@"high_px"]doubleValue];
entity.open= [dic[@"open_px"]doubleValue];
entity.low= [dic[@"low_px"]doubleValue];
entity.close= [dic[@"close_px"]doubleValue];
entity.date= dic[@"date"];
entity.ma5= [dic[@"avg5"]doubleValue];
entity.ma10= [dic[@"avg10"]doubleValue];
entity.ma20= [dic[@"avg20"]doubleValue];
entity.volume= [dic[@"total_volume_trade"]doubleValue];
[arrayaddObject:entity];
//YTimeLineEntity * entity = [[YTimeLineEntity alloc]init];
}
[arrayaddObjectsFromArray:array];
YKLineDataSet* dataset = [[YKLineDataSetalloc]init];
dataset.data= array;
dataset.highlightLineColor= [UIColorcolorWithRed:60/255.0green:76/255.0blue:109/255.0alpha:1.0];
dataset.highlightLineWidth=0.7;
dataset.candleRiseColor= [UIColorcolorWithRed:233/255.0green:47/255.0blue:68/255.0alpha:1.0];
dataset.candleFallColor= [UIColorcolorWithRed:33/255.0green:179/255.0blue:77/255.0alpha:1.0];
dataset.avgLineWidth=1.f;
dataset.avgMA10Color= [UIColorcolorWithRed:252/255.0green:85/255.0blue:198/255.0alpha:1.0];
dataset.avgMA5Color= [UIColorcolorWithRed:67/255.0green:85/255.0blue:109/255.0alpha:1.0];
dataset.avgMA20Color= [UIColorcolorWithRed:216/255.0green:192/255.0blue:44/255.0alpha:1.0];
dataset.candleTopBottmLineWidth=1;
[self.klineViewsetupChartOffsetWithLeft:50top:10right:10bottom:10];
self.klineView.gridBackgroundColor= [UIColorwhiteColor];
self.klineView.borderColor= [UIColorcolorWithRed:203/255.0green:215/255.0blue:224/255.0alpha:1.0];
self.klineView.borderWidth=.5;
self.klineView.candleWidth=8;
self.klineView.candleMaxWidth=30;
self.klineView.candleMinWidth=1;
self.klineView.uperChartHeightScale=0.7;
self.klineView.xAxisHeitht=25;
self.klineView.delegate=self;
self.klineView.highlightLineShowEnabled=YES;
self.klineView.zoomEnabled=YES;
self.klineView.scrollEnabled=YES;
[self.klineViewsetupData:dataset];
}
网友评论