在 Visiblox 图表中平移或缩放后自动缩放轴

发布于 2024-11-26 19:33:37 字数 1748 浏览 0 评论 0原文

我有一个 Visiblox 折线图,允许在 X 轴(但不能在 Y 轴)上缩放和平移。缩放或平移到图表的特定区域后,我希望仅根据可见数据重新计算 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();
}

I have a Visiblox line chart that allows zooming and panning on the XAxis (but not the YAxis). After zooming or panning to a particular region of the chart, I would like to have the YAxis range and ticks recalculated based on the visible data only. I tried setting AutoScaleToVisibleData="True" on the YAxis, but this does not work as zooming and panning do not set XAxis.Range, and XAxis.Range must change in order for the YAxis's AutoScaleToVisibleData property to have an effect.

EDIT

I am now attempting to use the IAxis.AdoptZoomAsRange() function but can't seem to figure it out. Relevant example code below:

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>

Code-behind:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天白云 2024-12-03 19:33:37

IAxis 上的 AdoptZoomAsRange 方法可能就是您正在寻找的 - 有一个可下载的示例,该示例在此 博客文章 希望能让这一点更清楚。

[披露:我在 Visiblox 工作]

The AdoptZoomAsRange method on IAxis is probably what you're looking for - there's a downloadable example it being used in this blog post which should hopefully make that clearer.

[disclosure: I work on Visiblox]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文