OxyPlot: How to use the axis label formatter and show Y labels?

后端 未结 1 1145
忘了有多久
忘了有多久 2021-01-06 23:37

I\'m using to Oxyplot for my Xamarin.iOS project for plotting a bar chart..

This is what my graph currently looks likes currently

here\'s instead of

1条回答
  •  离开以前
    2021-01-06 23:58

    To show the label on the axis you have to specify the property MajorStep, Oxyplot will paint only the labels matching the major step.

    model.Axes.Add(new LinearAxis()
    {
        MajorStep = 10,
        Position = AxisPosition.Left,
        ...
    });
    

    And to modify the labels with the day name, you can use a DateTimeAxis instead of LinearAxis:

    model.Axes.Add(new DateTimeAxis()
    {
        StringFormat = "ffffd",
        Position = AxisPosition.Bottom,
        ...
    });
    

    If you want something more customized you will have to use the LabelFormatter attribute.

    EDIT:

    Labels in CategoryAxis:

    var categoryAxis = new CategoryAxis()
    {
        Position = AxisPosition.Bottom,
        ...
    };
    
    categoryAxis.ActualLabels.Add("Mon");
    categoryAxis.ActualLabels.Add("Tue");
    categoryAxis.ActualLabels.Add("Wed");
    categoryAxis.ActualLabels.Add("Thu");
    categoryAxis.ActualLabels.Add("Fri");
    categoryAxis.ActualLabels.Add("Sat");
    categoryAxis.ActualLabels.Add("Sun");
    
    Model.Axes.Add(categoryAxis);
    

    CategoryAxis.ActualLabels is readOnly, so you will have to Add the items one by one.

    0 讨论(0)
提交回复
热议问题