如何在 Coreplot iOS 中的 x 轴/y 轴中获取动态数据:目前在这里使用演示代码:在每一列下方,我需要在 x 轴上显示年份,它本身是动态的,y 轴收入金额。我如何动态地做那个?
//
// CPDStockPriceStore.m
// CorePlotDemo
//
// NB: Price data obtained from Yahoo! Finance:
// http://finance.yahoo.com/q/hp?s=AAPL
// http://finance.yahoo.com/q/hp?s=GOOG
// http://finance.yahoo.com/q/hp?s=MSFT
//
// Created by Steve Baranski on 5/4/12.
// Copyright (c) 2012 komorka technology, llc. All rights reserved.
//
#import "CPDStockPriceStore.h"
@interface CPDStockPriceStore ()
@end
@implementation CPDStockPriceStore
#pragma mark - Class methods
+ (CPDStockPriceStore *)sharedInstance
{
static CPDStockPriceStore *sharedInstance;
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
#pragma mark - API methods
- (NSArray *)tickerSymbols
{
static NSArray *symbols = nil;
if (!symbols)
{
symbols = [NSArray arrayWithObjects:
@"AAPL",
@"GOOG",
@"MSFT",
nil];
}
return symbols;
}
- (NSArray *)dailyPortfolioPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:582.13],
[NSDecimalNumber numberWithFloat:604.43],
[NSDecimalNumber numberWithFloat:32.01],
nil];
}
return prices;
}
- (NSArray *)datesInWeek
{
static NSArray *dates = nil;
if (!dates)
{
dates = [NSArray arrayWithObjects:
@"4/23",
@"4/24",
@"4/25",
@"4/26",
@"4/27",
nil];
}
return dates;
}
- (NSArray *)weeklyPrices:(NSString *)tickerSymbol
{
if ([CPDTickerSymbolAAPL isEqualToString:[tickerSymbol uppercaseString]] == YES)
{
return [self weeklyAaplPrices];
}
else if ([CPDTickerSymbolGOOG isEqualToString:[tickerSymbol uppercaseString]] == YES)
{
return [self weeklyGoogPrices];
}
else if ([CPDTickerSymbolMSFT isEqualToString:[tickerSymbol uppercaseString]] == YES)
{
return [self weeklyMsftPrices];
}
return [NSArray array];
}
- (NSArray *)datesInMonth
{
static NSArray *dates = nil;
if (!dates)
{
dates = [NSArray arrayWithObjects:
@"2",
@"3",
@"4",
@"5",
@"9",
@"10",
@"11",
@"12",
@"13",
@"16",
@"17",
@"18",
@"19",
@"20",
@"23",
@"24",
@"25",
@"26",
@"27",
@"30",
nil];
}
return dates;
}
- (NSArray *)monthlyPrices:(NSString *)tickerSymbol
{
if ([CPDTickerSymbolAAPL isEqualToString:[tickerSymbol uppercaseString]] == YES)
{
return [self monthlyAaplPrices];
}
else if ([CPDTickerSymbolGOOG isEqualToString:[tickerSymbol uppercaseString]] == YES)
{
return [self monthlyGoogPrices];
}
else if ([CPDTickerSymbolMSFT isEqualToString:[tickerSymbol uppercaseString]] == YES)
{
return [self monthlyMsftPrices];
}
return [NSArray array];
}
#pragma mark - Private behavior
- (NSArray *)weeklyAaplPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:571.70],
[NSDecimalNumber numberWithFloat:560.28],
[NSDecimalNumber numberWithFloat:610.00],
[NSDecimalNumber numberWithFloat:607.70],
[NSDecimalNumber numberWithFloat:603.00],
nil];
}
return prices;
}
- (NSArray *)weeklyGoogPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:597.60],
[NSDecimalNumber numberWithFloat:601.27],
[NSDecimalNumber numberWithFloat:609.72],
[NSDecimalNumber numberWithFloat:615.47],
[NSDecimalNumber numberWithFloat:614.98],
nil];
}
return prices;
}
- (NSArray *)weeklyMsftPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:32.12],
[NSDecimalNumber numberWithFloat:31.92],
[NSDecimalNumber numberWithFloat:32.20],
[NSDecimalNumber numberWithFloat:32.11],
[NSDecimalNumber numberWithFloat:31.98],
nil];
}
return prices;
}
- (NSArray *)monthlyAaplPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:618.63],
[NSDecimalNumber numberWithFloat:629.32],
[NSDecimalNumber numberWithFloat:624.31],
[NSDecimalNumber numberWithFloat:633.68],
[NSDecimalNumber numberWithFloat:636.23],
[NSDecimalNumber numberWithFloat:628.44],
[NSDecimalNumber numberWithFloat:626.20],
[NSDecimalNumber numberWithFloat:622.77],
[NSDecimalNumber numberWithFloat:605.23],
[NSDecimalNumber numberWithFloat:580.13],
[NSDecimalNumber numberWithFloat:609.70],
[NSDecimalNumber numberWithFloat:608.34],
[NSDecimalNumber numberWithFloat:587.44],
[NSDecimalNumber numberWithFloat:572.98],
[NSDecimalNumber numberWithFloat:571.70],
[NSDecimalNumber numberWithFloat:560.28],
[NSDecimalNumber numberWithFloat:610.00],
[NSDecimalNumber numberWithFloat:607.70],
[NSDecimalNumber numberWithFloat:603.00],
[NSDecimalNumber numberWithFloat:583.98],
nil];
}
return prices;
}
- (NSArray *)monthlyGoogPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:646.92],
[NSDecimalNumber numberWithFloat:642.62],
[NSDecimalNumber numberWithFloat:635.15],
[NSDecimalNumber numberWithFloat:632.32],
[NSDecimalNumber numberWithFloat:630.84],
[NSDecimalNumber numberWithFloat:626.86],
[NSDecimalNumber numberWithFloat:635.96],
[NSDecimalNumber numberWithFloat:651.01],
[NSDecimalNumber numberWithFloat:624.60],
[NSDecimalNumber numberWithFloat:606.07],
[NSDecimalNumber numberWithFloat:609.57],
[NSDecimalNumber numberWithFloat:607.45],
[NSDecimalNumber numberWithFloat:599.30],
[NSDecimalNumber numberWithFloat:596.06],
[NSDecimalNumber numberWithFloat:597.60],
[NSDecimalNumber numberWithFloat:601.27],
[NSDecimalNumber numberWithFloat:609.72],
[NSDecimalNumber numberWithFloat:615.47],
[NSDecimalNumber numberWithFloat:614.98],
[NSDecimalNumber numberWithFloat:604.85],
nil];
}
return prices;
}
- (NSArray *)monthlyMsftPrices
{
static NSArray *prices = nil;
if (!prices)
{
prices = [NSArray arrayWithObjects:
[NSDecimalNumber numberWithFloat:32.29],
[NSDecimalNumber numberWithFloat:31.94],
[NSDecimalNumber numberWithFloat:31.21],
[NSDecimalNumber numberWithFloat:31.52],
[NSDecimalNumber numberWithFloat:31.10],
[NSDecimalNumber numberWithFloat:30.47],
[NSDecimalNumber numberWithFloat:30.35],
[NSDecimalNumber numberWithFloat:30.98],
[NSDecimalNumber numberWithFloat:30.81],
[NSDecimalNumber numberWithFloat:31.08],
[NSDecimalNumber numberWithFloat:31.44],
[NSDecimalNumber numberWithFloat:31.14],
[NSDecimalNumber numberWithFloat:31.01],
[NSDecimalNumber numberWithFloat:32.42],
[NSDecimalNumber numberWithFloat:32.12],
[NSDecimalNumber numberWithFloat:31.92],
[NSDecimalNumber numberWithFloat:32.20],
[NSDecimalNumber numberWithFloat:32.11],
[NSDecimalNumber numberWithFloat:31.98],
[NSDecimalNumber numberWithFloat:32.02],
nil];
}
return prices;
}
@end
#import "CPDBarGraphViewController.h"
@interface CPDBarGraphViewController ()
@property (nonatomic, strong) IBOutlet CPTGraphHostingView *hostView;
@property (nonatomic, strong) CPTBarPlot *aaplPlot;
@property (nonatomic, strong) CPTBarPlot *googPlot;
@property (nonatomic, strong) CPTBarPlot *msftPlot;
@property (nonatomic, strong) CPTPlotSpaceAnnotation *priceAnnotation;
-(IBAction)aaplSwitched:(id)sender;
-(IBAction)googSwitched:(id)sender;
-(IBAction)msftSwitched:(id)sender;
-(void)initPlot;
-(void)configureGraph;
-(void)configurePlots;
-(void)configureAxes;
-(void)hideAnnotation:(CPTGraph *)graph;
@end
@implementation CPDBarGraphViewController
CGFloat const CPDBarWidth = 0.25f;
CGFloat const CPDBarInitialX = 0.25f;
@synthesize hostView = hostView_;
@synthesize aaplPlot = aaplPlot_;
@synthesize googPlot = googPlot_;
@synthesize msftPlot = msftPlot_;
@synthesize priceAnnotation = priceAnnotation_;
#pragma mark - Rotation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
#pragma mark - UIViewController lifecycle methods
-(void)viewDidLoad {
[super viewDidLoad];
[self initPlot];
}
#pragma mark - Chart behavior
-(void)initPlot {
self.hostView.allowPinchScaling = NO;
[self configureGraph];
[self configurePlots];
[self configureAxes];
}
-(void)configureGraph {
// 1 - Create the graph
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
graph.plotAreaFrame.masksToBorder = NO;
self.hostView.hostedGraph = graph;
// 2 - Configure the graph
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainBlackTheme]];
graph.paddingBottom = 30.0f;
graph.paddingLeft = 30.0f;
graph.paddingTop = -1.0f;
graph.paddingRight = -5.0f;
// 3 - Set up styles
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor whiteColor];
titleStyle.fontName = @"Helvetica-Bold";
titleStyle.fontSize = 16.0f;
// 4 - Set up title
NSString *title = @"Portfolio Prices: April 23 - 27, 2012";
graph.title = title;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -16.0f);
// 5 - Set up plot space
CGFloat xMin = 0.0f;
CGFloat xMax = [[[CPDStockPriceStore sharedInstance] datesInWeek] count];
CGFloat yMin = 0.0f;
CGFloat yMax = 800.0f; // should determine dynamically based on max price
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xMin) length:CPTDecimalFromFloat(xMax)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(yMax)];
}
-(void)configurePlots {
// 1 - Set up the three plots
self.aaplPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor redColor] horizontalBars:NO];
self.aaplPlot.identifier = CPDTickerSymbolAAPL;
self.googPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor greenColor] horizontalBars:NO];
self.googPlot.identifier = CPDTickerSymbolGOOG;
self.msftPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
self.msftPlot.identifier = CPDTickerSymbolMSFT;
// 2 - Set up line style
CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineColor = [CPTColor lightGrayColor];
barLineStyle.lineWidth = 0.5;
// 3 - Add plots to graph
CPTGraph *graph = self.hostView.hostedGraph;
CGFloat barX = CPDBarInitialX;
NSArray *plots = [NSArray arrayWithObjects:self.aaplPlot, self.googPlot, self.msftPlot, nil];
for (CPTBarPlot *plot in plots) {
plot.dataSource = self;
plot.delegate = self;
plot.barWidth = CPTDecimalFromDouble(CPDBarWidth);
plot.barOffset = CPTDecimalFromDouble(barX);
plot.lineStyle = barLineStyle;
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
barX += CPDBarWidth;
}
}
-(void)configureAxes {
// 1 - Configure styles
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor whiteColor];
axisTitleStyle.fontName = @"Helvetica-Bold";
axisTitleStyle.fontSize = 12.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:1];
// 2 - Get the graph's axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
// 3 - Configure the x-axis
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axisSet.xAxis.title = @"Days of Week (Mon - Fri)";
axisSet.xAxis.titleTextStyle = axisTitleStyle;
axisSet.xAxis.titleOffset = 10.0f;
axisSet.xAxis.axisLineStyle = axisLineStyle;
// 4 - Configure the y-axis
axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axisSet.yAxis.title = @"Price";
axisSet.yAxis.titleTextStyle = axisTitleStyle;
axisSet.yAxis.titleOffset = 5.0f;
axisSet.yAxis.axisLineStyle = axisLineStyle;
}
-(void)hideAnnotation:(CPTGraph *)graph {
if ((graph.plotAreaFrame.plotArea) && (self.priceAnnotation)) {
[graph.plotAreaFrame.plotArea removeAnnotation:self.priceAnnotation];
self.priceAnnotation = nil;
}
}
#pragma mark - CPTPlotDataSource methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return [[[CPDStockPriceStore sharedInstance] datesInWeek] count];
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
if ((fieldEnum == CPTBarPlotFieldBarTip) && (index < [[[CPDStockPriceStore sharedInstance] datesInWeek] count])) {
if ([plot.identifier isEqual:CPDTickerSymbolAAPL]) {
return [[[CPDStockPriceStore sharedInstance] weeklyPrices:CPDTickerSymbolAAPL] objectAtIndex:index];
} }
return [NSDecimalNumber numberWithUnsignedInteger:index];
}
#pragma mark - CPTBarPlotDelegate methods
-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index {
NSLog(@"barWasSelectedAtRecordIndex %d", index);
}
@end
最佳答案
有another tutorial here那可能对你有帮助。
检查 3. 图形布局,第 24 行。他在那里动态地制作了 Y 轴,但这完全取决于您如何制作数据源。
希望一切都好起来:)
关于ios - Coreplot iOS 中 x 轴和 y 轴上的动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13756047/
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01 客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02 数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit