我可以像回答here一样使用IsAxisVisible = false
删除坐标轴,但是当我这样做时就不能再平移或缩放图形了。
图形无法平移的示例代码:
public class MainViewModel
{
public MainViewModel()
{
var tmp = new PlotModel { Title = "Simple example", Subtitle = "using OxyPlot" };
tmp.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Bottom,
IsAxisVisible = false
});
tmp.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Left,
IsAxisVisible = false
});
var series1 = new LineSeries { Title = "Series 1", MarkerType = MarkerType.Circle };
series1.Points.Add(new DataPoint(0, 0));
series1.Points.Add(new DataPoint(10, 18));
series1.Points.Add(new DataPoint(20, 12));
series1.Points.Add(new DataPoint(30, 8));
series1.Points.Add(new DataPoint(40, 15));
tmp.Series.Add(series1);
this.Model = tmp;
}
public PlotModel Model { get; private set; }
}
编辑:
xaml
<Window x:Class="SimpleDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
xmlns:simpleDemo="clr-namespace:SimpleDemo"
Title="OxyPlot SimpleDemo" Height="480" Width="640">
<Window.DataContext>
<simpleDemo:MainViewModel />
</Window.DataContext>
<Grid>
<oxy:PlotView Model="{Binding Model}" />
</Grid>
</Window>
xaml.cs
public partial class MainWindow
{
public MainWindow()
{
this.InitializeComponent();
}
}
答案 0 :(得分:1)
如前面的评论中所述,此行为似乎是在Oxyplot 2.0上发生的,而1.0确实允许缩放/平移,即使在轴不可见时也是如此。
另一种方法是将AxislineColor
,TextColor
和TicklineColor
设置为OxyColors.Transparent
。
tmp.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Bottom,
IsZoomEnabled = true,
IsPanEnabled = true,
AxislineColor = OxyColors.Transparent,
TextColor = OxyColors.Transparent,
TicklineColor = OxyColors.Transparent
}); ; ;
tmp.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Left,
IsZoomEnabled = true,
IsPanEnabled = true,
AxislineColor = OxyColors.Transparent,
TextColor = OxyColors.Transparent,
TicklineColor = OxyColors.Transparent
});
这将允许您在不显示轴的情况下进行缩放/平移。
答案 1 :(得分:1)
我已经确定的解决方案(至少在解决原始问题中描述的IsAxisVisible = false
问题之前)是实现Anu的答案,并增加了:
Model.PlotMargins = new OxyThickness(0);
隐藏轴粗度。