Hello,
I want to overwrite the default zooming behaviour for XamDataChart in a WPF application. I want the zoom to be only on the Y axis and the chart to be always centered; the base line ( zero line) to be in the middle of the graph.
The code below works inside a button click event function, but I want to make it work for the mouse wheel.
dataChart.WindowScaleVertical = 0.5;
dataChart.WindowPositionVertical = (1.0 - dataChart.WindowScaleVertical) / 2.0;
Thanks,
Radu.
Hello Radu,
Thank you for your post!
I have been looking into your issue and have created a small sample application for you. In order to achieve the functionality you have described I can suggest to set VerticalZoomable property of the XamDataChart to true and the VerticalZoombarVisibility to Visible, if you want the zoombar to be visible.
In order to use the code snippet you have provided I have handled the PreviewMouseWheel event of the XamDataChart.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter,
I am just checking if you have any further questions on this matter. Please do not hesitate to let me know if you do.
Hi Gergana,
Thank you for your reply. Handling the PreviewMouseWheel event, all you can do is to disable the zoom functionality like this:
private void DataChart_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
//this.DataChart.WindowPositionVertical = (1.0 - this.DataChart.WindowScaleVertical) / 2.0;
e.Handled = true;
}
The first line ( that is now commented) is useless because all the zoom calculation and repositioning of the chart control is done after this event.
I want the zoom on the mouse wheel to be pan vertical with the zero line to be always in the middle of the chart regardless of the zoom level.
Mouse wheel zoom is dependent of the cursor position in the control.
I tried to reposition the cursor inside of this event handler but I didn't get the expected behaviour.
I am displaying an real-time electrical signal with values between -1 to 1 volts. Zero line should be always in the middle for all zoom factors.
I have been looking into your post and have modified the sample application I have sent in my previous post.
In the modified sample application I have handled the PreviewMouseWheel event. In the handler of the event I am calculating the height of the WindowRect, so the zero would be in the middle of the rectangle.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.