OxyPlot:如何隐藏左轴和顶轴线

时间:2016-08-11 12:07:32

标签: c# xamarin.ios oxyplot

我正在使用Oxyplot为我的Xamarin.iOS项目绘制条形图

这就是我的情节目前的样子

enter image description here

这里我需要隐藏右轴和上轴

我试过了:

model.Axes.Add(new LinearAxis()
{
    Position = AxisPosition.Right,
    IsAxisVisible = false
});
model.Axes.Add(new LinearAxis()
{
    Position = AxisPosition.Top,
    IsAxisVisible = false
});

但没有效果..这是我的完整代码

public MyClass()
{
    var model = new PlotModel { Title = "ColumnSeries" };
    // A ColumnSeries requires a CategoryAxis on the x-axis.

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

    model.Axes.Add(new LinearAxis()
    {
        Position = AxisPosition.Left,
        MinorTickSize = 0,
        MajorGridlineStyle = LineStyle.Solid,
        MinorGridlineStyle = LineStyle.Solid,
        Minimum = 0,
        Maximum = 400
    });
    model.Axes.Add(new LinearAxis()
    {
        Position = AxisPosition.Right,
        IsAxisVisible = false
    });
    model.Axes.Add(new LinearAxis()
    {
        Position = AxisPosition.Top,
        IsAxisVisible = false
    });

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

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

编辑:

此外,在上面的图表中,为什么y标签没有显示。如何更改下面的x标签...是否可以在此图表中绘制线条,如下所示?

这就是我想要的最终图形:

enter image description here

1 个答案:

答案 0 :(得分:1)

问题是你当前看到的黑色边框不是轴,是绘图区边框,所以你必须在plotmodel中修改这个属性:

model.PlotAreaBorderColor = OxyColors.Transparent;

然后,您必须将AxisLineStyle添加到要绘制的轴(左侧和底部),如下所示:

model.Axes.Add(new LinearAxis()
{
    AxislineStyle = LineStyle.Solid,

    Position = AxisPosition.Left,
    MinorTickSize = 0,
    MajorGridlineStyle = LineStyle.Solid,
    MinorGridlineStyle = LineStyle.Solid,
    Minimum = 0,
    Maximum = 400
});