Core Plot - How to make a Floating Axis

RogierKoningRogierKoning ESMember ✭✭
edited June 2013 in Xamarin.iOS

Hi everyone,

I'm trying to do a XYGraph for an iOS application using the CorePlot component but I can't manage to make an axis Floating. What I want is keeping the axis line always at the same position when the user touches and drags the screen.

I've got this code.

        var axisSet = (CPTXYAxisSet) graph.AxisSet;

        // Label x with a fixed interval policy
        var x = axisSet.XAxis;
        x.LabelingPolicy = CPTAxisLabelingPolicy.Automatic;
        x.MinorTicksPerInterval = 4;
        x.PreferredNumberOfMajorTicks = 8;
        x.MajorGridLineStyle = major;
        x.MinorGridLineStyle = minor;
        x.Title = "X Axis";
        x.TitleOffset = 25f;

        // Label y with an automatic label policy. 
        var y = axisSet.YAxis;
        y.LabelingPolicy = CPTAxisLabelingPolicy.Automatic;
        y.MinorTicksPerInterval = 4;
        y.PreferredNumberOfMajorTicks = 8;
        y.MajorGridLineStyle = major;
        y.MinorGridLineStyle = minor;
        y.LabelOffset = -6f;
        y.Title = "Weight";
        y.TitleOffset = -30f;

        //Make the Y axis start on number 40
        x.OrthogonalCoordinateDecimal = NSDecimalNumber.FromFloat(40.0f).NSDecimalValue;
        plotspace.GetPlotRange (CPTCoordinate.X).Location = NSDecimalNumber.FromFloat(40.0f).NSDecimalValue;

        //Format the Y axis sufix " Kg"
        NSNumberFormatter newFormatter = new NSNumberFormatter();
        newFormatter.MinimumIntegerDigits = 1;
        newFormatter.PositiveSuffix = " Kg";
        y.LabelFormatter = newFormatter;

And the graph is shown properly like this.


but when the user scrolls to the up-right the axis are not visible


Now I want to make the axis always visible. I've found some Objective-C examples that use the instruction:

y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
But I can't find the "axisConstraints" property in a CPTXYAxis object.

I've also tried with the instruction x.IsFloatingAxis = true; but it makes the app to crash.

If anyone could help me to show floating axis I would be very pleased. Thank you in advance.


  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    This would appear to be an issue with the bindings. IsFloatingAxis should no longer be in there, and axisConstraints should. So it seems like it was bound against an old version of the library.

    Perhaps best to contact the creator of the binding, and/or create a new binding yourself (using ObjectiveSharpie)

  • RogierKoningRogierKoning ESMember ✭✭

    Thank you @ChrisHonselaar.

    I saw that Xamarin's coreplot binding is from version 0.9 and the latest coreplot version is 1.2.

    I've tried to create a binding from the latest obj-c version with ObjectiveSharpie but after 3 days the program still saying 'generating binding'. I've tried it several times with no success. Maybe I've made something wrong because it's the first time I use ObjectiveSharpie.

    I've also written to the binding author with no response.

    I'm still being interested in creating a floating axis, so I'll keep on trying to get it through the Xamarin's coreplot binding.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Yeah, it must be a version issue. If you cannot get it to work (make sure you match the correct version of the CorePlot binary) and the author does not contact you (maybe on holiday?), you could always create your own binding. If this seems a huge undertaking, perhaps you can get away with manually binding only the parts you need.

    Weird problem with ObjectiveSharpie though - you could file that on the Xamarin Bugzilla I think.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Also, did you try the new Objective Sharpie update?

  • RogierKoningRogierKoning ESMember ✭✭

    Thank you very much @ChrisHonselaar. I've tried the new version of Objective Sharpie but it takes days without finishing, as well.
    I think I'll try to use another component for making graphs instead of core-plot.

    If I get it to work I'll post which component I've used and how I've made it.

  • RogierKoningRogierKoning ESMember ✭✭

    Finally, I've used the Oxyplot library. @EmanueleSabetta has made a binding to monotouch that can be downloaded here under the MIT License, a wonderful work.

    My impressions are that Oxyplot library API is quite easy to use. I've managed to make floating axis with no problems.

    Furthermore, there are a lot of sample plots that help to use its API.

    Thank you very much @ChrisHonselaar for all your help.

  • PierceBogganPierceBoggan USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    OxyPlot is what I mess around with some as well. If I remember correctly, it has a Xamarin.Android version as well (available on their main page), although it is in Alpha.

Sign In or Register to comment.