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

Message ListMessage List     Post MessagePost Message

  Relationship between Chart, ChartViewer, and ChartViewPort?
Posted by Brad Kimble on Jan-13-2025 08:30
I am relatively new to ChartDirector. Most of our graphs will have multiple lines with live data coming in from several devices. I was able to get a few of our graphs working, without scrolling and zooming, just a Chart (with a few specific issues I'll submit separately). But when I tried to implement scrolling and zooming by adding the ChartViewer and ChartViewPort I am having basic problems. Before giving details of some of the specifics situations, I want to be certain I am using these correctly.
For each graph that I want scrolling and zooming, I have the main Chart, which I associate to a similar instance of a ChartViewer. Then I have an instance of the ChartViewPort which I add the ChartViewer to.
1. Our main program is Visual Studio 2022 C++, Windows (no web pages).
2. Is it correct that for each graph I need all three (Chartf/ChartViewer/ChartViewPort), associated together?
3. In looking at the samples, it appears each time I add data to a  chart, I need to create a completely new instance of the chart and assign it to my original ChartViewer. However in reading through some of the forum questions posted over the last 6 months I saw a few references that sounded like there are times when you only have to update the current chart. If this is true, when should I just update verses re-create the chart?

  Re: Relationship between Chart, ChartViewer, and ChartViewPort?
Posted by Peter Kwan on Jan-13-2025 17:03
Hi Brad,

As I am not sure what GUI framework you are using, I would use MFC terminology for the explanation.

You can consider the chart as an Image. Your code configures the XYChart object (by setting the data, labels, titles, axis scales ...), so it can draw the chart image.

In MFC, the CChartViewer is a control that displays the image.  In addition, it manages the "viewport". For example, the user can use mouse wheel and mouse drag to manipulate the viewport. You can consider the viewport to be like a "2D scrollbar", but it is invisible in the CChartViewer.

In recent versions of ChartDirector, we introduce the CViewPortControl so it is easier to visualize where is the viewport. The CViewPortControl is essentially a 2D scrollbar with a background image, which can be a tiny version of the full chart. The CViewPortControl is not mandatory. Some of our examples do not use the CViewPortControl.

https://www.advsofteng.com/doc/cdcpp.htm#viewportcontroldemo.htm
https://www.advsofteng.com/doc/cdcpp.htm#zoomscrolltrack.htm

For a zoomable/scrollable chart, the axis scale is controlled by the user through zoom/scroll actions. For the system to work, the charting should draw what the user selects. In our sample code, the drawChart function starts by asking the CChartViewer the data range selected by the user. It then gets the data and draws the chart. Typically, the charting code also sets the chart axis scale to the scale selected by the user (eg.  using syncDateAxisWithViewPort).

When the user performs zoom/scroll actions, the CChartViewer will emit a CVN_ViewPortChanged message. You code can then redraw the chart to the new data range. Usually, you do not need to write code to redraw the chart, as you can use the same code that draws the chart is the first place. In our zoom/scroll examples, we only need one drawChart subroutine.

You need to create a new XYChart object when you draw or redraw the chart. It is simpler this way as you do not need to write any additional code to update the chart. Also, in practice, recreating the chart can be faster than "updating the chart".

Best Regards
Peter Kwan

  Re: Relationship between Chart, ChartViewer, and ChartViewPort?
Posted by Brad Kimble on Jan-14-2025 00:50
Thank you for the clarification. Yes our application is MFC.
From your description we will not be needing the ChartViewPort.
I am using a common class to create my charts. I was just checking to make sure that was the correct way to do it.
I have gone through several of the examples but I will concentrate on the ones you mention as it is possible I may have mixed some code from multiple examples that may be causing my problems.

  Re: Relationship between Chart, ChartViewer, and ChartViewPort?
Posted by Brad Kimble on Jan-15-2025 00:53
Thank you for the clarification. Yes our application is MFC.
From your description we will not be needing the ChartViewPort.
I am using a common class to create my charts. I was just checking to make sure that was the correct way to do it.
I have gone through several of the examples but I will concentrate on the ones you mention as it is possible I may have mixed some code from multiple examples that may be causing my problems.