Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow horizontal scrolling only in the core-plot barchart?

I am using core-plot lib to draw bar charts in my app like this ......

My problem is that i want the enabling of grapgh movement only in horizontal direction so that I can see the records for a long period of time, But the problem is that i just wnt to keep the y axis fixed to its place,

How can i do this?

Waiting for help....

like image 662
Madhup Singh Yadav Avatar asked Dec 12 '09 06:12

Madhup Singh Yadav


1 Answers

Limit scrolling by setting a delegate (i.e., CPPlotSpaceDelegate) on the plot space and implement the willChangePlotRangeTo method. You can do other cool things at the same time. Here's how I limit the display to quadrant one:

- (CPPlotRange *)plotSpace:(CPPlotSpace *)space
    willChangePlotRangeTo:(CPPlotRange *)newRange
            forCoordinate:(CPCoordinate)coordinate {

    // Display only Quadrant I: never let the location go negative.
    //
    if (newRange.locationDouble < 0.0F) {
        newRange.location = CPDecimalFromFloat(0.0);
    }

    // Adjust axis to keep them in view at the left and bottom;
    // adjust scale-labels to match the scroll.
    //
    CPXYAxisSet *axisSet = (CPXYAxisSet *)self.graph.axisSet;
        if (coordinate == CPCoordinateX) {
            axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
            axisSet.xAxis.titleLocation = CPDecimalFromFloat(newRange. newRange.locationDouble +
                                                             (newRange.lengthDouble / 2.0F));
        } else {
            axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
            axisSet.yAxis.titleLocation = CPDecimalFromFloat(newRange.locationDouble +
                                                             (newRange.lengthDouble / 2.0F));
        }

    return newRange;
}

See: CPPlotSpace.h

like image 175
Tom Donaldson Avatar answered Oct 19 '22 20:10

Tom Donaldson