DynamicDataDisplay zoom and tooltips on realtime c

2019-08-23 17:13发布

问题:

Some time ago I posted the question about synchronous charts. I found the solution here, but I still have some problems.

  • I need to zoom in and out on Y axis on StrokeChart to see my date. I don't know why, but the range doesn't change on next added point. Actually range is 0-1 on Y axis. It's strange, but I can live with that
  • The second question is: how to configure zoom on chart area? I want it to zoom only Y axis when I scroll up/down.
  • And last, but not least: How to make realtime tooltips on chart which is build using ObservableCollection? It can be done for EnumerableDataSource easy. you can check this and this. I tried to do thing described by user "Thecentury", but it doesn't work. I even added method AddMapping to ObservableCollection and rebuilt the library, but it still doesn't work. So I don't know what to do next.

I appreciate for any help and advice. Thank you

回答1:

Regarding zooming I think I managed to solve the problem.

In MouseNavigation.cs add new properties

// 2014-02-22 - MPEKALSKI - added property to make possible
                         limiting on zoom on only one axis
private bool? _zoomX;
/// <summary>
/// Property for allowing/disallowing for zoom along X axis. By default allowed (true).
/// </summary>
public bool zoomX
{
    get { return _zoomX ?? true; }
    set { _zoomX = value; }
}
private bool? _zoomY;
/// <summary>
/// Property for allowing/disallowing for zoom along Y axis. By default allowed (true).
/// </summary>
public bool zoomY
{
    get { return _zoomY ?? true; }
    set { _zoomY = value; }
}     

In the same class modify the method

private void MouseWheelZoom(Point mousePos, int wheelRotationDelta)

by substituting

Viewport.Visible = Viewport.Visible.Zoom(zoomTo, zoomSpeed);

with

    // 2014-02-23 - MPEKALSKI - if we do not allow for change in Y
    //                          then keep the old value, by analogy for X
    Rect zoomedRect = Viewport.Visible.Zoom(zoomTo, zoomSpeed);
    if (zoomY == false) { zoomedRect.Y = Viewport.Visible.Y; 
                          zoomedRect.Height = Viewport.Visible.Height; }
    if (zoomX == false) { zoomedRect.X = Viewport.Visible.X;
                          zoomedRect.Width = Viewport.Visible.Width; }
    Viewport.Visible = zoomedRect;

The use now is pretty straightforward given chartPlotter object just set properties zoomY or zoomX to false to prevent zooming along this axis.

chartPlotter2.MouseNavigation.zoomY = false;

I do not know is it the most optimal solution, but it works for me.