iphone, using an array to define in core-plot range(iphone,使用数组在核心绘图范围内定义)
问题描述
我已经完成了几天工作的核心情节图.我仍然无法做的事情(而且我找不到关于此的文档),就是将 x 轴标签更改为我需要的.今天,我有一个 x 轴,每 5 个值显示一个整数标签:5 10 15 ...",我需要对应过去 24 小时的标签.例如,如果现在是 15:00,我需要如下标签:15 16 17 ... 23 0 1 2 .. 15"我正在考虑为此使用 NSArray 并将其传递给 plotSpace.xRange 但我没有知道这是否是这样做的好方法.这是我的代码:
I'm almost done with a core-plot graph I've been working on for a couple of day now. There is something I am still not able to do (and I cannot find documentation on this), is to change the x axis labels to what I need. Today, I have an x axis with integer label beeing displayed every 5 values: "5 10 15...", I need to have labels coresponding to the last 24 hours. For instance if it's 15:00, I would need labels like: "15 16 17 ... 23 0 1 2 .. 15" I was thinking of using a NSArray for this and passing it to the plotSpace.xRange but I do not know if this is the good way to do it. Here is my code:
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-15)
length:CPDecimalFromFloat(xmax + 15)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-1000)
length:CPDecimalFromFloat(4300)];
// Setup axis
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor whiteColor];
lineStyle.lineWidth = 1.0f;
CPTextStyle *cyanStyle = [CPTextStyle textStyle];
cyanStyle.color = [CPColor cyanColor];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:0];
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.xAxis.minorTicksPerInterval = 0;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLength = 5.0f;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.xAxis.labelExclusionRanges = [NSArray arrayWithObjects:
[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-15)
length:CPDecimalFromFloat(15)],
nil];
axisSet.xAxis.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromInteger(0) length:CPDecimalFromInteger(xmax)];
axisSet.xAxis.labelFormatter = formatter;
axisSet.xAxis.title = @"Hour";
axisSet.xAxis.titleOffset = 25.0f;
axisSet.xAxis.titleLocation = CPDecimalFromFloat(25.0f);
axisSet.xAxis.titleTextStyle = cyanStyle;
非常欢迎任何帮助:)非常感谢,卢克
Any help would be really welcome :) Thanks a lot, Luc
推荐答案
我终于找到了使用自定义标签的解决方案:
I finally found the solution using custom label:
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0],
[NSDecimalNumber numberWithInt:5],
[NSDecimalNumber numberWithInt:10],
[NSDecimalNumber numberWithInt:15],
[NSDecimalNumber numberWithInt:20],
[NSDecimalNumber numberWithInt:25],
[NSDecimalNumber numberWithInt:30],
[NSDecimalNumber numberWithInt:35],
[NSDecimalNumber numberWithInt:40],
nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"15",@"18",@"21",@"0",@"3",@"6",@"9",@"12",@"15",nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:axisSet.xAxis.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength;
[customLabels addObject:newLabel];
[newLabel release];
}
axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels];
还有一些事情要澄清,但这肯定是要走的路:)卢克
Still have some thing to clarify but this is surely the way to go :) Luc
这篇关于iphone,使用数组在核心绘图范围内定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iphone,使用数组在核心绘图范围内定义
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01