Am breaking my head on this since yesterday (tried various attribute settings, goggled, stackoverflow'ed , et al,... in vain). At last, I decided to post this! I hope am not asking anything dumb! Please pardon me if so! :)
My Project Settings:
Simple iPhone App that uses Core Plot, Xcode 4.2, iOS 5.0,
Testing using iOS Simulator
My Question : I used the wonderful and DatePlot example from Core Plot site and am plotting (Scatter Plot) dates along the x-axis. am having two plots. It's all plotted fine (thanks to the simple example!); But the distance between each plot (along the x-axis) i.e. the distance between the major ticks is too small ... it's like this :
(Notice that the two red-colored ellipse-plots are so close to each other...that's the current distance between the ticks)
My Code Snippet (Relevant)
// Set up the axes
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) lineChart.axisSet;
CPTXYAxis *x = axisSet.xAxis;
NSTimeInterval oneDay = 24.0 * 60.0 * 60.0;
x.majorIntervalLength = CPTDecimalFromFloat(oneDay);
x.majorTickLength = 1.0;
// Get a set of custom label for the X Axis
x.axisLabels = [self getXLabelSetForLineChart:x];
x.labelRotation = M_PI / 2;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = today;
x.labelFormatter = timeFormatter;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
Can someone please help!!!
Thanks!
The length of the plot space xRange is too long. This compresses your data points into a smaller area and leaves unused spaces off to the right.
Related
i want to Convert the point which touch to CPTXYPlotSpace point.but i find there have Offset with real coordinates。
I find ,it Calculated part of the x-axis from the border.
i want to get the point mapped to the value of the x&y axis.
my Enlish is poor....
i want to konw where wrong? please tell me .
this is the code.
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point
{ NSDecimal plotPoint[2];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
[plotSpace plotPoint:plotPoint forPlotAreaViewPoint:point];
//HERE HAVE SOME OFFSET. I FIND ,it Calculated part of the x-axis from the border
NSLog(#"touch plotPoint = %d, %f",
[[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPTCoordinateX]] intValue],
[[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPTCoordinateY]] doubleValue]);
return YES;
}
Convert the point to the coordinate system of the plot area first:
CGPoint plotAreaPoint = [graph convertPoint:point toLayer:graph.plotAreaFrame.plotArea];
[plotSpace plotPoint:plotPoint forPlotAreaViewPoint:plotAreaPoint];
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);
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];
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];