OxyPlot:如何隐藏左右轴线 [英] OxyPlot: how to hide left and top axis lines
问题描述
我正在使用 Oxyplot 为我的 Xamarin.iOS 项目绘制条形图
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
我试过了:
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....
另外,在我上面的图表中,为什么没有显示 y 标签.如何更改 x 标签,如下所示...是否可以在此图表中绘制如下所示的线条?
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:
推荐答案
问题是你当前看到的黑色边框不是轴,是绘图区边框,所以要在plotmodel中修改这个属性:
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;
然后,您必须将 AxisLineStyle 添加到要绘制的轴(左侧和底部),如下所示:
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
});
这篇关于OxyPlot:如何隐藏左右轴线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!