OxyPlot:如何使用轴标签格式器并显示Y标签? [英] OxyPlot: How to use the axis label formatter and show Y labels?

查看:56
本文介绍了OxyPlot:如何使用轴标签格式器并显示Y标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xamarin.iOS项目中使用Oxyplot绘制条形图.

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

这是我的图形当前的外观

This is what my graph currently looks likes currently

这里不是数字的x轴值,而是要显示sun,mon true,wed .....

here's instead of x axis values which are numbers, I want to show sun, mon true, wed.....

我可以看到CategoryAxis有一个称为LabelFormatter的方法,该方法返回 Func< double,string> ,但是如何使用它?

I can see that CategoryAxis has a method called LabelFormatter which returns Func<double, string>, but how do I use it?

为什么还没有显示Y轴标签?

And also why are the Y-Axis labels not showing?

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.PlotAreaBorderColor = OxyColors.Transparent;
        // A ColumnSeries requires a CategoryAxis on the x-axis.

        model.Axes.Add(new CategoryAxis()
        {
            Position = AxisPosition.Bottom,
            MinorTickSize = 0,
            MajorTickSize = 0,
            //MajorGridlineStyle = LineStyle.Solid,
            //MinorGridlineStyle = LineStyle.Solid,
        });

        model.Axes.Add(new LinearAxis()
        {
            AxislineStyle = LineStyle.None,
            Position = AxisPosition.Left,
            MinorTickSize = 0,
            MajorTickSize = 0,
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.Solid,
            Minimum = 0,
            Maximum = 400,
        });

        var series = new ColumnSeries();
        series.Items.Add(new ColumnItem() { Value = 200, Color = OxyColors.Orange});
        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);

        this.MyModel = model;
    }
}

推荐答案

要在轴上显示标签,必须指定属性 MajorStep ,Oxyplot将仅绘制与主要步骤匹配的标签.

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,
    ...
});

要修改带有日期名称的标签,可以使用 DateTimeAxis 代替 LinearAxis :

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

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

如果您要进行更多自定义,则必须使用 LabelFormatter 属性.

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

CategoryAxis中的标签:

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 是只读的,因此您必须一个接一个地添加项目.

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

这篇关于OxyPlot:如何使用轴标签格式器并显示Y标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆