CorePlot:创建具有可变宽度的波段(基于数据改变) [英] CorePlot: creating bands with mutable widths (changing based on data)

查看:182
本文介绍了CorePlot:创建具有可变宽度的波段(基于数据改变)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个带有动态乐队的 CorePlot 图表(随着时间的推移而变化),有点像这里的丑陋画图(请原谅我质量):



基本上乐队着色应该根据一些值/标准进行更改。黄色带可以稀薄,白色和绿色带也可以。 换言之,这些乐队需要有动态宽度 这是目前我设置y图谱乐队着色的方式,但是如果我动态更改它不起作用,因为它改变了它们(我只是想在图的特定区域动态地改变乐队而不是全部)。



任何想法如何实现这一目标?

这是与 / strong>:

  CPTFill * whitebandFill = [CPTFill fillWithColor:[[CPTColor whiteColor] colorWithAlphaComponent:0.5]]; 
CPTFill * greenbandFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.5]];
CPTFill * redbandFill = [CPTFill fillWithColor:[[CPTColor redColor] colorWithAlphaComponent:0.75]];

[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(0.0)lengthDecimal:CPTDecimalFromDouble(500.0)] fill:whitebandFill]];
[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(500.0)lengthDecimal:CPTDecimalFromDouble(750.0)] fill:greenbandFill]];

[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(750.0)lengthDecimal:CPTDecimalFromDouble(1024.0)] fill:redbandFill]];

这是我的完整当前源代码:

  self.data = [[NSMutableArray alloc] initWithCapacity:100]; 
self.allData = [[NSMutableArray alloc] init];

//创建一个CPTGraph对象并添加到hostView
self.graph = [[CPTXYGraph alloc] initWithFrame:self.graphHostView.bounds];
self.graphHostView.hostedGraph = self.graph;

CPTMutableTextStyle * titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor blackColor];
titleStyle.fontName = @Futura;
titleStyle.fontSize = 12.0f;

//////////
//轴
//用固定间隔策略标记x轴
CPTXYAxisSet * axisSet =(CPTXYAxisSet * )self.graph.axisSet;
CPTXYAxis * x = axisSet.xAxis;
x.separateLayers = NO;
x.title = @X Axis;
x.titleTextStyle = titleStyle;

colorWithAlphaComponent:CPTFloat(0.1)],[[CPTColor greenColor] colorWithAlphaComponent:CPTFloat(0.1)]] ;
x.delegate = self;

  CPTXYAxis * y = axisSet.yAxis; 
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.separateLayers = YES;
y.majorTickLocations = [NSSet setWithObjects:
[NSDecimalNumber numberWithDouble:0],
[NSDecimalNumber numberWithDouble:300],
nil];

y.title = @Y轴;
y.titleTextStyle = titleStyle;

colorWithAlphaComponent:CPTFloat(0.3)],[NSNull null]];
y.delegate = self;

  CPTFill * whitebandFill = [CPTFill fillWithColor:[[CPTColor whiteColor] colorWithAlphaComponent:0.5 ]]; 
CPTFill * greenbandFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.5]];
CPTFill * redbandFill = [CPTFill fillWithColor:[[CPTColor redColor] colorWithAlphaComponent:0.75]];

[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(0.0)lengthDecimal:CPTDecimalFromDouble(500.0)] fill:whitebandFill]];
[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(500.0)lengthDecimal:CPTDecimalFromDouble(750.0)] fill:greenbandFill]];

[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(750.0)lengthDecimal:CPTDecimalFromDouble(1024.0)] fill:redbandFill]];

self.graph.axisSet.axes = @ [x,y];


解决方案

。您可以使用其他绘图绘制更复杂的形状。设置 areaFill 在绘图线和 areaBaseValue 之间绘制填充。


I would like to create a CorePlot graph with dynamic bands (changing as the time goes along), a little bit like this ugly drawing here (forgive me for the quality):

Basically the band colouring should change based on some values/criteria. The yellow band can be wider or thinner and so can the white and green band. In other words these bands need to have dynamic width

This is the current way I set the y graph band colouring, however if I dynamically change it it does not work as it changes them all (I just want to change the band dynamically in a specific area of the graph and not all of it).

Any idea how I can achieve this?

This is the code related to the band:

CPTFill *whitebandFill = [CPTFill fillWithColor:[[CPTColor whiteColor] colorWithAlphaComponent:0.5]];
CPTFill *greenbandFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.5]];
CPTFill *redbandFill = [CPTFill fillWithColor:[[CPTColor redColor] colorWithAlphaComponent:0.75]];

 [y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(0.0) lengthDecimal:CPTDecimalFromDouble(500.0)] fill:whitebandFill]];
[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(500.0) lengthDecimal:CPTDecimalFromDouble(750.0)] fill:greenbandFill]];

 [y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(750.0) lengthDecimal:CPTDecimalFromDouble(1024.0)] fill:redbandFill]];

This is my complete current source code:

self.data = [[NSMutableArray alloc] initWithCapacity:100];
self.allData = [[NSMutableArray alloc] init];

// Create a CPTGraph object and add to hostView
self.graph = [[CPTXYGraph alloc] initWithFrame:self.graphHostView.bounds];
self.graphHostView.hostedGraph = self.graph;

CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor blackColor];
titleStyle.fontName = @"Futura";
titleStyle.fontSize = 12.0f;

//////////
// Axes
// Label x axis with a fixed interval policy
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
CPTXYAxis *x          = axisSet.xAxis;
x.separateLayers              = NO;
x.title                       = @"X Axis";
x.titleTextStyle              = titleStyle;

colorWithAlphaComponent:CPTFloat(0.1)], [[CPTColor greenColor] colorWithAlphaComponent:CPTFloat(0.1)]]; x.delegate = self;

CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy        = CPTAxisLabelingPolicyAutomatic;
y.separateLayers        = YES;
y.majorTickLocations = [NSSet setWithObjects:
                        [NSDecimalNumber numberWithDouble:0],
                        [NSDecimalNumber numberWithDouble:300],
                        nil];

y.title                 = @"Y Axis";
y.titleTextStyle        = titleStyle;

colorWithAlphaComponent:CPTFloat(0.3)], [NSNull null]]; y.delegate = self;

CPTFill *whitebandFill = [CPTFill fillWithColor:[[CPTColor whiteColor] colorWithAlphaComponent:0.5]];
CPTFill *greenbandFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.5]];
CPTFill *redbandFill = [CPTFill fillWithColor:[[CPTColor redColor] colorWithAlphaComponent:0.75]];

 [y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(0.0) lengthDecimal:CPTDecimalFromDouble(500.0)] fill:whitebandFill]];
[y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(500.0) lengthDecimal:CPTDecimalFromDouble(750.0)] fill:greenbandFill]];

 [y addBackgroundLimitBand:[CPTLimitBand limitBandWithRange:[CPTPlotRange plotRangeWithLocationDecimal:CPTDecimalFromDouble(750.0) lengthDecimal:CPTDecimalFromDouble(1024.0)] fill:redbandFill]];

self.graph.axisSet.axes = @[x, y];

解决方案

Limit bands always extend across the plot area in strait lines. You can draw more complex shapes by using additional plots. Set the areaFill to draw a fill between the plot line and the areaBaseValue.

这篇关于CorePlot:创建具有可变宽度的波段(基于数据改变)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆