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.