Paul Vinogradov Paul Vinogradov - 2 months ago 44
C# Question

Dynamic-Data-Display WPF Changing the ChartPlotter's default behaviour to moving instead of scaling

I have some data that comes via messages to my chart. It's a electric current over time (seconds) chart. How can I change the behaviour of the FitToView mode (or write a different one) so that the plotter doesn't zoom out and scale to fit the whole line graph, but move left instead, showing for example only the 100 last seconds?

I thought of calculating minimums and maximums every message and changing the plotters restraints explicitly but it doesn't seem very optimal. Also due to the fact that I would have to set the restraints in code-behind but all the data is in the ViewModel (using MVVM with caliburn).


So I have made this possible by wrtiting a method in the DataRect class that changes the width of the Visible rectangle

public void SetWidthFromMax(double wid)
        if (width < wid)
            XMin = XMax - wid;
            width = wid;

I call it in the CoerceVisible method of the Viewport2D after the union of all the DataSources has been calculated