gpt4 book ai didi

ios - 我想使用 CorePlot 从图形中删除负数部分?

转载 作者:行者123 更新时间:2023-11-29 02:48:04 25 4
gpt4 key购买 nike

我在我的应用程序中实现了核心绘图库,我想从我的图表中删除负面部分,我在谷歌上搜索了很多,但找不到任何答案。当我向下滚动图表时会显示图表上的负值,并且还会显示我向左滚动。这是我的代码

-(void)drawGraph{

graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];

CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[graph applyTheme:theme];

hostingView1 = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
hostingView1.hostedGraph = graph;
if ([[UIScreen mainScreen] bounds].size.height == 568){
hostingView1.frame = CGRectMake(15, 5, 290, 220);
}
else{
hostingView1.frame = CGRectMake(15, 3, 290, 135);
}
[myGraphView addSubview:hostingView1];
[myGraphView addSubview:lbl1];
[myGraphView addSubview:lbl2];

[lbl1 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[hostingView1 release];


graph.paddingLeft = 0;
graph.paddingTop = 0;
graph.paddingRight = 0;
graph.paddingBottom = 0;

graph.plotAreaFrame.paddingLeft = 35.0 ;
graph.plotAreaFrame.paddingTop = 20.0 ;
graph.plotAreaFrame.paddingRight = 5.0 ;
graph.plotAreaFrame.paddingBottom = 30 ;

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;

plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(50.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(10.0)];

CPTXYAxisSet *axisSet = (CPTXYAxisSet *) graph.axisSet ;
CPTXYAxis *x = axisSet.xAxis ;
x. minorTickLineStyle = nil ;

x. majorIntervalLength = CPTDecimalFromString (@"10");

x. orthogonalCoordinateDecimal = CPTDecimalFromString ( @"0" );

CPTXYAxis *y = axisSet.yAxis ;

y. minorTickLineStyle = nil ;

y. majorIntervalLength = CPTDecimalFromString ( @"2" );

y. orthogonalCoordinateDecimal = CPTDecimalFromString (@"0");

dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = @"Green Plot";

CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 0.3f;
lineStyle.lineColor = [CPTColor orangeColor];
dataSourceLinePlot.dataLineStyle = lineStyle;

dataSourceLinePlot.opacity = 0.0f;

dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];

CPTGradient *areaGradient = [ CPTGradient gradientWithBeginningColor :[CPTColor orangeColor] endingColor :[CPTColor colorWithComponentRed:0.55 green:0.55 blue:0.16 alpha:0.0]];

areaGradient.angle = -00.0f ;

CPTFill *areaGradientFill = [ CPTFill fillWithGradient :areaGradient];

dataSourceLinePlot. areaFill = areaGradientFill;
dataSourceLinePlot. areaBaseValue = CPTDecimalFromString ( @"0.0" );
dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationLinear ;


}

最佳答案

让处理图形的 View /对象采用 CPTPlotSpaceDelegate 协议(protocol):

@interface YourViewController () <CPTPlotSpaceDelegate>

然后将 Controller 分配给绘图空间的委托(delegate):

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
[plotSpace setDelegate:self];

最后,让 Controller 实现 CPTPlotSpaceDelegate 函数“willChangePlotRangeTo”

-(CPTPlotRange*)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
{
if([newRange locationDouble] < 0)
{
if(coordinate == CPTCoordinateX)
return [(CPTXYPlotSpace*)space xRange];
else if(coordinate == CPTCoordinateY)
return [(CPTXYPlotSpace*)space yRange];
}
return newRange;
}

这会通过返回当前绘图范围来防止绘图空间进一步滚动。如果您决定需要为任一轴更改它,您可以声明您想要的任何下边界。

关于ios - 我想使用 CorePlot 从图形中删除负数部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24858149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com