Core-plot Question : How to add a data Indicator
Asked Answered
S

1

6

i want to add a data indicator line similar to the following image in core-plot.

Plot Image http://img203.imageshack.us/img203/9412/plota.png

Any idea how i can achieve this using core-plot. I have just started to understand core-plot, so any tip will be very useful.

Thanks

Edit :

For better understanding i have created a screencast to show what i mean :

http://www.screencast.com/users/GauravVerma/folders/Jing/media/78fbef04-8785-46d6-9347-4f35d257109c

Added on 26th Feb :

I have solved partial problem by using two dataplots. here is the current implementation :

http://www.screencast.com/users/GauravVerma/folders/Jing/media/02a1e685-8bf8-41a9-aaa6-5ea6445f6a6c

I have used two dataplots, one is the main one & other one plots only one data point which is reloaded when slider value changes.

Here are my Datasource methods (may help somebody):

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
    if ([(NSString *)plot.identifier isEqualToString:@"Blue Plot"]){
        return [dataForPlot count];
    }else {
        return 1;
    }

}

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    if ([(NSString *)plot.identifier isEqualToString:@"Green Plot"]) {
        index = floor((double)[slider value]);
        if (index > [dataForPlot count] -1) {
            index = [dataForPlot count] -1;
        }
        NSLog(@"Green plot index : %f",index);
    }
    NSNumber *num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPScatterPlotFieldX ? @"x" : @"y")];
    num = [NSNumber numberWithDouble:[num doubleValue] + 1.0];
    return num;
}

Now only problem remains is to find out a easy way to draw the line. Any Ideas ??

Sheepshearing answered 24/2, 2010 at 11:4 Comment(2)
Which element in the image you're showing is the "data indicator"?Wellfound
the red line, which shows the current value. When user moves slider, red line also moves showing the current value on top. For a implementation please look at the Cardex view of Roambi application (roambi.com)Sheepshearing
I
6

There is not really any direct way to do this type of interaction in Core Plot itself yet, though it is planned for future inclusion.

One way to do it would be to place your own UIView over the top of the graph, and use that to get mouse move events.

You could then have a few choices for showing the red line:

1) Add a second y axis, and position it according to the mouse events

2) Add a bar plot with exactly one bar, that extends over the whole vertical space

3) Add a scatter plot that has two points, one at the bottom, and one at the top.

These are all hacks, but they should all work.

Issykkul answered 27/2, 2010 at 18:35 Comment(2)
can you elaborate a bit on this and how to detect the touch events on graph since it is not supported..Osset
This response is now quite old. We now do have some support for event handling in Core Plot. There are several delegate methods in the CPTPlotSpace class that allow you to receive events. Just set the delegate of the plot space, and implement the methods to update the position of your red line.Issykkul

© 2022 - 2024 — McMap. All rights reserved.