我有一个 Visiblox 折线图,它允许在 XAxis(但不是 YAxis)上进行缩放和平移。缩放或平移到图表的特定区域后,我希望仅根据可见数据重新计算 YAxis 范围和刻度。我尝试在 YAxis 上设置 AutoScaleToVisibleData="True",但这不起作用,因为缩放和平移不设置 XAxis.Range,并且 XAxis.Range 必须更改才能使 YAxis 的 AutoScaleToVisibleData 属性生效。
编辑
我现在正在尝试使用 IAxis.AdoptZoomAsRange() 函数,但似乎无法弄清楚。相关示例代码如下:
XAML:
<charts:Chart Name="chart">
<charts:Chart.Behaviour>
<charts:BehaviourManager AllowMultipleEnabled="True">
<charts:PanBehaviour IsEnabled="True" YPanEnabled="False" PanEnded="PanBehaviour_PanEnded" />
<charts:ZoomBehaviour IsEnabled="True" YZoomEnabled="False" AnimationEnabled="False" ZoomMode="MouseWheel" ZoomEnded="ZoomBehaviour_ZoomEnded" />
</charts:BehaviourManager>
</charts:Chart.Behaviour>
<charts:Chart.XAxis>
<charts:DateTimeAxis />
</charts:Chart.XAxis>
<charts:Chart.YAxis>
<charts:LinearAxis AutoScaleToVisibleData="True" />
</charts:Chart.YAxis>
</charts:Chart>
代码隐藏:
public MainWindow()
{
InitializeComponent();
DataSeries<DateTime, double> dataSeries = new DataSeries<DateTime, double>();
for (int i = 0; i < 100; i++)
dataSeries.Add(new DataPoint<DateTime, double>(DateTime.Now.AddMonths(i), i));
LineSeries lineSeries = new LineSeries();
lineSeries.DataSeries = dataSeries;
chart.Series.Add(lineSeries);
}
private void PanBehaviour_PanEnded(object sender, EventArgs e)
{
chart.YAxis.AdoptZoomAsRange();
}
private void ZoomBehaviour_ZoomEnded(object sender, EventArgs e)
{
chart.YAxis.AdoptZoomAsRange();
}