简体   繁体   中英

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM