remove negative axes from coreplot(scatter plot) in iphone - iphone

How to remove negative axes from corePlot(scatterplot) in iphone and how to set the area of graph that is visible?

Here are some examples pulled from the CPTTestApp example included with Core Plot:
Setting plot ranges:
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0)
length:CPTDecimalFromDouble(-10.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.5)
length:CPTDecimalFromDouble(1500.0)];
Remember that plot ranges are similar to NSRange—they have a starting location and length. The length can be negative if you want the reverse the direction of an axis.
Limiting the length of axes:
yAxis.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(2)
length:CPTDecimalFromInteger(3)];
yAxis.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(2)
length:CPTDecimalFromInteger(3)];
Changing the visible area:
graph.paddingLeft = 60.0;
graph.paddingTop = 60.0;
graph.paddingRight = 60.0;
graph.paddingBottom = 60.0;
You can also set padding on graph.plotAreaFrame to inset the plot area to create room for axis labels and titles.
Eric

Use plotRangeWithLocation: length: methods.
-(void)initXYAxesRanges{
//Set graph ranges for x and y planes
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(10];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(10)];
}

Related

CPTScatterPlotInterpolationCurved going out of bounds unable to determine scale

I have determined somewhat flexible way to determine size of chart and axes, but I've got problem with CPTScatterPlotInterpolationCurved, because it can be higher than maximum data provided (unable to calculate how much easily).
Is there any property or method that can return maximum value after interpolation?
Example here (look at the top cut # green tick)
Code that calculates bounds:
// Setup scatter plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
CGFloat margin = [[self.dataArray valueForKeyPath:#"#max.floatValue"] integerValue]*0.10;
double xLow = 0.0f;
double yHigh = 0;
double yLow = 0;
double xHigh = [self drawnDataTilPlot:self.graph.allPlots.lastObject] + [self.dividedDataArray.lastObject count]-1;
if (round([[self.dataArray valueForKeyPath:#"#max.floatValue"] integerValue]/10)*10 < [[self.dataArray valueForKeyPath:#"#max.floatValue"] integerValue]) {
yHigh = [[self.dataArray valueForKeyPath:#"#max.floatValue"] integerValue] + margin;
}
else {
yHigh = round([[self.dataArray valueForKeyPath:#"#max.floatValue"] integerValue]/10)*10+margin;
}
if (self.type == GRChartTypeScatterLine) {
yLow = [[self.dataArray valueForKeyPath:#"#min.floatValue"] integerValue];
yLow -= margin*0.5;
yHigh -= yLow;
}
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xLow) length:CPTDecimalFromFloat(xHigh)];
if ([[self.dataArray valueForKeyPath:#"#max.integerValue"]integerValue]==0 &&
[[self.dataArray valueForKeyPath:#"#min.integerValue"]integerValue]==0){
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-1) length:CPTDecimalFromFloat(2)];
}
else {
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yLow) length:CPTDecimalFromFloat(yHigh)];
}
There isn't any way to do this right now. See the comments on issue 131 for one possible workaround.

Core Plot on iPhone - Extra white Lines beside Axes

I'm using Core Plot to do some graphing in an iOS app. I'm in the midst of configuring the axes, and I'm getting strange white lines below the X and to the left of the Y axis, as seen in the following picture:
My set-up code for the graph is as follows:
// 1 - Create the graph
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.barHostView.bounds];
graph.plotAreaFrame.masksToBorder = NO;
self.barHostView.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
graph.title = [NSString stringWithFormat:#"Usage on %#", self.turnout];
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -16.0f);
// 5 - Set up plot space
CGFloat xMin = -1.5f;
CGFloat xMax = [self.points count] + 2;
CGFloat yMin = 0.0f;
self.yMax = [[self greatestFlowValue] floatValue] * 1.4;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xMin) length:CPTDecimalFromFloat(xMax)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(self.yMax)];
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.65f)];
plotSpace.yRange = yRange;
I more ore less copied this out of a tutorial and then modified it. In the walk-through, they didn't have labels on the axes -- which they had set at the left and bottom of the screen.
Can anyone explain what is causing these extra lines and how I might disable them? They only appear on my Bar Charts... I have other graphs that use scatter plots without any similar results.
It looks like you have a border on you plotAreaFrame(set by the theme), try removing it after applying the theme:
graph.plotAreaFrame.borderLineStyle = nil;

how to create static line in coreplot

I am trying to make my control lines static so instead of being displayed as part of the graph(the control lines are moving with the graph), they would be displayed like an axis
the app can only scroll horizontally
i'm talking about the two red line and the green line(which i put over the x axis)
this is how i do my lines:
// Center line
CPTScatterPlot *centerLinePlot = [[CPTScatterPlot alloc] init];
centerLinePlot.identifier = kCenterLine;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth = 2.0;
lineStyle.lineColor = [CPTColor greenColor];
centerLinePlot.dataLineStyle = lineStyle;
centerLinePlot.dataSource = self;
[graph addPlot:centerLinePlot];
but maybe it has something to do with the displayed range:
////////ajuste la portion a voir
if(data.Resultats.count>10)
{
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(data.Resultats.count - 10) length:CPTDecimalFromDouble(10)];
}
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(RangeMin) length:CPTDecimalFromDouble(RangeMax-RangeMin)];
// Adjust visible ranges so plot symbols along the edges are not clipped
CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
//place l'axe x sur la ligne de controle pour voir les WorkOrders
x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(center);
//x.orthogonalCoordinateDecimal = yRange.location;
//y.orthogonalCoordinateDecimal = xRange.location;
//x.visibleRange = xRange;
//y.visibleRange = yRange;
//x.gridLinesRange = yRange;
//y.gridLinesRange = xRange;
[xRange expandRangeByFactor:CPTDecimalFromDouble(1.15)];//1.05
[yRange expandRangeByFactor:CPTDecimalFromDouble(1.15)];
plotSpace.xRange = xRange;
plotSpace.yRange = yRange;
If there's a limit on how far the main plot can scroll, just set the end points of the control lines outside that range. Core Plot will only draw the visible portion.
Another way to do this would be to add a second plot space to the graph. Add the control plots to this plot space instead of the default one. Set the globalXRange and globalYRange on it so it can't scroll.

How do remove the border around a core-plot graph

I am trying to remove the border around a core plot graph on the iPhone - but seem to be struggling on what should be simple in my mind.
Pointers please!
You should be able to nil out the borderLineStyle on the graph's plotArea to remove the border:
graph.plotAreaFrame.borderLineStyle = nil; // don't draw a border
You could also create your own theme, using the ones in the framework as examples, and simply not set the borderLineStyle in that.
None of the answers worked for me. This did the job:
graph.paddingLeft = 0;
graph.paddingRight = 0;
graph.paddingTop = 0;
graph.paddingBottom = 0;
graph.plotAreaFrame.borderWidth = 0;
graph.plotAreaFrame.cornerRadius = 0;
OK I found out how to do it - quite simple really!
CPLineStyle *borderLineStyle = [CPLineStyle lineStyle];
borderLineStyle.lineColor = [CPColor whiteColor];
borderLineStyle.lineWidth = 1.0;
graph.plotArea.borderLineStyle = borderLineStyle;
where graph is your graph object - the reason I had a border in the first place was because I used CPPlainWhiteTheme.
Hope this helps others - is there a better way?
You can set any line style to nil. This will cause the line to not be drawn at all.
In CorePlot 1.0, the structure of CPTGraph has changed slightly. The code for removing the border line of a graph, assuming that graph is of type GPTGraph or a subclass of CPTGraph, is
graph.plotAreaFrame.borderLineStyle = nil;
The correct way with borderLineStyle = nil after applyTheme:
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
// Set padding for plot area
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
graph.plotAreaFrame.borderLineStyle = nil;
If, like me, you are looking to not just remove the border line, but to make a plot that takes up the entire hosting view, the answer from Thomas Johannesmeyer got me on the right track.
Here's what I did:
CPTGraphHostingView* hostingView = [[CPTGraphHostingView alloc] initWithFrame: frame];
CGRect bounds = hostingView.bounds;
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds];
hostingView.hostedGraph = graph;
graph.paddingTop = CPTFloat(0.0);
graph.paddingRight = CPTFloat(0.0);
graph.paddingBottom = CPTFloat(0.0);
graph.paddingLeft = CPTFloat(0.0);
graph.plotAreaFrame.paddingTop = CPTFloat(0.0);
graph.plotAreaFrame.paddingRight = CPTFloat(0.0);
graph.plotAreaFrame.paddingBottom = CPTFloat(0.0);
graph.plotAreaFrame.paddingLeft = CPTFloat(0.0);
graph.plotAreaFrame.masksToBorder = NO;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.title = nil;
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.title = nil;

Why won't my x-axis show with core-plot on the iPhone?

EDIT: I think my question is better phrased as: How can I have a Y-axis that doesn't start at zero? It seems like the x-axis always gets placed at the y=0, but I would like the x-axis to be at some positive number on the y-axis.
Here's a graph with more regular data... I just wish the x-axis was placed at the minimum y-value for the plot (about 77), instead of at 0.
Here is the function I use to create the graph.
It's a whole bunch of code, and I'm not quite sure which piece might be off to not display the x-axis.
Could the x-axis not showing have something to do with my data?
- (void) showGraph:(SavedDetailScreen*)dataSource {
// create the graph and add it to the view
CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame: CGRectZero];
graph.plotArea.masksToBorder = NO;
CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 280, 240)];
[self addSubview:graphView];
graphView.hostedLayer = graph;
graph.paddingLeft = 50.0;
graph.paddingTop = 20.0;
graph.paddingRight = 10.0;
graph.paddingBottom = 40.0;
// set up the ranges for the graph axis
float minElevation = dataSource.track.tbStats.minAlt;
float maxElevation = dataSource.track.tbStats.maxAlt-dataSource.track.tbStats.minAlt;
float minDistance = 0.0f;
float maxDistance = dataSource.track.tbStats.totalDistance;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minDistance)
length:CPDecimalFromFloat(maxDistance)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minElevation)
length:CPDecimalFromFloat(maxElevation)];
// style the graph with white text and lines
CPTextStyle *whiteText = [CPTextStyle textStyle];
whiteText.color = [CPColor whiteColor];
CPLineStyle *whiteStyle = [CPLineStyle lineStyle];
whiteStyle.lineColor = [CPColor whiteColor];
whiteStyle.lineWidth = 2.0f;
// set up the axis
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x = axisSet.xAxis;
CPXYAxis *y = axisSet.yAxis;
x.majorIntervalLength = CPDecimalFromFloat(maxDistance/10.0f);
x.minorTicksPerInterval = 0;
x.majorTickLineStyle = whiteStyle;
x.minorTickLineStyle = whiteStyle;
x.axisLineStyle = whiteStyle;
x.minorTickLength = 5.0f;
x.majorTickLength = 10.0f;
x.labelOffset = 3.0f;
x.labelTextStyle = whiteText;
y.majorIntervalLength = CPDecimalFromFloat(maxElevation/5.0f);
y.minorTicksPerInterval = 0;
y.majorTickLineStyle = whiteStyle;
y.minorTickLineStyle = whiteStyle;
y.axisLineStyle = whiteStyle;
y.minorTickLength = 5.0f;
y.majorTickLength = 10.0f;
y.labelOffset = 3.0f;
y.labelTextStyle = whiteText;
CPScatterPlot *plot = [[[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
plot.dataLineStyle.lineWidth = 2.0f;
plot.dataLineStyle.lineColor = [CPColor blueColor];
plot.dataSource = dataSource;
[graph addPlot:plot];
CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
plot.plotSymbol = greenCirclePlotSymbol;
}
I've had the same problem yesterday/today and the solution seems to be using the orthogonalCoordinateDecimal property on the axis. For example:
graph.axisSet.xAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(minHeight);
You set the position of an axis on the orthogonal axis using the constantCoordinateValue property of the axis. Just set that property on the x axis to a positive value of y, and the axis should move up.
https://github.com/djw/core-plot/tree/9282845bddbb8c40ff314bbfa158beff797c91f7/examples
This states that the isFloatingAxis property has been removed from at least version 0.9.
I also found this in the discussion group as well http://code.google.com/p/core-plot/issues/detail?id=125
After some hunting, it looks like the new way to float an axis looks like this:
x.axisConstraints = [CPTConstraints constraintWithUpperOffset:132];
this framework really needs a better way to configure itself. I don't see any problem jumping out. Maybe just try simplifying the method to the point where debugging becomes manageable. Check the data that you are passing in to make sure it is what you expect it to be. Better yet, create some dummy data that you know will produce the plot you expect.