Xamarin Oxyplot:如何隐藏YAxis Minor tick?

时间:2016-08-11 10:25:03

标签: xamarin xamarin.ios oxyplot

我试图在我的Xamarin.iOS项目中使用oxyplot绘制一个列系列。我需要隐藏YAxis次要蜱虫。所以我试过

var model = new PlotModel { Title = "ColumnSeries" };
model.DefaultYAxis.MinorTickSize = 0;

但是第二行给了我错误

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at MyAZHealth.MyClass..ctor () [0x00128] in /Users/cinchmac/Projects/Gogch/MyAZHealth/Controllers/VitalDetailsViewController.cs:100
  at MyAZHealth.VitalDetailsViewController..ctor (IntPtr handle) [0x00001] in /Users/cinchmac/Projects/Gogch/MyAZHealth/Controllers/VitalDetailsViewController.cs:23
  at at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
  --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:650
  at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00089] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:635
  at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:663
  at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62
  at ObjCRuntime.Runtime.ConstructNSObject[T] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x0003e] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/ObjCRuntime/Runtime.cs:843
  at ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass, MissingCtorResolution missingCtorResolution) [0x00013] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/ObjCRuntime/Runtime.cs:824
  at ObjCRuntime.Runtime.GetNSObject (IntPtr ptr, MissingCtorResolution missingCtorResolution, Boolean evenInFinalizerQueue) [0x00022] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/ObjCRuntime/Runtime.cs:937
  at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject (System.Type type, IntPtr selector, IntPtr obj, System.IntPtr& mthis) [0x00064] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/ObjCRuntime/DynamicRegistrar.cs:849
  at ObjCRuntime.Runtime.GetMethodAndObjectForSelector (IntPtr klass, IntPtr sel, IntPtr obj, System.IntPtr& mthis) [0x00000] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/ObjCRuntime/Runtime.cs:555
  at ObjCRuntime.Runtime.get_method_and_object_for_selector (IntPtr cls, IntPtr sel, IntPtr obj, System.IntPtr& mthis) [0x00000] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/runtime/Delegates.generated.cs:242
  at at (wrapper native-to-managed) ObjCRuntime.Runtime:get_method_and_object_for_selector (intptr,intptr,intptr,intptr&)
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/UIKit/UIApplication.cs:79
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/UIKit/UIApplication.cs:63
  at MyAZHealth.Application.Main (System.String[] args) [0x00008] in /Users/cinchmac/Projects/Gogch/MyAZHealth/Main.cs:12

我该怎么做?任何帮助表示赞赏

编辑:

public partial class VitalDetailsViewController : UIViewController
{
    private PlotView plotView;
    public ProgramVital pVital { get; set;} 

    public VitalDetailsViewController (IntPtr handle) : base (handle)
    {

    }

    private readonly MyClass myClass = new MyClass();

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        this.plotView = new PlotView();
        this.plotView.Model = myClass.MyModel;

        // Set the frame and add the plot view to the vie
        this.plotView.Frame = chartContainerView.Frame;
        this.plotView.AutoresizingMask = UIViewAutoresizing.All;
        chartContainerView.AddSubview(this.plotView);
    }

    public override void ViewWillDisappear(bool animated)
    {
        base.ViewWillDisappear(animated);
        //this.NavController.ToolbarHidden = true;
    }


}

public class MyClass
{
    /// <summary>
    // Gets or sets the plot model that is shown in the demo apps.
    /// </summary>
    /// <value>My model.</value>
    public PlotModel MyModel { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="OxyPlotSample.MyClass"/> class.
    /// </summary>
    public MyClass()
    {
        var model = new PlotModel { Title = "ColumnSeries" };
        //model.DefaultYAxis.MinorTickSize = 0;
        // A ColumnSeries requires a CategoryAxis on the x-axis
        CategoryAxis axis = new CategoryAxis();
        axis.Position = AxisPosition.None;
        axis.MinorTickSize = 0;
        axis.MajorTickSize = 0;
        model.Axes.Add(axis);


        var series = new ColumnSeries();
        series.Items.Add(new ColumnItem(100));
        series.Items.Add(new ColumnItem(200));
        series.Items.Add(new ColumnItem(300));
        series.Items.Add(new ColumnItem(100));
        series.Items.Add(new ColumnItem(200));
        series.Items.Add(new ColumnItem(100));
        series.Items.Add(new ColumnItem(130));

        model.Series.Add(series);

        //model.DefaultYAxis.AbsoluteMinimum = 0;
        //model.DefaultYAxis.AbsoluteMaximum = 400;

        this.MyModel = model;
    }
}

1 个答案:

答案 0 :(得分:2)

问题是DefaultYAxis返回null,所以你必须创建自己的轴,如下所示:

Model.Axes.Add(new LinearAxis()
{
    Position = AxisPosition.Left,
    MinorTickSize = 0,
    MajorGridlineStyle = LineStyle.Solid,
    MinorGridlineStyle = LineStyle.Solid,
    Title = "left axis"
});

我已尝试过此操作,MinorTick未显示。