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

Message ListMessage List     Post MessagePost Message

  Resize a chart, I cannot figure out how to do it.
Posted by Tony on Oct-21-2021 22:18
Hello,

I'm looking to use ChartDirector in a wxWidgets application.

I've looked at the realtimesweep demo, and I cannot figure out how the chart is resized.

All I want to do is resize it to fill a window. So I know the size the chart needs to resize to.

Is there a simple way to do it?

Thanks in advance,

Tony.

PS. I did find the following thread which is what I need to do, but the thread does not include details on how to get it to resize.
https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=resize&thread=1531506901#N1531575092

  Re: Resize a chart, I cannot figure out how to do it.
Posted by Peter Kwan on Oct-22-2021 13:14
Hi Tony,

You may already know that resizing a chart means to redraw a chart at a different size, so that it can show more or less details. You cannot resize it like resizing a photograph, because the x and y direction can be resized at different ratio.

First, you can create a drawChart function to draw and display the chart. The charting code must determine the chart size (from the window size), and then draw the chart according to the size. For example, instead of using a fixed width and height, your chart should use a width and height determined by the window size. Note that the window size can be unreasonable (eg. the user may resize the window to 1000 x 1 pixel), so your code must be able to handle all cases. For example, it may impose a lower limit on the chart width or height.

In the simplest case, you can just call drawChart in the window resize event handler.
The drawChart is supposed to redraw the chart at the current window size, so the chart should fit the resized window. However, for smoother operation, and to manage the case that multiple events can update the chart at almost the same time (such as a real-time chart that keeps updating, and a track cursor to update the chart whenever the mouse moves, etc), we suggest to update through the "ViewPortChanged" event, which has update rate control.

In the window resize event, your code can call wxChartViewer::updateViewPort

https://utelle.github.io/wxchartdir/docs/html/classwx_chart_viewer.html#aeb48e0323a8eff7e176060d972de9439

Then in the wxEVT_CHARTVIEWER_VIEWPORT_CHANGED message handler, you code can call drawChart to redraw the chart.

(Note: I am familiar with ChartDirector for MFC/Qt, but I have never used wxWidgets before.)

Regards
Peter Kwan

  Re: Resize a chart, I cannot figure out how to do it.
Posted by Tony on Oct-22-2021 16:00
Thanks. With the help of Ulrich Telle (wxChartDir), I managed to get it working.

I assumed that the ChartDirector control was a "live" window, I didn't realise you would need to rebuild the graph each time. I was trying to set the width/height of the existing chart and then call a redraw function.

I'm going to test some performance things next, Ulrich said performance was excellent, I just want to be certain though before full implementation.

All the best,

Tony.

  Re: Resize a chart, I cannot figure out how to do it.
Posted by BrunoVoisin on May-06-2023 00:15
Would you have some code example (C# WinForms) to resize while keeping all objects from the previous chart intact?  Can it cause issues when real time data is fed to the chart?
Thanks in advance

  Re: Resize a chart, I cannot figure out how to do it.
Posted by Peter Kwan on May-06-2023 04:50
Hi BrunoVoisin.

Would you mind to clarify what type of "resize" do you mean? Do you mean to create a chart that is larger or smaller than the original chart in terms of pixel width and height, but you want to display the same data in it?

Consider the following real time chart sample code:

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

In the sample code, in the drawChart function, the chart size and plot area size is hard coded. You can simply modify the code to use a variable size. In this case, if you change the variable, the chart will change size the next time drawChart function is called. The chart will have all the features of the original chart, since it is the same drawChart function except the size.

Best Regards
Peter Kwan

  Re: Resize a chart, I cannot figure out how to do it.
Posted by BrunoVoisin on May-06-2023 17:23
Thank you Peter
Shall definitely use Zooming and Scrolling now you pointed it out with a code example.
More basically, my question was about redrawing a chart after the container is resized.
Best,
Bruno

  Re: Resize a chart, I cannot figure out how to do it.
Posted by Peter Kwan on May-07-2023 13:36
Hi Bruno,

When the container is resize, in the resize event handler, you code need to determine what is the new chart size.

Note that there is no automatic way to resize the chart when the container resize. The container may contain many things, and they may resize differently. As an example, you can to resize the Windows File Explorer. You will find that the search box on the top left will not resize, while the address bar on the right side of the search box will resize. Also, the tree view on the right side will not resize, while the list view on the left will resize.

Also, certain things may have constraints when resizing. For example, a photograph must resize horizontally and vertically by the same ratio. If a user just make the container wider (but not taller), nothing will resize. Some kinds of chart must maintain aspect ratio too. For example, charts that may contain a picture (eg. as a background image ), polar chart, pie chart, certain contour charts, ... And to be useful as a chart, there may be a lower limit how the chart can be resized down. That's why you must determine the new chart size with your own code.

After determining the new chart size, you can call drawChart to redraw the chart. However, if you are using Real Time Zooming and Scrolling sample code, we suggest you to call winChartViewer1.updateViewPort(true, false). This would trigger the viewPortChanged event which in turn will call drawChart. We suggest this method because in a real time chart or in a chart with a programmable track cursor, many things will cause the chart to redraw in real time. The updateViewPort will consolidate all simultaneous update to make the redrawing smoother. Your drawChart routine should be designed to draw the chart at the sized determined by your code.

Best Regards
Peter Kwan

  Re: Resize a chart, I cannot figure out how to do it.
Posted by BrunoVoisin on May-08-2023 15:36
Thank you, Peter, for the clarifications.
Much appreciated.

  Re: Resize a chart, I cannot figure out how to do it.
Posted by MackenzieNewman on May-10-2023 21:08
Get a pointer to the diagram object. In the realtimesweep example, this is a variable m_c of type XYChart.
Use the setPlotArea method of the chart object to change the size of the graphic area. The setPlotArea method takes the coordinates of the top left corner (left, top) and bottom right corner (right, bottom) of the graphic area. You can set these values so that the graphic area occupies the entire available window:
int left = 0;
int top = 0;
int right = windowWidth; // Change windowWidth to your desired window width
int bottom = windowHeight; // Change windowHeight to the desired window height

m_c->setPlotArea(left, top, right, bottom);
Update the diagram to show the changes:
m_c->makeChart();
After performing these steps, the diagram should be modified so that it fills your application window. Note that you may also need to implement logic to update the size of the diagram when the application window is resized.