Here is my code:
CPTXYPlotSpace *barGraphPlotSpace = [[CPTXYPlotSpace alloc] init];
barGraphPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPDecimalFromFloat(100.0)];
CPTXYAxis *rightY = [[CPTXYAxis alloc] init];
rightY.coordinate = CPTCoordinateY;
rightY.orthogonalCoordinateDecimal = CPTDecimalFromFloat(oneDay*7);
rightY.plotSpace = barGraphPlotSpace;
[graph addPlotSpace:barGraphPlotSpace];
This doesn't add another axis to my graph though.
What I'm trying to do is get a second y axis which will go from 0-100 (percent). To do this I'm creating a new plot space and a new y axis adding the new plot space to the y axis and adding the plot space to the graph.
What am I doing wrong?
Thank you.
You need to add the new axis to the graph:
NSMutableArray *newAxes = [graph.axisSet.axes mutableCopy];
[newAxes addObject:rightY];
graph.axisSet.axes = newAxes;
[newAxes release];
Related
I using coreplot , and I want to plot two plots ,1) Bar Plot w.r.t Y1 axis 2) Scatter Plot w.r.t Y2 axis, as shown in the below figure with different set of values.
I managed to create the Y2 axis on the right side by the code below,by referring to the code in CorePlotTestApp example.
CPTXYAxis *y2 = [[(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero] autorelease];
//y2.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y2.orthogonalCoordinateDecimal = CPTDecimalFromString(#"10");
y2.minorTicksPerInterval = 1;
y2.preferredNumberOfMajorTicks = 2;
y2.labelOffset = -20.0f;
y2.titleOffset = -23.0f;
y2.coordinate = CPTCoordinateY;
y2.plotSpace = plotSpaceRightYaxis;
y2.axisLineStyle = lineStyle;
y2.majorTickLineStyle = lineStyle;
y2.minorTickLineStyle = lineStyle;
//y2.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(20)];
y2.title = #"Y2Title";
y2.labelTextStyle = textStyle;
y2.titleLocation = CPTDecimalFromInteger(4);
y2.axisConstraints = [CPTConstraints constraintWithUpperOffset:0.0];
graph.axisSet.axes = [NSArray arrayWithObjects:x, y,y2,nil];
I can plot the bar graph and scatter plot but with respect to only Y1 axis on left but I want to plot it with respect to Y2 axis so how should I proceed with this,please help me out, waiting for your reply.
Regards
Ranjit.
I am using CorePlot for the iPhone. I can do a simple graph just fine. But what I'm looking to do is to have the y-axis go from 0-100 and the x-axis go from 1998 - 2007. I'd like to keep this numerical (not custom text based labels) if possible.
The issue, is that when you set up these axis:
// We modify the graph's plot space to setup the axis' min / max values.
float xAxisMin = 1998
float xAxisMax = 2007;
float yAxisMin = 0;
float yAxisMax = 100;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];
// Modify the graph's axis with a label, line style, etc.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.xAxis.title = #"";
axisSet.xAxis.titleTextStyle = textStyle;
axisSet.xAxis.titleOffset = 10.0f;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(1000.0f);
axisSet.xAxis.labelOffset = 1.0f;
axisSet.xAxis.minorTicksPerInterval = 1;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
You get a graph that shows the y-axis at 0 going to 100 then the xaxis starts at about 1998 to the right. i.e. they graph does not cross at X: 1998 y: 0. Is there a way to force it to do so? As far as I can tell I have to do a graph with x-axix range from 0-2007 and y-axis range 0-100. Then can I tell it to cut out the 0-1997 piece and shift so that piece is at 0?
The alternative is to use custom points. Which I tried. But is seems there is a problem where it doesn't show ticks on the graph line. For example if I follow the example in from the source, I can see 1998, 1999, 2000, etc but no | lines cross the x-axis. It's like the tick lines will not draw because I'm using custom lines.
Thanks for any and all help,
-David
Use the orthogonalCoordinateDecimal property:
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(yAxisMin);
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(xAxisMin);
I am working on core-plot. I want to make the graph which drawn in the screen need to be centered. when the application get loaded its showing from the bottom the graph. I want to make the entire view visible from center has shown in below figure.
#Thanks in advance
// Just set the xRange and YRange with initial offset:
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
/* Range which is visible on screen */
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(offset)
length:CPTDecimalFromFloat(X_LENGTH)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(offset_Y)
length:CPTDecimalFromFloat(Y_LENGTH)];
/* Total Range which is visible on screen and can be scrolled up to */
CPTPlotRange *globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble(Y_LENGTH)];
plotSpace.globalYRange = globalYRange;
CPTPlotRange *globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble(xRange)];
plotSpace.globalXRange = globalXRange;
/* To constraint X and Y axis */
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:55.0];
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
How to make a smooth line in CPScatterplot .To make scatterplot like a curve chart.
i use this code
CPScatterPlot.dataSource = self;
CPScatterPlot.dataLineStyle.lineWidth = 3.0f;
For future reference, this feature has now been addressed in Core Plot issue #156. As of 0.9 it has not been merged however a diff is available at http://code.google.com/p/core-plot/issues/detail?id=156
Core Plot only draws straight line segments between your data points. You can insert extra points between your existing data, but you have to calculate the values yourself to get the desired curve. If you insert enough points, it will appear to be a smooth curve.
Try this one May be Helped.
CPScatterPlot *Cps = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds]autorelease];
Cps.identifier = #" ";
Cps.dataLineStyle.lineWidth = 1.0f; // if u want smooth the line
//Cps.dataLineStyle.lineColor = [CPColor blueColor]; // if u want color the line
Cps.dataSource = self;
[graph addPlot:Cps];
I am new to coreplot. I would like to insert a horizontal scroll bar on my application in order to move my graph. I don't know how do to this.
I find some code on internet like this:
-(IBAction)moveLineLocation:(id)sender {
CPPlotRange *rangeX = plotSpace.xRange;
CPPlotRange *rangeY = plotSpace.yRange;
rangeX.location = CPDecimalAdd(rangeX.location, CPDecimalFromFloat(-0.5));
plotSpace.xRange = rangeX;
plotSpace.yRange = rangeY;
[graph.axisSet relabelAxes];
[graph reloadData];
}
But it's not working. Do you have any hint,idea please
Regards
You can make the Graph scroll without scrollbars:
plotSpace.allowsUserInteraction = YES;
plotSpace.globalYRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5f) length:CPDecimalFromFloat(5)];
plotSpace.globalXRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5f) length:CPDecimalFromFloat(5)];
Those ranges are the limits of the scrolling. Make the Y range equal to your graph range to remove scrolling on the Y axis.