ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  synchronize a viewport control with several winchartviewers
Posted by Salvador de Lira Ramirez on Nov-09-2019 00:02
There is some way how to synchronize a viewport control with several winchartviewers, that is, use the same controller for several winchartviewers. I'm runing in C# and using the chardirecot .net.

  Re: synchronize a viewport control with several winchartviewers
Posted by Peter Kwan on Nov-09-2019 15:05
Hi Salvador,

Yes. You can use the same ViewPortChanged event handler to update all the charts in all the WinChartViewers.

Suppose you have two WinChartViewers, called "winChartViewer1" and "winChartViewer2". You can set up a WinViewPortControl and connect it to "winChartViewer1". Then in the ViewPortChanged event handler, you can update both charts in both WinChartViewers. It is like:

void winChartViewer1_ViewPortChanged(object sender, WinViewPortEventArgs e)
      // Update the chart if necessary
      if (e.NeedUpdateChart)
          // update chart 1

          // update chart 2
          winChartViewer2.ViewPortLeft = winChartViewer1.ViewPortLeft;
          winChartViewer2.ViewPortTop = winChartViewer1.ViewPortTop;
          winChartViewer2.ViewPortWidth = winChartViewer1.ViewPortWidth;
          winChartViewer2.ViewPortHeight = winChartViewer1.ViewPortHeight;

          // ... update additional charts ...

Would you also allow the user to zoom/scroll without using the WinViewPortControl? For example, can the user zoom by using the mouse wheel over winChartViewer2? If the user can do this, then you would need to handle the ViewPortChanged event for winChartViewer2 by forwarding that event to winChartViewer1. It is like:

void winChartViewer2_ViewPortChanged(object sender, WinViewPortEventArgs e)
      // forward event to winChartViewer1 as all charts are update together in the
      // winChartViewer1 ViewPortChanged event

      winChartViewer1.ViewPortLeft = winChartViewer2.ViewPortLeft;
      winChartViewer1.ViewPortTop = winChartViewer2.ViewPortTop;
      winChartViewer1.ViewPortWidth = winChartViewer2.ViewPortWidth;
      winChartViewer1.ViewPortHeight = winChartViewer2.ViewPortHeight;
      winChartViewer1.updateViewPort(e.NeedUpdateChart, e.NeedUpdateImageMap);

Hope this can help.

Peter Kwan