Weird border on Core Plot Pie Chart - ios

Why is Core Plot drawing these two lines?
This is how I'm setting up the graph:
// setup the pie chart
graph = [[CPTXYGraph alloc] initWithFrame:[_pieView bounds]];
[_pieView setHostedGraph:graph];
CPTPieChart *pieChart = [[CPTPieChart alloc] init];
[pieChart setDataSource:self];
[pieChart setPieRadius:75.0];
[pieChart setIdentifier:#"PieChart1"];
[pieChart setStartAngle:M_PI_4];
[pieChart setSliceDirection:CPTPieDirectionClockwise];
[graph addPlot:pieChart];
(_pieView is the CPTGraphHostingView*)
How do I remove the two black lines? I tried doing what's described in How do remove the border around a core-plot graph, to no avail.

That's not a border—it's the default axes that come with a CPTXYGraph. It's one line of code to remove them:
graph.axisSet = nil;

Related

Scrolling through data only in core plot iOS

Currently I'm using core plot cocoa pod to draw a scatter graph, currently I need scrolling to be enabled but at the same time I need the x & y axis the be fixed on the corner of the screen and only move through data any way to do this ?.
My current implementation for the following code makes me scrolls through data but x-axis or y-axis disappears when I scroll far through the graph
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
CPTGraphHostingView* hostView = [[CPTGraphHostingView alloc] initWithFrame:self.view.frame];
[self.view addSubview: hostView];
// Create a CPTGraph object and add to hostView
CPTGraph* graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
hostView.hostedGraph = graph;
// Get the (default) plotspace from the graph so we can set its x/y ranges
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction=YES;
// Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !!
[plotSpace setYRange:[CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:10]]];
[plotSpace setXRange:[CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:10]]];
plotSpace.delegate = self;
graph.paddingLeft = 10.0;
graph.paddingRight = 10.0;
graph.paddingTop = 10.0;
graph.paddingBottom = 10.0;
// Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...)
CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];
// Let's keep it simple and let this class act as datasource (therefore we implemtn <CPTPlotDataSource>)
plot.dataSource = self;
// Finally, add the created plot to the default plot space of the CPTGraph object we created before
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
}
Thanks in advance :)
Use the axisConstraints:
x.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0.0];
y.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0.0];
Use 0.0 to place the axis to the left (y-axis) or bottom (x-axis). Use 1.0 to place the axis to the right (y-axis) or top (x-axis). Any fraction between 0.0 and 1.0 is valid.

Enable zoom and pan in Coreplot for CPTPieChart

CPTPieChart *pieChart = [[CPTPieChart alloc] init];
pieChart.plotSpace.delegate = self;
pieChart.plotSpace.allowsUserInteraction=YES;
pieChart.labelOffset=-50;
pieChart.dataSource = self;
pieChart.delegate = self;
pieChart.pieRadius = (self.hostView.bounds.size.height * 0.4) / 2;
pieChart.pieInnerRadius=pieChart.pieRadius/2;
pieChart.identifier = graph.title;
pieChart.startAngle = M_PI_4;
pieChart.sliceDirection = CPTPieDirectionClockwise;
enabled the userinteraction in plot space my delegate are getting called but the piechart is not zooming and panning.
Get reference to graph
CPTGraph *graph = self.hostView.hostedGraph;
self.hostView.allowPinchScaling=YES;
Pie charts don't support pinch-zoom (see issue #15) or panning. I haven't tried it, but you should be able to use the plot space delegate to adjust the center and/or radius of the plot.

Core Plot extremely slow on iOS?

I am having issues with a simple X/Y scatter plot with Core Plot 2.0 on iOS 7.1
The following plot code:
CPTGraphHostingView* graphHostView;
CPTXYGraph* graph;
CPTScatterPlot* plot;
CPTXYPlotSpace* plotSpace;
DebugLog(#"Initializing GRAPH HOST VIEW");
graphHostView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
[self addSubview: graphHostView];
// Create a CPTGraph object and add to hostView
graph = [[CPTXYGraph alloc] initWithFrame:graphHostView.bounds];
graphHostView.hostedGraph = graph;
// Get the (default) plotspace from the graph so we can set its x/y ranges
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
// Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !!
[plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( 0 ) length:CPTDecimalFromFloat( 20000 )]];
[plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( 0 ) length:CPTDecimalFromFloat( 6 )]];
// Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...)
plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];
plot.dataSource = dataSource;
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
takes just about 60 seconds to complete grinding at 100% CPU usage, and allocating steadily up to 300 MB RAM. What could be up? The graph is being hosted in a "parent" UIView.
I have used Core Plot before, and while it seemed slow, this is clearly totally unacceptably slow! What could be the cause of this?
I solved this by using dispatch_async when updating my graph. For example, in my code i Used:
dispatch_async(dispatch_get_main_queue(), ^{
[self setupGraph];
});
I hope this helps.

Draw Multiple Piecharts using coreplot

How to draw multiple pie charts using coreplot.Is it possible to draw these side by side?
Regards,
krishna
Yes, Krishna. You can add the multiple pie charts to the same graph like this:
CPTGraphHostingView *hostingView = (CPTGraphHostingView *) self;
CPTXYGraph *graph;
// set up the graph parameters
...
...
hostingView.hostedGraph = graph;
// Pie chart 1
CPTPieChart *pieChart1 = [[CPTPieChart alloc] init];
// Pie Chart 2
CPTPieChart *pieChart2 = [[CPTPieChart alloc] init];
// Add them to the graph
[graph addPlot:pieChart1];
[graph addPlot:pieChart2];

core plot help to draw two plots together

How to draw both bar and scatter plot together? I have created object of both in viewDidLoad and the datasource also read correctly. I add it to the same plotspace. But no use!
Have you looked at the example programs? Many of them show how to add multiple plots (of the same or different types) to a single graph.
What are you seeing? Does either plot show up, or neither of them?
Just add multiple plots to graph with graph addPlot
CPTScatterPlot * sPlot = [[CPTScatterPlot alloc] init];
dataLineStyle = [CPTMutableLineStyle lineStyle];
sPlot.identifier = #"SomeIdentifier"
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
sPlot.dataLineStyle = dataLineStyle;
sPlot.dataSource = self;
greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor redColor]];
greenCirclePlotSymbol.size = CGSizeMake(5.0, 5.0);
sPlot.plotSymbol = greenCirclePlotSymbol;
[graph addPlot:sPlot];

Resources