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

ⅰ亾dé卋堺 提交于 2019-12-01 09:01:35

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 = "ddd",
    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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!