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

Message ListMessage List     Post MessagePost Message

  Real Time Multiply Charts
Posted by Chris on Dec-30-2019 23:23
Hi!

I'm looking for advise of best approach to succeed what I want. Writing in C# Win Forms.

My goal is to have a Form showing 5 stacked by 5 stacked XY Line Charts. With other words a "column" of five stacked charts on top of each other to the left, and likewise to the right.

All the charts should share the same Real Time X-Axis. Every chart have different Y-Axis, around 4-6 lines / Data Sets per chart.

A View Port Control at the bottom, reaching from leftmost of left chart to rightmost of right chart. Affecting all charts evenly.

A Track Line that follows the mouse when over either the left charts or the right charts. The track line should reflect the X axis position also on the other "column" of charts where the mouse does not hover. When mouse leaves area it should jump to the rightmost position.

Zooming ability, that zooms the X- axis evenly on all charts at the same where track line is located.

Bonus; ability to move Track Line and zoom with arrow keys.

On top of every chart I would like the Y-Axis Labels, and also showing the actual Y-Axis data, also the actual Time of X-Axis, all by the track line position.

The Y axis scale could be hard coded for every chart, and no need of labels, as this will be shown at the top of every chart.

The real time data comes in rather quick, about new data for all charts every 3 ms. With a data buffer readout and chart redraw every 20 ms.

I Have tried to marge some code from various examples , but find it hard to get it working. So please tell me a suggestion of best approach. And regarding the data rate is there any problem with so many charts?

Thank you! /Chris

  Re: Real Time Multiply Charts
Posted by Peter Kwan on Dec-31-2019 14:57
Hi Chris,

Just in case you are not aware, there are some additional multi-threading real-time chart sample code in the Library section of our web site. They are most useful for high speed real-time charts.

https://www.advsofteng.com/tutorials/extra.html

For your chart type, you can create this step by step as follows:

(a) Write code to create 5 stacked line charts with realtime zoom/scroll/track. The best way is to create them as a MultiChart.

(b) Extend (a) by create two such MultiCharts, and put them into two WinChartViewer on the left and right side, and sync them.

(c) Finally, add the WinViewPortControl at the bottom.

(d) Add other misc features, like using keyboard instead of mouse events to move the track cursor, or moves the track cursor to the rightmost position when the mouse leaves the plot area.


For (a), there is a C# Win Forms example at:

https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1531918054#N1532367831

The above contains 2 charts stacked up. You can easily expand it into 5 charts stacked up. The charts have the same x-axis scales, with sychronized track cursors and zooming scrolling.

For your information, a "financial chart" is just a type of stacked charts packing closely together so that only the bottom x-axis is visible. You may try this style if you like:

https://www.advsofteng.com/doc/cdnet.htm#trackfinance.htm


For (b), you can create two MultiCharts for the left and right stacks. To keep the two charts in sync, make them update each others in their ViewPortChange event handler.

When you zoom/scroll a chart (eg. by using the mouse wheel), it will trigger the "ViewPortChanged" event. The ViewPortChanged event handler should update the chart and as well as other affected controls. In some of our sample code, such as the "Multi-Threading Real-time Chart", we update the horizontal scrollbar as well.

For your case, instead of updating the horizontal scrollbar, you can update the other WinChartViewer. That is, if the left chart is zoom/scroll, update the right chart too and vice versa. This is by copying the viewport left/top/width/height to the other WinChartViewer, and then call its updateViewPort method. To avoid an infinite update loop due to mutually updating each others, your code should check if the viewports of the two WinChartViewers are different before updating each others.

For synchronizing the track cursors, you just need to draw the track cursors for both WinChartViewers in the OnMouseMovePlotArea events of either WinChartViewer.


For (c), you can set up a WinViewPortControl and connect it to either the left and right WinChartViewer. It does not matter because the two WinChartViewers should synchronize each others.


For (d), when the mouse leaves the plot area (in the OnMouseLeavePlotArea event), just  redraw the track cursor with the rightmost x-coordinate (the right side of the chart). If you want to use the keyboard to control the track cursor, you can handle the keyboard event, and redraw the track cursor in the event handler.


Hope this can help.

Regards
Peter Kwan