开发者

Autoscaling axis after pan or zoom in Visiblox chart

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


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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜