Remove blank space around scatter graph in core plot - ios

I'm using core plot for line graph.in the scatter graph i'm getting some blank space around the scatter graph.as you can see the screen shot(in debug mode) my graph plot area is covered by empty space.How can i remove it?
Initialising host view
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-10)];
self.hostView.backgroundColor = [UIColor clearColor];;
self.hostView.allowPinchScaling = NO;
[self addSubview:self.hostView];
Initializing graph
graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
self.hostView.hostedGraph = graph;
EDIT
graph.plotAreaFrame.PaddingLeft = 55.0f;
graph.plotAreaFrame.PaddingRight = 15.0f;
graph.plotAreaFrame.PaddingTop = 10.0f;
graph.plotAreaFrame.paddingBottom = 28.0;
These are the paddings i have provided.

The graph starts with 20 pixels of padding on each edge but that's easy to change:
graph.PaddingLeft = 0.0;
graph.PaddingTop = 0.0;
graph.PaddingRight = 0.0;
graph.PaddingBottom = 0.0;

Related

CorePlot: unable to change pie chart position (displacement)

I am unable to change the pie chart position (I would like it to be more left in respect to the legend so that the legend does not overlay the pie chart). Basically I would like to shift it towards the left to allow the legend to display.
I tried modifying the following properties (but with no apparent effect on the pie graph position):
// pieChartGraph is a CPTPieChart object
pieChartGraph.graph.position = CGPointMake(-100, 0);
// I also tried:
pieChart.position = CGPointMake(-100, 0);
// and also playing with:
pieChart.anchorPoint
Here is what I get and also my code (by the way, the title does not show either):
pieChartGraph = [[CPTXYGraph alloc] initWithFrame:self.pieChartgraphHostView.bounds];
self.pieChartgraphHostView.hostedGraph = pieChartGraph;
pieChartGraph.plotAreaFrame.masksToBorder = NO;
pieChartGraph.axisSet = nil;
pieChart.title = #"title"; // <-- BTW, the title does not show either
// 2 - Create chart
pieChart = [[CPTPieChart alloc] init];
pieChart.dataSource = self;
pieChart.delegate = self;
pieChart.pieRadius = self.pieChartgraphHostView.bounds.size.width;
pieChartGraph.delegate = self;
pieChart.identifier = pieChartGraph.title;
pieChart.startAngle = CPTFloat(M_PI_4);
pieChart.sliceDirection = CPTPieDirectionClockwise;
pieChart.borderLineStyle = [CPTLineStyle lineStyle];
// 3 - Create gradient
CPTGradient *overlayGradient = [[CPTGradient alloc] init];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.9];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.4] atPosition:1.0];
pieChart.overlayFill = [CPTFill fillWithGradient:overlayGradient];
// 4 - Add chart to graph
pieChart.pieRadius = pieChart.pieRadius / 2.3;
[pieChartGraph addPlot:pieChart];
self.dataForChart = [#[#(self.displayedLastDataPoint.percentageUnder), #(self.displayedLastDataPoint.percentageOver), #(self.displayedLastDataPoint.percentageClean), #(self.displayedLastDataPoint.percentageRemaining)] mutableCopy];
// Add legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:pieChartGraph];
theLegend.numberOfColumns = 1;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.entryFill = [CPTFill fillWithColor:[CPTColor lightGrayColor]];
theLegend.entryBorderLineStyle = [CPTLineStyle lineStyle];
theLegend.entryCornerRadius = CPTFloat(3.0);
theLegend.entryPaddingLeft = CPTFloat(3.0);
theLegend.entryPaddingTop = CPTFloat(3.0);
theLegend.entryPaddingRight = CPTFloat(3.0);
theLegend.entryPaddingBottom = CPTFloat(3.0);
theLegend.cornerRadius = 5.0;
theLegend.delegate = self;
pieChartGraph.legend = theLegend;
pieChartGraph.legendAnchor = CPTRectAnchorRight;
CGFloat legendPadding = +(self.view.bounds.size.width / 16);
pieChartGraph.legendDisplacement = CGPointMake(legendPadding, 0.0);
pieChartGraph.graph.position = CGPointMake(-30, 0);
Set the centerAnchor to position the pie chart within the graph. It is a CGPoint. Both coordinates range between 0 and 1, similar to the anchorPoint of a CALayer.

Black color squared border appear in core plot piechart

CPTXYGraph *graph = [[CPTXYGraph alloc]initWithFrame:self.hostingView.frame];
graph.borderColor = [CPTColor whiteColor].cgColor;
graph.paddingTop = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingLeft = 0.0f;
graph.paddingBottom = 0.0f;
self.hostingView.hostedGraph = graph;
graph.axisSet = nil;
//Apply for theme to graph
self.graphTheme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
[graph applyTheme:self.graphTheme];
[graph release];
CPTPieChart *pieChart = [[CPTPieChart alloc]init];
pieChart.identifier = #"OverView";
pieChart.dataSource = self;
pieChart.sliceDirection = CPTPieDirectionClockwise;
pieChart.pieRadius = ((self.hostingView.frame.size.height / 2) - 5);
pieChart.startAngle = M_PI;
CPTGraph *tempGraph = self.hostingView.hostedGraph;
[tempGraph addPlot:pieChart];
[pieChart release];
For this code i am getting black colored border ,i thought that is due to graph axisSet but i don't how to remove.
If what you're talking about is the border box that appears around the entire graph, I would say use this code after the statement [graph applyTheme:self.graphTheme];:
graph.plotAreaFrame.borderLineStyle = nil;
This removes the border completely from the graph area.

CPTScatterPlot not showing

I am using CPTScatterPlot for showing graphs in iPad. The code runs properly but the points are not plotted on the graph. Not even a single point is shown. Why is it so???
My code is:
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = #"Red Plot";
CPTMutableLineStyle *symbolLineStyle2 = [CPTLineStyle lineStyle];
symbolLineStyle2.lineColor = [CPTColor redColor];
symbolLineStyle2.lineWidth = 5.0;
//symbolLineStyle2.miterLimit = 1.0f;
dataSourceLinePlot.dataLineStyle = symbolLineStyle2;
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];
// Animate in the new plot, as an example
dataSourceLinePlot.opacity = 0.0f;
[graph addPlot:dataSourceLinePlot];
I checked both the delegate methods. Both return proper values but graph is not plotted what could be the reason. Please help...
Remove this line:
dataSourceLinePlot.opacity = 0.0f;

Core plot axis labels not visible outside plot area

I'm having some trouble with the axis labels. It seems my custom labels aren't visible outside of the plot area. Looking at the Design Overview for core plot, the axis labels should be outside of the plot area. Any ideas on how I can make them visible outside the plot area?
The code/image below shows how the labels only show within the plot area. If I change the label offset to a positive number, the labels do not show at all. I'm using Core Plot 0.9 with iOS 5.
Thanks in advance!
CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
graph = [[theme newGraph] retain];;
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
hostingView.hostedGraph = graph;
graph.paddingLeft = 40.0;
graph.paddingTop = 40.0;
graph.paddingRight = 40.0;
graph.paddingBottom = 40.0;
graph.masksToBorder = NO;
// ... setup axis
axisSet.yAxis.majorIntervalLength = CPTDecimalFromInt(0);
axisSet.yAxis.minorTicksPerInterval = 0;
axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
// if this number is negative, the labels show,
// if it is positive, that is outside the plot area, the labels are hidden.
axisSet.yAxis.labelOffset = -20;
// ... setup labels
NSMutableArray *labels = [NSMutableArray array];
for (int i = 0; i < reportData.rowCount; ++i) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:#"Test Row %i", i] textStyle:labelStyle];
label.tickLocation = CPTDecimalFromInt(i);
label.offset = axisSet.yAxis.labelOffset;
label.alignment = CPTAlignmentLeft;
[labels addObject:label];
[label release];
}
axisSet.yAxis.axisLabels = [NSSet setWithArray:labels];
Set some padding on the plot area frame in addition to or instead of the graph itself.
graph.plotAreaFrame.paddingTop = 20.0;
graph.plotAreaFrame.paddingBottom = 50.0;
graph.plotAreaFrame.paddingLeft = 50.0;
graph.plotAreaFrame.paddingRight = 50.0;
This code is from the axis demo in the Plot Gallery example app.
I was having exactly the same problem and tried every solution I could find online for this with no success.
Finally I got it to work by turning off the border masking, like this:
graph.plotAreaFrame.masksToBorder = NO;

upside down x_axis

Am working with coreplot for creating bar-chart .Bar-chart is getting displayed but its upside down..X-axis starts at the top of the screen instead of being at the bottom of the screen..and even X-Axis isn't visible..It looks as if bars in the chart are hanging :(....How do I change its position and make it proper and even make x-Axis visible???
Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
[self generateDataSamples];
double xAxisStart = 0;
double xAxisLength = 14;
double yAxisStart = 0;
// double yAxisLength = [[samples valueForKeyPath:#"#max.Y_VAL"] doubleValue];
double yAxisLength = 190.0;
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+3)];
CPBarPlot *plot = [[CPBarPlot alloc] initWithFrame:CGRectZero];
plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0)
length:CPDecimalFromDouble(xAxisLength-5)];
plot.barOffset = CPDecimalFromDouble(1.5);
plot.dataSource = self;
[graph addPlot:plot];
[plot release];
[graph release];
[hostingView release];
}
Thank U
Add some padding to the plot area frame to make the axes visible:
graph.plotAreaFrame.paddingTop = 20.0;
graph.plotAreaFrame.paddingBottom = 50.0;
graph.plotAreaFrame.paddingLeft = 50.0;
graph.plotAreaFrame.paddingRight = 20.0;
I'm not sure why the graph would appear upside down. Does the hosting view's superview have any transforms applied to it?

Resources