Draw majorGridLine Sactter Plot - CorePlot - ios5

I'm trying draw my line chart. But i cant drawn majorgridline.
When i custom x axis label, all majorgridline not show. And how to hid y axis lable.
Here is my line chart:
enter link description here
help me draw it like:
enter link description here
MajorGridLine
custome xaxis lable, and hide yaxis lable.
Thank.
Here is my code:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect bounds = layerHostingView.bounds;
// Create the graph and assign the hosting view.
graph = [[CPTXYGraph alloc] initWithFrame:bounds];
layerHostingView.hostedGraph = graph;
[graph applyTheme:theme];
graph.plotAreaFrame.masksToBorder = NO;
// chang the chart layer orders so the axis line is on top of the bar in the chart.
NSArray *chartLayers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:CPTGraphLayerTypePlots],
[NSNumber numberWithInt:CPTGraphLayerTypeMajorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeMinorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLabels],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisTitles],
nil];
graph.topDownLayerOrder = chartLayers;
[chartLayers release];
// Add plot space for horizontal bar charts
graph.paddingLeft = 50.0;
graph.paddingTop = 25.0;
graph.paddingRight = 50.0;
graph.paddingBottom = 60.0;
// Setup plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(7)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(1000)];
// Setup grid line style
CPTMutableLineStyle *majorXGridLineStyle = [CPTMutableLineStyle lineStyle];
majorXGridLineStyle.lineWidth = 1.0f;
majorXGridLineStyle.dashPattern = CPTLinearBlendingMode;
majorXGridLineStyle.lineColor = [CPTColor colorWithComponentRed:64/255.0 green:177/255.0 blue:219/255.0 alpha:1.0];
// Setup x-Axis.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorGridLineStyle = majorXGridLineStyle;
x.preferredNumberOfMajorTicks = 7;
x.majorIntervalLength = CPTDecimalFromString(#"1");
x.minorTicksPerInterval = 1;
x.labelRotation = M_PI/4;
x.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(-7.0f)];
x.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(-7.0f)];
x.labelingPolicy = CPTAxisLabelingPolicyNone;
NSMutableArray *labels = [[NSMutableArray alloc] initWithCapacity:[xAxisWeek count]];
int idx = 0;
for (NSString *week in xAxisWeek)
{
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:week textStyle:x.labelTextStyle];
label.tickLocation = CPTDecimalFromInt(idx);
label.offset = 5.0f;
label.rotation = M_PI/4;
[labels addObject:label];
[label release];
idx--;
}
x.axisLabels = [NSSet setWithArray:labels];
[labels release];
// Setup y-Axis.
CPTMutableLineStyle *majorYGridLineStyle = [CPTMutableLineStyle lineStyle];
majorYGridLineStyle.lineWidth = 1.0f;
majorYGridLineStyle.dashPattern = CPTLinearBlendingMode;
majorYGridLineStyle.lineColor = [CPTColor colorWithComponentRed:87/255.0 green:142/255.0 blue:242/255.0 alpha:1.0];
CPTXYAxis *y = axisSet.yAxis;
y.majorGridLineStyle = majorYGridLineStyle;
y.majorIntervalLength = CPTDecimalFromString(#"200");
y.minorTicksPerInterval = 1;
y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(1000.0f)];
y.gridLinesRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(-1000.0f)];

Don't set the visibleRange or gridLinesRange for either axis. The default values will make the axis and grid lines extend across the plot area, which is what is shown in your second image.
If you do need to use those properties (e.g., to let the plot symbols hang outside the grid), set both to the same range.

Related

scatter plot Highlighted points using Core-plot in iphone

My code is below:
- (void)viewDidLoad
{
[super viewDidLoad];
[self generateDataSamples];
CPTGraphHostingView *hostingview=[[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:hostingview];
graph=[[CPTXYGraph alloc] initWithFrame:self.view.bounds];
hostingview.hostedGraph =graph;
// Border
graph.plotAreaFrame.borderLineStyle = nil;
graph.plotAreaFrame.cornerRadius = 0.0f;
// Paddings
graph.paddingLeft = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingBottom = 0.0f;
graph.plotAreaFrame.paddingLeft = 70.0;
graph.plotAreaFrame.paddingTop = 20.0;
graph.plotAreaFrame.paddingRight = 20.0;
graph.plotAreaFrame.paddingBottom = 80.0;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = NO;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(7.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(50.0)];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPTDecimalFromString(#"1.0");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0.0");
x.minorTicksPerInterval =9;
// x.majorGridLineStyle = majorGridLineStyle;
// x.minorGridLineStyle = minorGridLineStyle;
x.title = #"X Axis";
x.titleOffset = 30.0;
x.titleLocation = CPTDecimalFromString(#"1.25");
// Label y with an automatic label policy.
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0.0");
y.minorTicksPerInterval =9;
y.preferredNumberOfMajorTicks = 8;
//y.majorGridLineStyle = majorGridLineStyle;
// y.minorGridLineStyle = minorGridLineStyle;
y.labelOffset = 10.0;
y.title = #"Y Axis";
y.titleOffset = 30.0;
y.titleLocation = CPTDecimalFromString(#"1.0");
// Set axes
graph.axisSet.axes = [NSArray arrayWithObjects:x, y, nil];
CPTScatterPlot *datasourceLinePlot =[[CPTScatterPlot alloc] init];
datasourceLinePlot.dataSource =self;
[graph addPlot:datasourceLinePlot];
[datasourceLinePlot release];
[graph release];
[hostingview release];
}
This code generate Scatter-plot using Core-plot library in iphone ...!
Code is Working Perfectly below output.
but i am try highlight points no idea....!
I want Highlight x and y value points like dot....!
Help Me with us...!
You can use a plot symbol and add this to your line plot.
Objective-C
CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
plotSymbol.size = CGSizeMake(10.0, 10.0);
datasourceLinePlot.plotSymbol = plotSymbol;
Swift
let plotSymbol = CPTPlotSymbol.ellipse()
plotSymbol.fill = CPTFill(color: CPTColor.white())
plotSymbol.size = CGSize(width: 10.0, height: 10.0)
datasourceLinePlot.plotSymbol = plotSymbol

CorePlot - Set y-Axis range to include all data points

I have implemented a CorePlot graph in my iOS application, however I am unable to dynamically size the y-Axis based on the data points in the set. Some datasets range from 10-50, while others would range from 400-500. In both cases, I would like to have y-origin (0) visible.
I have tried using the scaletofitplots method:
[graph.defaultPlotSpace scaleToFitPlots:[graph allPlots]];
but this has no effect on the graphs, they still show the default Y-Axis range of 0 to 1.
The only way that I can change the y-Axis is to do it manually via this:
graph.defaultPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)) length:CPTDecimalFromFloat(500.0f)];
however this doesn't work well for graphs with smaller ranges (10-50), as you can imagine.
Is there any method to retrieve the highest y-value from my dataset so that I can manually set the maximum y-Axis to that value? Or is there a better alternative?
EDIT : Here's the file I am using:
#import "TUTSimpleScatterPlot.h"
#implementation TUTSimpleScatterPlot
#synthesize hostingView = _hostingView;
#synthesize graph = _graph;
#synthesize graphData = _graphData;
-(id)initWithHostingView:(CPTGraphHostingView *)hostingView andData:(NSMutableArray *)data {
self = [super init];
if (self != nil) {
self.hostingView = hostingView;
self.graphData = data;
self.graph = nil;
}
return self;
}
-(void)initialisePlot {
if ((self.hostingView == nil) || (self.graphData == nil)) {
NSLog(#"TUTSimpleScatterPlot: Cannot Initialise plot with hosting view and data");
return;
}
if (self.graph != nil) {
NSLog(#"TUTSimpleScatterPlot: Graph Object already exists.");
}
NSDate *refDate = [NSDate date];
NSTimeInterval oneDay = 24 * 60 * 60;
CGRect frame = [self.hostingView bounds];
self.graph = [[CPTXYGraph alloc] initWithFrame:frame];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
self.graph.plotAreaFrame.paddingBottom = 20.0f;
self.graph.plotAreaFrame.paddingLeft = 35.0f;
self.hostingView.hostedGraph = self.graph;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor whiteColor];
lineStyle.lineWidth = 2.0f;
CPTMutableLineStyle *lineStyleThin = [CPTMutableLineStyle lineStyle];
lineStyleThin.lineColor = [CPTColor whiteColor];
lineStyleThin.lineWidth = 1.0f;
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.fontName = #"HelveticaNeue-Medium";
textStyle.fontSize = 10;
textStyle.color = [CPTColor whiteColor];
CPTMutableLineStyle *plotSymbolLineStyle = [CPTMutableLineStyle lineStyle];
plotSymbolLineStyle.lineColor = [CPTColor whiteColor];
plotSymbolLineStyle.lineWidth = 1.0f;
CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.lineStyle = plotSymbolLineStyle;
plotSymbol.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.4 green:0.6 blue:0.8 alpha:1.0]];
plotSymbol.size = CGSizeMake(8.0, 8.0);
CPTScatterPlot *plot = [[CPTScatterPlot alloc] init];
plot.dataSource = self;
plot.identifier = #"mainPlot";
[plotSpace scaleToFitPlots:[graph allPlots]];
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[yRange expandRangeByFactor:CPTDecimalFromDouble(615)];
plotSpace.yRange = yRange;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(oneDay - (oneDay * 6.3f)) length:CPTDecimalFromFloat(oneDay * 6.6f)];
plotSpace.allowsUserInteraction = YES;
CPTPlotRange *globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(615.0f)];
plotSpace.globalYRange = globalYRange;
// Modify the graph's axis with a label, line style, etc
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.xAxis.labelOffset = 1.0f;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(oneDay*1);
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0.0");
axisSet.xAxis.minorTicksPerInterval = 0;
axisSet.xAxis.majorTickLength = 0.0f;
axisSet.xAxis.majorGridLineStyle = majorGridLineStyle;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd MMM"];
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = refDate;
axisSet.xAxis.labelFormatter = timeFormatter;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyleThin;
axisSet.yAxis.labelTextStyle = textStyle;
axisSet.yAxis.labelOffset = 3.0f;
axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(#"50.0");
axisSet.yAxis.minorTicksPerInterval = 1;
axisSet.yAxis.minorTickLength = 3.0;
axisSet.yAxis.majorTickLength = 5.0;
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0);
axisSet.yAxis.majorGridLineStyle = majorGridLineStyle;
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
CPTMutableLineStyle *theLineStyle = [CPTMutableLineStyle lineStyle];
theLineStyle.lineColor = [CPTColor colorWithComponentRed:0.3 green:0.6 blue:0.9 alpha:1.0];
theLineStyle.lineWidth = 2.0f;
plot.dataLineStyle = theLineStyle;
plot.plotSymbol = plotSymbol;
[self.graph addPlot:plot];
}
It looks like you're using -scaleToFitPlots: correctly. This method will update the plot data if needed. Make sure the proper data is available to the datasource before you call it.
Edit based on the new code:
-scaleToFitPlots: is being called before you add the plot to the graph. Therefore the -allPlots array is empty and there is nothing to scale. Move the scaling operation after the plot is built and added to the graph.

How to set Y axis range when using multiple graphs in Coreplot

I'm using coreplot for plotting two graphs in one view. The data that is being plotted changes when a user choses to receive different kinds of data.
The data I receive is being plotted properly. However I'd like to change the range of one of the Y axis when it needs to. (The data could differ from 0 to 40 or from 0.0 to 1.0).
How can I implement this function so that when a user plots data from 0.0 to 1.0 the y-axis it's range also changes to these values
Here's a snippit of my code:
- (void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme fromGraph:(int)graphNumber
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect bounds = layerHostingView.bounds;
layerHostingView.backgroundColor = [UIColor clearColor];
// Create the graph and assign the hosting view.
graph = [[CPTXYGraph alloc] initWithFrame:bounds];
layerHostingView.hostedGraph = graph;
[graph applyTheme:theme];
graph.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
graph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
graph.plotAreaFrame.borderLineStyle = nil;
graph.plotAreaFrame.masksToBorder = NO;
// chang the chart layer orders so the axis line is on top of the bar in the chart.
NSArray *chartLayers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:CPTGraphLayerTypePlots],
[NSNumber numberWithInt:CPTGraphLayerTypeMajorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeMinorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLabels],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisTitles],
nil];
graph.topDownLayerOrder = chartLayers;
[chartLayers release];
// Add plot space for horizontal bar charts
graph.paddingLeft = 45.0;
graph.paddingTop = 40.0;
graph.paddingRight = 45.0;
graph.paddingBottom = 60.0;
// Setup plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(28.0f)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(45)];
CPTScatterPlot *highPlot2 = [[[CPTScatterPlot alloc] init] autorelease];
highPlot2.identifier = #"Graph2";
CPTMutableLineStyle *highLineStyle2 = [[highPlot2.dataLineStyle mutableCopy] autorelease];
highLineStyle2.lineWidth = 1.f;
highLineStyle2.lineColor = [CPTColor colorWithComponentRed:0.00f green:0.00f blue:0.00f alpha:0.0f];
highPlot2.dataLineStyle = highLineStyle2;
highPlot2.dataSource = self;
CPTFill *areaFill2 = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.00f green:0.92f blue:0.0f alpha:0.58f]];
highPlot2.areaFill = areaFill2;
highPlot2.shadow = Shadow;
highPlot2.areaBaseValue = CPTDecimalFromString(#"0");
[graph addPlot:highPlot2];
// Setup grid line style
CPTMutableLineStyle *majorXGridLineStyle = [CPTMutableLineStyle lineStyle];
majorXGridLineStyle.lineWidth = 1.0f;
majorXGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.60f];
CPTMutableTextStyle *TextStyleBlack = [CPTMutableTextStyle textStyle];
TextStyleBlack.color = [CPTColor blackColor];
TextStyleBlack.fontSize = 15.0;
// Setup x-Axis.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.majorGridLineStyle = majorXGridLineStyle;
x.majorIntervalLength = CPTDecimalFromString(#"1");
x.minorTicksPerInterval = 1;
x.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0");
x.title = #"Days";
x.timeOffset = 30.0f;
NSArray *exclusionRanges = [NSArray arrayWithObjects:[CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(0)], nil];
x.labelExclusionRanges = exclusionRanges;
NSMutableArray *labels = [[NSMutableArray alloc] initWithCapacity:[sampleDays count]];
int idx = 0;
for (NSString *day in sampleDays)
{
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:day textStyle:x.labelTextStyle];
label.tickLocation = CPTDecimalFromInt(idx);
label.offset = 5.0f;
[labels addObject:label];
[label release];
idx++;
}
x.axisLabels = [NSSet setWithArray:labels];
[labels release];
// Setup y-Axis.
CPTMutableLineStyle *majorYGridLineStyle = [CPTMutableLineStyle lineStyle];
majorYGridLineStyle.lineWidth = 1.0f;
majorYGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.60];
CPTXYAxis *y1 = axisSet.yAxis;
y1.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:#"10"]decimalValue];
y1.labelShadow = Shadow;
y1.minorTicksPerInterval = 0;
y1.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0");
y1.labelTextStyle = TextStyleYellow;
y1.labelOffset = 15;
y1.axisLineStyle = nil;
NSArray *yExlusionRanges = [NSArray arrayWithObjects:
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(0)],
nil];
y1.labelExclusionRanges = yExlusionRanges;
//setup second y axis
CPTXYAxis *y2 = [[(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero] autorelease];
y2.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y2.orthogonalCoordinateDecimal = CPTDecimalFromString(#"27");
y2.minorTicksPerInterval = 0;
y2.preferredNumberOfMajorTicks = 4;
y2.majorGridLineStyle = majorYGridLineStyle;
y2.labelOffset = - 40.0;
y2.coordinate = CPTCoordinateY;
y2.plotSpace = graph.defaultPlotSpace;
y2.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:#"10"]decimalValue];
y2.minorTickLineStyle = nil;
y2.axisLineStyle = nil;
//add all axis to the graph
graph.axisSet.axes = [NSArray arrayWithObjects:x, y1, y2,nil];
// Create a high plot area
CPTScatterPlot *highPlot = [[[CPTScatterPlot alloc] init] autorelease];
highPlot.identifier = kHighPlot;
CPTMutableLineStyle *highLineStyle = [[highPlot.dataLineStyle mutableCopy] autorelease];
highLineStyle.lineWidth = 1.f;
highLineStyle.lineColor = [CPTColor colorWithComponentRed:0.00f green:0.00f blue:0.00f alpha:0.0f];
highPlot.dataLineStyle = highLineStyle;
highPlot.dataSource = self;
//fillcolor
CPTFill *areaFill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:1.00f green:0.97f blue:0.0f alpha:0.41f]];
highPlot.areaFill = areaFill;
highPlot.shadow = Shadow;
highPlot.areaBaseValue = CPTDecimalFromString(#"0");
[graph addPlot:highPlot];
// Create the Savings Marker Plot
selectedCoordination = 2;
touchPlot = [[[CPTScatterPlot alloc] initWithFrame:CGRectNull] autorelease];
touchPlot.identifier = kLinePlot;
touchPlot.dataSource = self;
touchPlot.delegate = self;
[self applyTouchPlotColor];
[graph addPlot:touchPlot];
[pool drain];
}
EDIT:
The solution came out to:
A. remove the graph.defaultPlotSpace before initializing the plotspaces.
B. adding both plotspaces
[graph addPlotSpace:plotSpace2];
[graph addPlotSpace:plotSpace];
C. asign both plots to it's own plotspace
[graph addPlot:highPlot toPlotSpace:plotSpace];
[graph addPlot:highPlot2 toPlotSpace:plotSpace2];
The plot ranges are part of the plot space. Just update the yRange whenever you want to change the displayed range. You can do this any time, not just when setting up the graph.

Core plot x-axis labels are not shown

This is my code. X-Axis labels are not shown. I am using core plot.
scatterGraph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
CPTheme *theme = nil;
[scatterGraph applyTheme:theme];
hostView.hostedGraph = scatterGraph;
hostView.backgroundColor = [UIColor clearColor];
hostView.collapsesLayers = NO;
scatterGraph.paddingTop = 25.0;
scatterGraph.paddingRight = 25.0;
scatterGraph.paddingLeft = 25.0;
scatterGraph.paddingBottom = 25;
scatterGraph.plotAreaFrame.masksToBorder = NO;
CPXYPlotSpace *scatterPlot = (CPXYPlotSpace *) scatterGraph.defaultPlotSpace;
scatterPlot.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromInt(yCount)];
float xx = [self findMax:LivePriceFeedArray] - [self findMin:LivePriceFeedArray]+1.0;
scatterPlot.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat([self findMin:LivePriceFeedArray]-0.5) length:CPDecimalFromFloat(xx)];
CPXYAxisSet *axisSet =(CPXYAxisSet *) scatterGraph.axisSet;
CPXYAxis *xAxis = axisSet.xAxis;
axisSet.delegate = self;
xAxis.title = #"Days";
xAxis.titleLocation = CPDecimalFromFloat(4.0f);
xAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(0.0f);
xAxis.majorIntervalLength = CPDecimalFromFloat(5.0f);
xAxis.labelingPolicy = CPAxisLabelingPolicyNone;
NSUInteger labelLocation = 0;
NSMutableArray *customArray = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *i in customLocations) {
CPAxisLabel *iLabel = [[CPAxisLabel alloc] initWithText:[xAxisLabels objectAtIndex:labelLocation++] textStyle:xAxis.labelTextStyle];
iLabel.tickLocation = [i decimalValue];
[customArray addObject:iLabel];
[iLabel release];
}
xAxis.axisLabels = [NSSet setWithArray:customArray];
xAxis.majorTickLocations = [NSSet setWithArray:customLocations ];
CPLineStyle *majorGridLineStyle = [CPLineStyle lineStyle];
xAxis.majorGridLineStyle = [CPLineStyle lineStyle];
CPXYAxis *yAxis = axisSet.yAxis;
yAxis.title = #"Sales Target";
yAxis.majorIntervalLength = CPDecimalFromFloat(1.0f);
yAxis.labelOffset = -5.0f;
yAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(0.0f);
CPScatterPlot *graphPlot = [[[CPScatterPlot alloc]init] autorelease];
CPMutableLineStyle *lineStyle = [[graphPlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 3.0f;
lineStyle.lineColor = [CPColor whiteColor];
graphPlot.dataLineStyle = lineStyle;
graphPlot.dataSource = self;
[scatterGraph addPlot:graphPlot];
graphPlot.backgroundColor = [UIColor clearColor];
CPLineStyle *minorGridLineStyle = majorGridLineStyle;
xAxis.minorGridLineStyle = minorGridLineStyle;
yAxis.majorGridLineStyle = majorGridLineStyle;
yAxis.minorGridLineStyle = minorGridLineStyle;
Why are the x-axis labels not shown?
I solved the issue. There was a problem with orthogonal coordinates.
I solved it like this:
scatterPlot.yRange = [CPPlotRange
plotRangeWithLocation:
CPDecimalFromFloat (min)
length:CPDecimalFromFloat(xx)];
xAxis.orthogonalCoordinateDecimal =
CPDecimalFromFloat(min);
Here plotRangeWithLocation for y-axis and orthogonalCoordinateDecimal for x-axis should be the same.
Thanks for the help, Krishnabhadra :)

grouped bar graph example using core plot iphone?

I want to know how to create grouped bar graph? I tried but I got only single bar graph.
Below, is my code any one tell me what is the mistake .
Thank you
-(void)viewDidLoad {
[super viewDidLoad];
[self generateDataSamples];
double xAxisStart = 0;
double xAxisLength = [samples count];
double yAxisStart = 0;
double yAxisLength = [[samples valueForKeyPath:#"#max.Y_VAL"] doubleValue];
NSLog(#"xAxisLength===%f",xAxisLength);
NSLog(#"yAxisLength===%f",yAxisLength);
CPGraphHostingView *hostingView = [[CPGraphHostingView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:hostingView];
CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame:self.view.bounds];
hostingView.hostedGraph = graph;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(xAxisStart)
length:CPDecimalFromDouble(xAxisLength+1)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(yAxisStart)
length:CPDecimalFromDouble(yAxisLength)];
graph.plotAreaFrame.borderLineStyle = nil;
graph.plotAreaFrame.cornerRadius = 0.0f;
// Paddings
graph.paddingLeft = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingBottom = 0.0f;
graph.plotAreaFrame.paddingLeft = 70.0;
graph.plotAreaFrame.paddingTop = 20.0;
graph.plotAreaFrame.paddingRight = 20.0;
graph.plotAreaFrame.paddingBottom = 80.0;
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *y = axisSet.yAxis;
y.majorIntervalLength = CPDecimalFromString(#"1");
y.orthogonalCoordinateDecimal = CPDecimalFromString(#"0");
y.title = #"Y Axis";
y.titleOffset = 45.0f;
y.titleLocation = CPDecimalFromFloat(3.0f);
//first bar
CPBarPlot *plot = [[CPBarPlot alloc] initWithFrame:CGRectZero];
plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0)
length:CPDecimalFromDouble(xAxisLength)];
CPFill* cpFill = [[CPFill alloc] initWithColor:[CPColor greenColor]];
plot.barOffset = CPDecimalFromFloat(0.25f);
plot.fill = cpFill;
plot.dataSource = self;
plot.identifier=#"plot1";
[graph addPlot:plot toPlotSpace:plotSpace];
//second bar
plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(1.0)
length:CPDecimalFromDouble(xAxisLength)];
CPFill* cpFill1 = [[CPFill alloc] initWithColor:[CPColor lightGrayColor]];
plot.fill = cpFill1;
plot.dataSource = self;
plot.identifier=#"plot2";
[graph addPlot:plot toPlotSpace:plotSpace];
[graph addPlot:plot];
[plot release];
[graph release];
[hostingView release];
}
You never created a second plot object--your code just adds the same one to the graph twice. You also need to make sure to use a different barOffset for the second plot. If you're not using garbage collection, watch your memory management. The code in your question has several memory leaks.