环信和coreplot ios有冲突么

先看代码,有标注,很详细,看看是如何设定x、y轴的可视范围、移动范围、已经如何确定原点的位置的、还有就是如何固定坐标轴!!!//坐标轴的初始化-(void)axesInit{ // Setup plot space: 设置一屏内可显示的x,y量度范围 CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)[xyGraph defaultPlotSpace]; plotSpace.delegate = plotSpace.allowsUserInteraction = YES;//允许拖动 //设置移动时的停止动画这些参数保持默认即可变化不大 plotSpace.momentumAnimationCurve = CPTAnimationCurveCubicIn; plotSpace.bounceAnimationCurve = CPTAnimationCurveBackIn; plotSpace.momentumAcceleration = 20000.0; //设置x,y在视图显示中大小,也就是点的个数,通过这样设置可以达到放大缩小的效果,来达到我们想要的合理视图显示 plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(18.0) length:CPTDecimalFromFloat(22.0)]; plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(32.0) length:CPTDecimalFromFloat(10.5)]; //设置x、y轴的滚动范围,如果不设置,默认是无线长的
plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-1.0) length:CPTDecimalFromFloat(25.0)]; plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(32.0) length:CPTDecimalFromFloat(10.5)]; // Axes: 设置x,y轴属性,如原点,量度间隔,标签,刻度,颜色等 CPTXYAxisSet *axisSet = (CPTXYAxisSet *)xyGraph.axisS CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle]; lineStyle.miterLimit = 1.0f; lineStyle.lineWidth = 1.0f; lineStyle.lineColor = [CPTColor whiteColor];
[plotSpace setAllowsMomentumX:YES];
CPTXYAxis *x = axisSet.xA
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@&33&);// x轴的原点位置,其实这里是y坐标的值,也就是说x轴的原点在y轴的1位置
x.majorIntervalLength = CPTDecimalFromString(@&1.0&);// x轴主刻度:显示数字标签的量度间隔
x.minorTicksPerInterval= 4;// x轴细分刻度:每一个主刻度范围内显示细分刻度的个数
x.minorTickLineStyle = lineS
lineStyle.lineColor = [CPTColor lightGrayColor]; x.majorGridLineStyle = lineS//这里设置x轴中主刻度的栅格,平行于y轴 // 需要排除的不显示数字的主刻度 NSArray *exclusionRanges = [NSArray arrayWithObjects:
[self CPTPlotRangeFromFloat:0.99 length:0.02],
[self CPTPlotRangeFromFloat:2.99 length:0.02],
nil]; x.labelExclusionRanges = exclusionR
CPTXYAxis *y = axisSet.yA y.orthogonalCoordinateDecimal = CPTDecimalFromString(@&18&);//y轴的原点位置,其实这里是x坐标的值,也就是说y轴的原点在x轴的0位置 //固定y轴,也就是在你水平移动时,y轴是固定在左/右边不动的,以此类推x轴 y.axisConstraints = [CPTConstraints constraintWithLowerOffset:20];//这里是固定y坐标轴在最右边(距离可视右边界有20个像素距离,一遍显示标签)
y.majorIntervalLength = CPTDecimalFromString(@&0.5&); y.minorTicksPerInterval = 4; y.minorTickLineStyle = lineS
y.tickDirection = CPTSignN//标签的方向,对于y轴来说:CPTSignPositive标签在y轴的右边,CPTSignNegative:在y轴的左侧
lineStyle.lineColor = [CPTColor lightGrayColor]; y.majorGridLineStyle = lineS//设置栅格线,平行于x轴 如果 labelingPolicy 设置为 CPTAxisLabelingPolicyNone , majorGridLineStyle 将不起作用 // y.labelingPolicy = CPTAxisLabelingPolicyN NSArray *exclusionRangesY = [NSArray arrayWithObjects:
[self CPTPlotRangeFromFloat:1.99 length:0.2],
[self CPTPlotRangeFromFloat:2.99 length:0.2], nil]; y.labelExclusionRanges = exclusionRangesY; y.delegate = }下面我想说说如何固定一个坐标轴,在移动时,该轴始终是不会动的!上面代码里有://固定y轴,也就是在你水平移动时,y轴是固定在左/右边不动的,以此类推x轴y.axisConstraints = [CPTConstraints constraintWithLowerOffset:20];//这里是固定y坐标轴在最右边(距离可视右边界有20个像素距离,一遍显示标签)下面分析一下相应的方法有哪些:主要在CPTConstraints.h和CPTConstraints.m中实现的/** @brief Creates and returns a new CPTConstraints instance initialized with a fixed offset from the lower bound. *@param newOffset The offset. *@return A new CPTConstraints instance initialized with the given offset. *@sfx :该函数主要是实现固定坐标轴在距离最小端newoffset的地方,我个人对大端小端的理解:对y轴来说,最大端(或者说最高处)也就是我们坐标系bounce的右边界 *最小端(或者说最低处)就是坐标系视图boundce的左边界,这样x轴也就同样可以理解了,相应的就是上、下边界 **/+(CPTConstraints *)constraintWithLowerOffset:(CGFloat)newOffset{return [[(_CPTConstraintsFixed *)[_CPTConstraintsFixed alloc] initWithLowerOffset : newOffset] autorelease];}/** @brief Creates and returns a new CPTConstraints instance initialized with a fixed offset from the upper bound. *@param newOffset The offset. *@return A new CPTConstraints instance initialized with the given offset.&pre name=&code& class=&objc&& *@sfx :该函数主要是实现固定坐标轴在距离最高端newoffset的地方,我个人对大端小端的理解:对y轴来说,最大端(或者说最高处)也就是我们坐标系bounce的右边界 *最小端(或者说最低处)就是坐标系视图boundce的左边界,这样x轴也就同样可以理解了,相应的就是上、下边界&**/+(CPTConstraints *)constraintWithUpperOffset:(CGFloat)newOffset{ return [[(_CPTConstraintsFixed *)[_CPTConstraintsFixed alloc] initWithUpperOffset : newOffset] autorelease];}/** @brief Creates and returns a new CPTConstraints instance initialized with a proportional offset relative to the bounds. * * For example, an offset of @num{0.0} will return a position equal to the lower bound, @num{1.0} will return the upper bound, * and @num{0.5} will return a point midway between the two bounds. * * @param newOffset The offset.* @sfx : 这个类方法实现的是按一定比例值来固定坐标轴,比如我们固定y轴,如果newoffset = 1.0,就相当于把y轴固定在右边界,如果newoffset = 0.0 就是左边界,如果等于0.5就是中间newoffset取值范围:0 --- 1.0&* @return A new CPTConstraints instance initialized with the given offset. **/+(CPTConstraints *)constraintWithRelativeOffset:(CGFloat)newOffset{ return [[(_CPTConstraintsRelative *)[_CPTConstraintsRelative alloc] initWithRelativeOffset : newOffset] autorelease];}2216人阅读
Core Plot是OS X和IOS下的一个开源图形库,它提供数据的可视化处理,就是画曲线图、柱状图和饼图等等。如何在项目中使用Core Plot的静态库呢?以下是几个步骤:
首先先去Google Code下载Core Plot图形库,网址&&。目前该网址提供了CorePlot_1.0.zip下载,下载后解压。
然后打开压缩包中的ReadMes文件中的“README for Static Library Install”文件,该文件内容如下:
Install Binaries for iOS
1. Copy the CorePlotHeaders to your Xcode project
2. Copy libCorePlotCocoaTouch.a to your Xcode project
3. Add to Other Linker Flags in your target build settings:
-ObjC -all_load
4. Add the QuartzCore framework to the project.
5. Add a CPTGraph to your application. See the example apps in Source Code to see how, or read the documentation.
其实如何使用CorePlot的静态库该文档说明的很清楚了,以下结合示意图说明如何操作。
1.找到刚才压缩包中的&Binaries--&iOS&文件夹,把整个“CorePlotHeaders”文件夹拷贝到项目中,拷贝的时候记得选上“Copy items into destination group's folder(if need)”选项。
2.把上述文件夹中的&libCorePlotCocoaTouch.a&拷贝到项目中,也选上“Copy items into destination group's folder(if need)”选项。
3.项目目标的编译设置的“Other Linker Flags”选择项中加入 &“-ObjC -all_load”
完成以上几个步骤后大致如下图所示,注意画红线的地方:
4.把“QuartzCore”框架加入项目中,操作如下:
到此已经可以工作了,第5点实际上是针对编程的,告诉你要把图形画在“CPTGraph”上。具体的代码可以参考CorePlot压缩包自带examples, 其中在ios下有个例子比较有用:“CorePlotGallery” 。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:57981次
排名:千里之外
原创:12篇
评论:17条
(1)(1)(3)(1)(1)(3)(4)创建单视图工程,导入CorePloLib库,
声明私有成员和方法
请参考文件:
@interface KSViewController ()
CPTXYGraph * _
NSMutableArray * _dataForP
- (void)setupCoreplotV
-(CPTPlotRange *)CPTPlotRangeFromFloat:(float)location length:(float)
在本例中,要描绘基于 xy 轴的图形,因此,声明了 CPTXYGraph 对象 _graph,然后声明一个可变数字 _dataForPlot 为 Core Plot 提供数据。私有方法 setupCoreplotView 是本例的重点,所有的描绘设置都在这个函数中进行。CPTPlotRangeFromFloat:length:是一个辅助类以简化 CPTPlotRange 的创建,其实现如下:
-(CPTPlotRange *)CPTPlotRangeFromFloat:(float)location length:(float)length
return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(location) length:CPTDecimalFromFloat(length)];
为了支持旋转操作,添加如下代码(注意,本文只考虑了 iOS6 的旋转,这又是 iOS 兼容性不太好的一大明证啊!):
#pragma mark -
#pragma mark Rotation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
return YES;
-(BOOL)shouldAutorotate
return YES;
4,实现&setupCoreplotViews
先来看效果说明图,此图非常重要,CorePlot常见的概念都在图中有说明,后文会多次引用到该图。
下面,来介绍重点内容,如何使用 CorePlot 对数据进行描绘。
- (void)setupCoreplotViews
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
// Create graph from theme: 设置主题
_graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme * theme = [CPTTheme themeNamed:kCPTSlateTheme];
[_graph applyTheme:theme];
CPTGraphHostingView * hostingView = (CPTGraphHostingView *)self.
hostingView.collapsesLayers = NO; // Setting to YES reduces GPU memory usage, but can slow drawing/scrolling
hostingView.hostedGraph = _
_graph.paddingLeft = _graph.paddingRight = 10.0;
_graph.paddingTop = _graph.paddingBottom = 10.0;
a)首先,创建了一个可编辑的线条风格 lineStyle,用来描述描绘线条的宽度,颜色和样式等,这个 lineStyle 会被多次用到。
然后,创建基于 xy 轴的图:CPTXYGraph,并设置其主题 CPTTheme,CorePlot 中的主题和日常软件中的换肤概念差不多。目前支持五种主题:kCPTDarkGradientTheme,&kCPTPlainBlackTheme,&kCPTPlainWhiteTheme,&kCPTSlateTheme,kCPTStocksTheme,&最后一种股票主题效果见上面的效果图,而石板色主题
kCPTSlateTheme 效果见下面的效果图。你可以修改此处的代码尝试不同的主题效果,^_^。将 hostingView的 hostedGraph与 _graph 关联起来,也就是说:我们要在 View (CPTGraphHostingView)上画一个基于xy轴的图(CPTXYGraph)。至此,我们接触到CorePlot中的两个概念:宿主view 和图graph。然后我们设置_graph的 padding,这样在图的四周与屏幕边缘之间留有一丝空隙。
// Setup plot space: 设置一屏内可显示的x,y量度范围
CPTXYPlotSpace * plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotS
plotSpace.allowsUserInteraction = YES;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(2.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)];
上面的代码设置PlotSpace,这是什么意思呢?x,y二维空间可以无限延伸,但在屏幕上我们可以看到的只是一小部分空间,这部分可视空间就由 Plot Space设置。CPTXYPlotSpace 的 xRange 和 yRange 就设置了一屏内可显示的x,y方向的量度范围。在这里,我们设置x,y轴上的起点都是1.0,然后长度分别为2个和3个单位。请结合上面的说明图理解 PlotSpace 的含义。(注意:说明图中的起点不是1.0,这是因为设置了 allowsUserInteraction 为 YES,我对PlotSpace进行了拖动所导致的)。
// Axes: 设置x,y轴属性,如原点,量度间隔,标签,刻度,颜色等
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)_graph.axisS
lineStyle.miterLimit = 1.0f;
lineStyle.lineWidth = 2.0;
lineStyle.lineColor = [CPTColor whiteColor];
CPTXYAxis * x = axisSet.xA
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@&2&); // 原点的 x 位置
x.majorIntervalLength = CPTDecimalFromString(@&0.5&);
// x轴主刻度:显示数字标签的量度间隔
x.minorTicksPerInterval = 2;
// x轴细分刻度:每一个主刻度范围内显示细分刻度的个数
x.minorTickLineStyle = lineS
// 需要排除的不显示数字的主刻度
NSArray * exclusionRanges = [NSArray arrayWithObjects:
[self CPTPlotRangeFromFloat:0.99 length:0.02],
[self CPTPlotRangeFromFloat:2.99 length:0.02],
x.labelExclusionRanges = exclusionR
b), 有了 xy 轴图对象,我们可以来对 xy 轴的显示属性进行设置了。通过获取 XYGraph 的 axisSet 来获取轴的集合,集合中就包含了 x,y 轴对象 CPTXYAxis。在这里,设置 x 轴的原点为 2,主刻度的量度间隔为 0.5,每一个主刻度内显示细分刻度的个数为 2 个,并用白色宽度为2的线条来描绘 x 轴。如果有一些刻度的标签我们不想让它显示那该如何呢?很简单,设置轴的排除标签范围&labelExclusionRanges&即可。
同样,我们设置 y 轴的显示属性:
CPTXYAxis * y = axisSet.yA
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@&2&); // 原点的 y 位置
y.majorIntervalLength = CPTDecimalFromString(@&0.5&);
// y轴主刻度:显示数字标签的量度间隔
y.minorTicksPerInterval = 4;
// y轴细分刻度:每一个主刻度范围内显示细分刻度的个数
y.minorTickLineStyle = lineS
exclusionRanges = [NSArray arrayWithObjects:
[self CPTPlotRangeFromFloat:1.99 length:0.02],
[self CPTPlotRangeFromFloat:2.99 length:0.02],
y.labelExclusionRanges = exclusionR
y.delegate =
请参考说明图理解上面轴设置的含义。注意,在这里,我设置了 y 轴的 delegate 为自身,这个 delegate 需要实现CPTAxisDelegate 协议,在这里我想要用不同的颜色对 y 轴方向大于等于0和小于0的刻度标签进行区分,因此需要实现该协议方法:axis:shouldUpdateAxisLabelsAtLocations:。
#pragma mark -
#pragma mark Axis Delegate Methods
-(BOOL)axis:(CPTAxis *)axis shouldUpdateAxisLabelsAtLocations:(NSSet *)locations
static CPTTextStyle * positiveStyle =
static CPTTextStyle * negativeStyle =
NSNumberFormatter * formatter
= axis.labelF
CGFloat labelOffset
= axis.labelO
NSDecimalNumber * zero
= [NSDecimalNumber zero];
NSMutableSet * newLabels
= [NSMutableSet set];
for (NSDecimalNumber * tickLocation in locations) {
CPTTextStyle *theLabelTextS
if ([tickLocation isGreaterThanOrEqualTo:zero]) {
if (!positiveStyle) {
CPTMutableTextStyle * newStyle = [axis.labelTextStyle mutableCopy];
newStyle.color = [CPTColor greenColor];
positiveStyle
theLabelTextStyle = positiveS
if (!negativeStyle) {
CPTMutableTextStyle * newStyle = [axis.labelTextStyle mutableCopy];
newStyle.color = [CPTColor redColor];
negativeStyle
theLabelTextStyle = negativeS
NSString * labelString
= [formatter stringForObjectValue:tickLocation];
CPTTextLayer * newLabelLayer= [[CPTTextLayer alloc] initWithText:labelString style:theLabelTextStyle];
CPTAxisLabel * newLabel
= [[CPTAxisLabel alloc] initWithContentLayer:newLabelLayer];
newLabel.tickLocation
= tickLocation.decimalV
newLabel.offset
[newLabels addObject:newLabel];
axis.axisLabels = newL
return NO;
在上面的代码中,对于 y 轴上大于等于0的刻度标签用绿色描绘,而小于0的刻度标签用红色描绘。因为在这里我们自己设置了轴标签的描绘,所以这个方法返回 NO 告诉系统不需要使用系统的标签描绘设置了。其效果如下:
至此,xy轴部分的描绘设置完成。
c) 下面我们向图中添加曲线的描绘:
// Create a red-blue plot area
lineStyle.miterLimit
lineStyle.lineWidth
lineStyle.lineColor
= [CPTColor blueColor];
CPTScatterPlot * boundLinePlot
= [[CPTScatterPlot alloc] init];
boundLinePlot.dataLineStyle = lineS
boundLinePlot.identifier
= BLUE_PLOT_IDENTIFIER;
boundLinePlot.dataSource
// Do a red-blue gradient: 渐变色区域
CPTColor * blueColor
= [CPTColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8];
CPTColor * redColor
= [CPTColor colorWithComponentRed:1.0 green:0.3 blue:0.3 alpha:0.8];
CPTGradient * areaGradient1 = [CPTGradient gradientWithBeginningColor:blueColor
endingColor:redColor];
areaGradient1.angle = -90.0f;
CPTFill * areaGradientFill
= [CPTFill fillWithGradient:areaGradient1];
boundLinePlot.areaFill
= areaGradientF
boundLinePlot.areaBaseValue = [[NSDecimalNumber numberWithFloat:1.0] decimalValue]; // 渐变色的起点位置
// Add plot symbols: 表示数值的符号的形状
CPTMutableLineStyle * symbolLineStyle = [CPTMutableLineStyle lineStyle];
symbolLineStyle.lineColor = [CPTColor blackColor];
symbolLineStyle.lineWidth = 2.0;
CPTPlotSymbol * plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.fill
= [CPTFill fillWithColor:[CPTColor blueColor]];
plotSymbol.lineStyle
= symbolLineS
plotSymbol.size
= CGSizeMake(10.0, 10.0);
boundLinePlot.plotSymbol = plotS
[_graph addPlot:boundLinePlot];
首先,添加一个由红到蓝渐变的曲线图 CPTScatterPlot,设置该曲线图的曲线线条颜色为蓝色,宽度为3,标识为&@&Blue Plot&,数据源 datasource 为自身。注意:一个图中可以有多个曲线图,每个曲线图通过其&identifier 进行唯一标识。 数据源将在后面介绍。如果我们不仅仅是描绘曲线,还想描绘曲线覆盖的区域,那么就要设置曲线图的区域填充颜色 areaFill,并设置 areaBaseValue。areaBaseValue就是设置该填充颜色从哪个值开始描述,比如本例是从1.0开始描绘(见上图中红色部分开始的位置为
y=1)。在这里我们设置的填充颜色为从红色变到蓝色的渐变色 CPTGradient,CPTGradient默认的变化开始色从x轴左边变化到右边的结束色,如下图所示:
在本例中,将渐变色旋转-90度(即顺时针方向旋转90度),使得红色在下面,蓝色在上面(见说明图)。 对于曲线上的数值点用什么样的符号来表示呢?这就是CPTPlotSymbol 发挥作用的时候了,在这里是用蓝色的实心圆点来表示具体的数值。
d), 有了蓝红曲线图的介绍,下面再来添加一个破折线风格的绿色曲线图:
// Create a green plot area: 画破折线
= [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth
lineStyle.lineColor
= [CPTColor greenColor];
lineStyle.dashPattern
= [NSArray arrayWithObjects:
[NSNumber numberWithFloat:5.0f],
[NSNumber numberWithFloat:5.0f], nil];
CPTScatterPlot * dataSourceLinePlot = [[CPTScatterPlot alloc] init];
dataSourceLinePlot.dataLineStyle = lineS
dataSourceLinePlot.identifier = GREEN_PLOT_IDENTIFIER;
dataSourceLinePlot.dataSource =
// Put an area gradient under the plot above
CPTColor * areaColor
= [CPTColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8];
CPTGradient * areaGradient
= [CPTGradient gradientWithBeginningColor:areaColor
endingColor:[CPTColor clearColor]];
areaGradient.angle
areaGradientFill
= [CPTFill fillWithGradient:areaGradient];
dataSourceLinePlot.areaFill
= areaGradientF
dataSourceLinePlot.areaBaseValue= CPTDecimalFromString(@&1.75&);
// Animate in the new plot: 淡入动画
dataSourceLinePlot.opacity = 0.0f;
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@&opacity&];
fadeInAnimation.duration
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode
= kCAFillModeF
fadeInAnimation.toValue
= [NSNumber numberWithFloat:1.0];
[dataSourceLinePlot addAnimation:fadeInAnimation forKey:@&animateOpacity&];
[_graph addPlot:dataSourceLinePlot];
上面的代码与前面的红蓝渐变曲线图结构大体相同,只不过在这里使用的市破折线风格的线条,并且没有使用特殊符号对数值点进行描绘。在这里,我们添加了一个有意思的淡入动画。
至此,描绘相关设置就完成了。先来回顾一下整个步骤:
a) 在 CPTGraphHostingView 上放置一个 xy 轴图 CPTXYGraph;
b) 然后对 xy 轴图进行设置,设置其主题,可视空间 CPTPlotSpace,以及两个轴 CPTXYAxis;
c) 然后在 xy 轴图上添加红蓝渐变的曲线图CPTScatterPlot;
d) 然后在 xy 轴图上添加绿色破折线曲线图CPTScatterPlot;
e) 最后,我们来初始化一些演示数据,从而结束 setupCoreplotViews 方法的介绍。
// Add some initial data
_dataForPlot = [NSMutableArray arrayWithCapacity:100];
for ( i = 0; i & 100; i++ ) {
id x = [NSNumber numberWithFloat:0 + i * 0.05];
id y = [NSNumber numberWithFloat:1.2 * rand() / (float)RAND_MAX + 1.2];
[_dataForPlot addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @&x&, y, @&y&, nil]];
5,实现数据源协议
#pragma mark -
#pragma mark Plot Data Source Methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
return [_dataForPlot count];
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
NSString * key = (fieldEnum == CPTScatterPlotFieldX ? @&x& : @&y&);
NSNumber * num = [[_dataForPlot objectAtIndex:index] valueForKey:key];
// Green plot gets shifted above the blue
if ([(NSString *)plot.identifier isEqualToString:GREEN_PLOT_IDENTIFIER]) {
if (fieldEnum == CPTScatterPlotFieldY) {
num = [NSNumber numberWithDouble:[num doubleValue] + 1.0];
和 NSTableView 相似,我们需要提供数据的个数,以及对应x/y轴的数据。至此,编译允许,你就能看到如期的效果:绿色破折线曲线图淡入,然后整个xy轴图就呈现在你面前,并且该图是允许你拖拽的,不妨多拖拽下,以更好地理解 CorePlot 中各种概念属性的含义。
6,动态修改 CPTPlotSpace 的范围
为了让例子更有趣一点,在 SetupCoreplotViews 的末尾添加如下代码:
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(changePlotRange) userInfo:nil repeats:YES];
并实现 changePlotRange 方法:
-(void)changePlotRange
// Change plot space
CPTXYPlotSpace * plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotS
plotSpace.xRange = [self CPTPlotRangeFromFloat:0.0 length:(3.0 + 2.0 * rand() / RAND_MAX)];
plotSpace.yRange = [self CPTPlotRangeFromFloat:0.0 length:(3.0 + 2.0 * rand() / RAND_MAX)];
四,Core Plot 框架结构分析
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:46728次
积分:1370
积分:1370
排名:第14527名
原创:92篇
转载:26篇
(1)(8)(2)(17)(2)(4)(1)(4)(12)(5)(4)(17)(9)(3)(18)(12)

我要回帖

更多关于 coreplot ios 的文章

 

随机推荐