OxyPlot: how to hide left and top axis lines

随声附和 提交于 2019-12-11 00:38:04

问题


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

This is what my plot currently looks like

Here I need to hide the Right and top axis

I tried :

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

But no effect.. Here's my full code

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;
}

How do I do it? Any help is appreciated....

Edit:

Also, In my chart above, why are the y labels not showing. How can I change the x labels like below... Is it possible to draw lines in this chart like below?

This is what I want my final graph to look like:


回答1:


The problem is that the black border you are currently seeing is not the axis, is the plot area border, so you have to modify this property in the plotmodel:

model.PlotAreaBorderColor = OxyColors.Transparent;

And then, you have to add the AxisLineStyle to the axis that you want to draw(left and bottom), like this:

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

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


来源:https://stackoverflow.com/questions/38895963/oxyplot-how-to-hide-left-and-top-axis-lines

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