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.
Related
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.
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 want to draw the pin and information of the place on the image of the camera..
Please any one help me..
i had done the coding in the app delegate
The code is :-
overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; overlay.opaque = NO; overlay.backgroundColor=[UIColor clearColor];
[window addSubview:overlay];
#define CAMERA_TRANSFORM 1.24299
UIImagePickerController *uip;
#try {
uip = [[[UIImagePickerController alloc] init] autorelease];
uip.sourceType = UIImagePickerControllerSourceTypeCamera; uip.showsCameraControls = NO;
uip.toolbarHidden = YES;
uip.navigationBarHidden = YES;
uip.wantsFullScreenLayout = YES;
uip.cameraViewTransform = CGAffineTransformScale(uip.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM);
}
#catch (NSException * e)
{ [uip release];
uip = nil;
}
#finally
{ if(uip) {
[overlay addSubview:[uip view]]; [overlay release]; }
}
it shows the camera.Not i want to detect the place and put the pin on that place which shows the information of that place.
Here is a more straightforward recipe to detect the presence of a camera:
BOOL isCameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
99% of the job is still ahead I'm afraid. Roughly you need the following:
Get the geographical location for the user.
Get the geographical location for the point of interest (POI) you want to show. You may need to use a 3rd party library like Foursquare, Google maps, or something like that.
Calculate the distance between the user and a POI using a right triangle between both points h^2=c^2+c^2. Note that the distance in spherical geometry is calculated with the haversine formula, but the loss of precision is irrelevant for small distances if we assume cartesian coordinates, so we will just do that.
Assuming that east is 0º, get the angle from the user to the POI, which is atan dy/dx (y=latitude, x=longitude). dy is of course, the difference between the latitudes from the user and the POI.
Get the bearing from the compass and calculate the difference between the user bearing and the angle to the POI.
The position on screen of the object depends on the bearing and the device orientation. If the user is looking exactly at the POI, paint a label for the POI in the middle of the screen. If there is an offset from the exact angle, multiply offset * (width in pixels / horizontal field vision) to get the offset in pixels for the label representing the point. Do the same for the vertical offset.
If there is a rotation on the axis X (see the axis here), apply a vertical offset.
If there is a rotation on the axis Y, there will be an update in bearing from the compass.
If there is a rotation on the axis Z, if the object is near rotate the object in the opposite angle.
Scale the label according to the distance, with a minimum and a maximum.
To position the labels you may want to use a 3D engine or rotate them in a circle around your device (x=x+r*cos, y=y+r*sin) and use a billboard effect.
If that sounds like too much work, concentrate on implementing just the response to changes in bearing using offset * width in pixels / horizontal field vision. Horizontal field vision is the visible angle for the camera. It is 180º for humans, 37.5 for iPhone 3, and hmm was it 45º for iPhone 4? Width is 320, so if you are looking 10º away from your target, you have to move it horizontally 320*10/37.5 pixels away from the center.
If the readings from the compass have too much noise, add a low pass filter.
Please go through
https://github.com/zac/iphonearkit.
It's the best objectiveC code available.
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];
Is there a set of string attributes I can specify that will draw the text at an angle when I call:
[label drawAtPoint:textStart withAttributes:attributes];
Here's an example that uses a transform to rotate the drawing context. Essentially it's just like setting a color or shadow, just make sure to use -concat instead of -set.
CGFloat rotateDeg = 4.0f;
NSAffineTransform *rotate = [[NSAffineTransform alloc] init];
[rotate rotateByDegrees:rotateDeg];
[rotate concat];
// Lock focus if needed and draw strings, images here.
[rotate release];
NSString itself doesn't have rotation, but you can rotate the context. The string will always be drawn "horizontally" as far as the coordinate space goes, but what actual direction that corresponds to depends on the context. Just use NSAffineTransform to spin it as needed.