In my App, I am using Coreplot to draw a CPTScatterPlot. Now i want to do a scanner on the chart and this animation of UIView (a line) should be like a Line aligned with Y-axis and travels through x=0 to whatever the last value of x is.
I want to perform an action based on the y value while this custom UIView (scanner) travels.
Any help would be appreciated.
Thanks,
i have something similar in an app of mine, the way i went about it was to add a bar graph on top of the scatter plot, i used that bar graph to represent the line that tracks the user's touch.
then i have a UIView that is overlaid on the plot and tracks the scatter plot touches and displays details of the point being touched.
if you just want to display a line, adding a bar graph is probably the easiest, then you don't have to worry about plot space coordinates vs superview coordinates.
the bar graph data source is only returning a value for the location the user is touching, with a height to match the size of the scatter plot.
the quick version is you can use handlePlotTouchEventInSpace:atPoint:isNewEvent to track the user's touches on the graph.
from there you can use the plotPoint:forPlotAreaViewPoint method on the plot space to get the coordinates of the touch.
something like this is a good starting point. it's a bit of a journey to get it all working, but its not too bad once you get the puzzle started.
-(void)handlePlotTouchEventInSpace:(CPTPlotSpace *)space atPoint:(CGPoint)point isNewEvent:(BOOL)newEvent {
NSDecimal plotPoint[2];
CPTXYPlotSpace *xySpace = (CPTXYPlotSpace *)space;
[xySpace plotPoint:plotPoint forPlotAreaViewPoint:point];
after that plotPoint will contain the x and y location of the touch inside the plot space.
Related
Here's a picture that I think quickly illustrates the issue. You need only download the example from git hub, go to the curved scatter plot example and tap on a point to get the point annotations to appear, then simply scroll the graph over to move the points off the graph.
So normally we would want annotations floating above everything but for times when we set the axisContraints, in this case we set them to:
x.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0.5];
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
We want the annotations, that we add, to be drawn the same as the gridlines, plot lines, and plot points.
I've tried the following as a test, to see what would happen and this does NOT help.
// reorder layer
[annotationHostLayer insertSublayer:annotation.contentLayer atIndex:0];
[annotationHostLayer setNeedsDisplay];
It'll draw the gridlines, axes over the annotations but the annotations still float off the graph.
I'm using the sample code from coreplot, here's github link and the chart I've been experimenting with is the "Curved Scatter Plot" graph.
Update: I've been fooling around with maskToBorder and maskToBounds for the plotArea. It seems that masking to bounds would work if the axis were drawn within the layers bounds, which it is not. This clips the yaxis. I've looked around for other clipping code but to no avail.
Hide the content layers of any annotations that fall outside the desired area. Use a plot space delegate to monitor changes to the plot space and show or hide annotations as needed.
I'm working with a CorePlot scatter plot, and I'm having trouble putting the finishing touches on the axis label styling. I'd like for the plot to overlap above the Y-axis labels, but the opposite is happening. I've scoured the documentation, but can't find any options to do this.
Here's the output:
I've tried manipulating the ZPosition of both the plot & axis labels, but that doesn't seem to be working:
[plot setZPosition:99];
[axisSet.yAxis.axisLabels each:^(CPTAxisLabel *label) {
[label.contentLayer setZPosition:-1];
}];
Note - Objective Sugar used for loop comprehension
Any ideas as to how to accomplish this?
The plot area has a property called topDownLayerOrder that allows you to rearrange the different graph elements in exactly this way.
So I have a simple line XY Graph with integer values on the Y axis and dates on the X axis. What I would be like to be able to do is do a horizontal two-finger pinch and adjust the range dynamically. Eg, pinching in would give you a bigger range (mental model being that you're setting the start and end date shown to be further apart) and then pinching out would give you smaller time window.
Is there some stuff built in for this already? Reasonably new to CorePlot and the default finger stuff just zooms the graph itself, none of the values.
Would I need to put a gesture recgoniser on it? or does coreplot have stuff build into it for this?
Cheers
This is how the built-in zoom features work. Use a plot space delegate to monitor changes to the plot space while zooming and make changes to the axis appearance as needed based on the changes. See my answer to your other question for more info.
I'm trying to customize a Coreplot graph in many ways I can and the next thing I would like to do is place the X Axis Labels (one that is custom as well) at the bottom of the graph, independent of the X axis' position (whether it's scrolled up or down).
To make it clear, it is similar to giving the labels an offset value of something like 50.0. But offset is not the property I'm looking for since it fixes the labels location relative to the X axis.
Any way this can be done? Or do I have to skip the axisLabels property and place and layer or something manually at the bottom of the graph?
EDIT: Alright, I managed to place an axis on the bottom with CPTConstraints. But it's not on the bottommost. If a plot point is on those levels, the plot line overlaps the labels. I tired padding of the graph but of course, it moves the whole graph, hence the issue persists.
Thanks in advance
Make a second x-axis. Have the first one draw the axis line, tick marks, etc., as normal but no labels. Label the second one and set all of the line style properties to nil so it doesn't draw any of the lines.
Turns out that aside from the graph, the plotAreaFrame property of the CPTGrpah also has paddings. If you give more paddings to plotAreaFrame than that of the graph, the plot will be drawn in a smaller frame and the rest of the graph area will be for you to add what you want (i.e., a second Axis).
Big thanks to #Eric, for trying to answer Every single CorePlot question as soon as possible.
CorePlot does have a lot of customisation than I thought.
I have a Core Plot chart with two line plots (plot 1 uses the y-axis on the LHS, plot 2 uses the y2-axis on the RHS) and two plot spaces (lhsPlotSpace and rhsPlotSpace).
For the initial plot set-up, I use scaleToFitPlotsto autoscale the two plots, which works as expected:
[lhsPlotSpace scaleToFitPlots:lhsPlots];
[rhsPlotSpace scaleToFitPlots:rhsPlots];
The plot then looks similar to the screen shot below.
In order to show more details, I would like to allow the user to pan horizontally and to zoom horizontally as long there is more data to be shown on the left and right (panning and zooming should be user driven only along the x-axis).
The y-axis and y2-axis should be scaled automatically depending on the range visible after panning and zooming.
Could you please help me a bit with this problem? I tried to use the delegate
Based on the code example I have found in the Core Plot forums and on StackOverFlow I tried to do this using the delegate method plotSpace:willChangePlotRangeTo:forCoordinate
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate
{
if (coordinate == CPTCoordinateY) {
newRange = ((CPTXYPlotSpace*)space).yRange;
return newRange
}
but besides getting very basic zooming, I did not found a solution which is even close to my problem.
Could you please point me to which delegates methods to use, how to restrict scrolling and how and where to set the new y-scale factor after panning and zooming?
Thank you very much!
Set the globalYRange of each plot space to the corresponding yRange to prevent scaling and scrolling in the y-direction.
-scaleToFitPlots: uses all plot data for the given plots when computing the new ranges. If you want to scale the plot space yRange based on the visible data, you'll have to do that yourself in the plot space delegate. The -plotSpace:willChangePlotRangeTo:forCoordinate: delegate method is a good choice for this.