I am plotting graph using core plot. I am trying to plot my graph on plot area, but it contains white background. But I want to plot graph with my own background. This is my code.
// setting frame of graph
CGRect frame = [self.hostingView bounds];
self.graph = [[[CPTXYGraph alloc] initWithFrame:frame] autorelease];
// Add some padding to the graph, with more at the bottom for axis labels.
self.graph.plotAreaFrame.paddingTop = 10.0f;
self.graph.plotAreaFrame.paddingRight = 10.0f;
self.graph.plotAreaFrame.paddingBottom = 25.0f;
self.graph.plotAreaFrame.paddingLeft = 30.0f;
// set background color of plot area by fill property and CPTColor
self.graph.plotAreaFrame.plotArea.fill=[(CPTFill *)[CPTFill alloc] initWithColor: [CPTColor colorWithComponentRed:0.8 green:0.8 blue:0.8 alpha:1.0]];
// add graph to hosting view by hostedGraph property of hostingView
self.hostingView.hostedGraph = self.graph;
In above code I tried to change color but I want to draw horizontal dotted lines for each ticks on y axis.
Set the majorGridLineStyle and/or minorGridLineStyle on the y-axis to draw horizontal lines at the major and minor tick locations, respectively.
Use the dashPattern and patternPhase properties of the line style to make a dotted line. See Apple's Quartz 2D docs for details on how those properties work.
This is my code which i have used for above....
// create an object of CPTMutableLineStyle and set property of it.
CPTMutableLineStyle *dottedStyle=[CPTMutableLineStyle lineStyle];
dottedStyle.dashPattern=[NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1,[NSDecimalNumber numberWithInt:2],nil];
dottedStyle.patternPhase=0.0f;
// set the majorGridLinestyleProperty by this line as.
axisSet.yAxis.majorGridLineStyle=dottedStyle;
Related
I'm using iOS-Charts linechart view to draw lines that have zero circle radius and I would like the user to be able to drop Points on the line. Is there a way to change an individual data points circle radius from zero to 20 by using the delegate chartValueSelected?
I can easily change the entire dataSet circleRadius, but I'm having a hard time figuring out how to do individual data points.
lineChartDataSet2.circleRadius = 0
lineChartDataSet2.circleRadius = 20
I solved this in an application by actually having multiple data sets, the second data set being used only for adding points on the same line but with a given circle radius. I checked with the developers of Charts and there's no other way to achieve it.
I have:
- (void)displayChartWithSet:(LineChartDataSet *)set highlightedSet:(LineChartDataSet *)highlightedSet {
set.drawValuesEnabled = NO;
set.drawCirclesEnabled = YES;
set.circleColors = [NSArray arrayWithObject:[UIColor clearColor]];
set.colors = [NSArray arrayWithObject:[UIColor whiteColor]];
set.lineWidth = 2.0f;
set.mode = LineChartModeHorizontalBezier;
//Builds the data to be presented from two distinct data sets
// one containing only points with a radius
LineChartData *data = [[LineChartData alloc] initWithDataSets:[NSArray arrayWithObjects:set, highlightedSet, nil]];
}
This allows me to add individual points to the highlighted set and then redraw the view when needed, or have a nil set and have no highlighted points. There's a further setup function for the highlighted data set that does the configuration of points.
I have implemented a pie chart on iPhone application by following the Rayenderlich CORE PLOT tutorial for PIE CHART
http://www.raywenderlich.com/13269/how-to-draw-graphs-with-core-plot-part-1
Here i have some issues,
I need to add another data label (Name of project) on the graph,
I tried with implementing another method like
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
in CorePlot.h (i found only once in the application) and method definition in my viewcontroller class,
but extra datalabel doesn't displayed yet.
And i need to move the legend table bellow the graph instead of beside the graph
i tried with frame and legendDisplacement but no result found
Data labels are tied to the plot data, one for each slice in a pie chart. In your example image, "Weekly Report" would be the graph title.
graph.title = #"Weekly Report";
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor whiteColor];
textStyle.fontName = #"Helvetica-Bold";
textStyle.fontSize = 12.0;
graph.titleTextStyle = textStyle;
graph.titleDisplacement = 5.0;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
You can move the legend with the legendAnchor property:
graph.legendAnchor = CPTRectAnchorBottom;
Similar to the titleDisplacement, the legendDisplacement sets the margin between the legend and its anchor point on the graph.
How can I get an image behind my labels within my graph. I succeeded with putting an image in front of the graph with:
CPTPlotSpaceAnnotation *imageAnnotation;
CGRect imageRect = CGRectMake(0, 0 , 480, 320);
CPTBorderedLayer * ImageLayer = [[CPTBorderedLayer alloc] initWithFrame:imageRect];
ImageLayer.fill = [CPTFill fillWithImage:[CPTImage imageWithCGImage:[[UIImage imageNamed:#"Overlay_3_digits.png"] CGImage]]];
imageAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace anchorPlotPoint:nil];
imageAnnotation.contentLayer = ImageLayer;
[graph addAnnotation:imageAnnotation];
[graph addSublayer:ImageLayer];
[newImagelLayer release];
[imageAnnotation release];
adding the image with [graph insertSubLayer:ImageLayer below:y]; didn't worked, this also puts the image in front of the graphs and axislabels. Hope someone can help me out.
EDIT:
I added a screenshot from the simulator. The three black rectangles needs to be in front of my plots and behind my labels. The labels will be readible more easily.
I also editted the hierarchy of layers from my graph by putting the axislabels at the first index:
NSArray *chartLayers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:CPTGraphLayerTypeAxisLabels],
[NSNumber numberWithInt:CPTGraphLayerTypePlots],
[NSNumber numberWithInt:CPTGraphLayerTypeMajorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeMinorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisTitles],
nil];
graph.topDownLayerOrder = chartLayers;
I also found a better way of putting my image inside the graph. I did this by means of a new hostlayer:
CPTAnnotationHostLayer *newHostLayer = [[CPTAnnotationHostLayer alloc]
initWithFrame:CGRectMake(0, 0, 480, 220)];
UIImage * annotationBG = [UIImage imageNamed:#"Overlay_3_digits.png"];
newHostLayer.backgroundColor = [UIColor colorWithPatternImage:annotationBG].CGColor;
Any ideas how I can put the three black triangle image at the back of my labels and in front of the plots?
The -addAnnotation: method takes care of updating the layer tree; you should remove your call to -addSublayer:.
Do you want the image to completely fill the background behind the graph? If so, just set the fill on the graph instead of making an annotation.
graph.fill = [CPTFill fillWithImage:[CPTImage imageWithCGImage:[[UIImage imageNamed:#"Overlay_3_digits.png"] CGImage]]];
To put the box behind each label, you can use custom labels. Build a CPTBorderedLayer the same way you did for the annotation. Add a CPTTextLayer with the label text as a sublayer of the bordered layer. Make the bordered layer the contentLayer of the custom label. This should remove the need to change the topDownLayerOrder, too.
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];
In iPhone App i am using core Plot vertical bar chart.
How to Remove shadow effect in Vertical Bars?
Here as shown in figure bars are displaying with shadow
Here is the code:
CPBarPlot *barPlot = [CPBarPlot tubularBarPlotWithColor:[CPColor colorWithComponentRed:111 green:129 blue:113 alpha:1.0] horizontalBars:NO];
barPlot.shadowColor=NO;
How can I remove this shadow effect?
Please Help and Suggest.
Thanks
Haven't tested this, but my guess is that what you see is not a shadow but a gradient fill generated by the use of "tubularBarPlotWithColor". The shadow is probably something outside the bar borders.
Instead, try creating the bar plot with:
CPBarPlot *barPlot = [[CPBarPlot alloc] init];
Then use:
barPlot.fill = [CPFill fillWithColor:myCPColor];
Or if you actually want a gradient fill:
fillGradient = [CPGradient gradientWithBeginningColor:myCPColorBegin endingColor:myCPColorEnd];
barPlot.fill = [CPFill fillWithGradient:fillGradient];
Hope this helps!
Claes
I faced the white colored plots isssue
yourPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:80.0f / 255.0f green:186.0f / 255.0f blue:224.0f / 255.0f alpha:1.0f]];
this gives me the desired color..