如何从 Oxplot 图形中删除轴但保留缩放和平移功能?
How can I remove the axes from an Oxplot graph but retain zoom and pan functionality?
我可以像答案 一样使用 IsAxisVisible = false
删除轴,但是当我这样做时无法再平移或缩放图表。
图形不平移的示例代码(使用 Oxyplot 2.0):
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();
}
}
正如前面评论中提到的,这种行为似乎发生在 Oxyplot 2.0 中,而 1.0 确实允许 Zoom/Pan 即使轴不可见。
另一种方法是将 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
});
这将允许您 Zoom/Pan 不显示轴。
我确定的解决方案(至少在解决原始问题中描述的 IsAxisVisible = false
问题之前)是实施 Anu 的答案,并添加:
Model.PlotMargins = new OxyThickness(0);
隐藏轴粗细。
我可以像答案 IsAxisVisible = false
删除轴,但是当我这样做时无法再平移或缩放图表。
图形不平移的示例代码(使用 Oxyplot 2.0):
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();
}
}
正如前面评论中提到的,这种行为似乎发生在 Oxyplot 2.0 中,而 1.0 确实允许 Zoom/Pan 即使轴不可见。
另一种方法是将 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
});
这将允许您 Zoom/Pan 不显示轴。
我确定的解决方案(至少在解决原始问题中描述的 IsAxisVisible = false
问题之前)是实施 Anu 的答案,并添加:
Model.PlotMargins = new OxyThickness(0);
隐藏轴粗细。