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];
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.
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;
I need help with this, please help me. Here is my situation:
This is what I have now. The red plot has value 190. And the yellow plot has 63.3 value. I want to plot the red one above the yellow one. It means the yellow plot has baseValue= 0 and the red plot has baseValue = tip value of the yellow. I used CPTBarPlotFieldBarBase to change the baseValue of the red plot(set barBaseValue= Yes). As my expect, the total value of both plots at that index = 190+63.3=253.3. Unfortunately, the outcome of the total is only 190 which is value of red plot only.
Thus, My question is how can I still display values of plots graph in this format, but the total height of 2 plots at this index must be 253.3(I dont need to display this number). I just want to make the graph height looked right to its value like this one
This plot has total value is 97 which is little below 100.
Please help me. I appreciate the helps.
Core Plot doesn't do the stacking calculations for you. Make the tip value of the red bar 253.3 (190 + 63.3).
Ok just want to share. As Eric pointed out "Make the tip value of the red bar 253.3 (190 + 63.3)", but he didn't mention how. Here is how I did it. First, plot a red bar with value is total of 2 values(red+yellow). Then plot the yellow bar overlap the red one and it has a same the baseValue with the red plot. Here is the trick, when I label te red plot, I used its actual value which is not total value. And here is the func that I used to modify the labels.
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
CPTTextLayer *label;
if (red_plot.identifier){
label = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:#"%#", [_charDataOfRed objectAtIndex:index]]];
}
else{
label = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:#"%#", [_charDataOfYellow objectAtIndex:index]]];
}
CPTMutableTextStyle *textStyle = [label.textStyle mutableCopy];
textStyle.color = [CPTColor redColor];
label.textStyle = textStyle;
[textStyle release];
return [label autorelease];
Hope this can help!
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];