IOS Core-Plot: How to get visible range of X and Y axis - ios

In Core-Plot I want to plot only the visible area of the plot. For this I need the visible range of the plot after Zoom-In and Zoom-Out.
Any Idea how to get visible range of X-Axis?

You can use a plot space delegate to find out when the plot ranges change. Each delegate method receives a reference to the plot space as one of its parameters. You can read the xRange and yRange to find out what the new ranges are.

You can get visible range of X-Axis using code like this:
space.graph.axisSet.xAxis.visibleAxisRange

Related

How to view a fixed number of points on timechart of achartengine?

For LineChart I used
XYMultipleSeriesRenderer mRenderer=new XYMultipleSeriesRenderer();
mRenderer.setXAxisMin(0);
mRenderer.setXAxisMax(30);
When I use the same for TimeChart, my graph disappears, only the layout is visible. Is there any other way I can display a fixed number or points on my graph?
This is because the X axis range for a time chart is much wider, given by the values returned from the getTime() method in Date.

How to detect the coordinates of a custom UIView on CPTPlotspace?

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.

Core Plot: Pan and zoom two plot spaces along x-axis and auto-scaling both y-axes

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.

Adding label to core plot chart

I want to add a label to a core plot scatter chart. It should be at a specific y value at the left edge of the chart, like that:
I tried doing it using annotation but I have a problem with dragging. When I drag the chart the annotation is also being dragged, and I would like it to always stay at the left edge.
Create your label as a plot space annotation. Use a plot space delegate to monitor changes to the xRange and update the x-value of the anchor point as needed. You can use the plot space to convert the desired x-position to the corresponding data value for the anchor point.

Draw a vertical line in Core Plot?

I have an iPhone project that displays some data of the past 24h in Core Plot. x axis shows the time, y axis the data value.
Now I want to highlight a day change by drawing a vertical line at midnight. How can this be done?
Add a scatter plot to your graph to draw the vertical line. Just give it two data points—one for each end of the line.

Resources