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

Message ListMessage List     Post MessagePost Message

  Move ChartControl c++
Posted by Alejandro on Feb-27-2018 17:46
Hello.
I am coding a MFC GUI application.
I have a CFormView derived class inside of which I have some ChartControls.
This CFormView is set inside a docking pane which is a dockable, resizable framed window. The user can pick the pane from its corner and drag it producing a resizing.
I´ve just arrived to Chart Director and I need to relocate the Chart Control inside that CFormView.
Making use of ChardDirector samples, in fact mfcdemo, I found that, in order to insert a Chart, a Picture Control set up as Bitmap must be used as a resource. I´ve done so and everything is Ok. Later I use a dynamic allocation (new) to a XYChart by giving the width and height of the control.
My problem is that I cannot find any way to change the location of my Chart Control on the form. I looked inside the documentation and always found functions to get the height, width, X offset and Y offset. Even there is a function inside BaseChart to set the Size, but there is nothing like "SetPosition" or "SetXPos", "SetYPos" or anything like this.
I am talking about the changing of the overall position of the XYChart control inside the form, not the location and dimensions of the PlotArea inside it. It is just to get the control to another location with all its contents.
I then tried to use the window of my control as set inside DoDataExchange function, but I cannot use functions as CWnd::GetWindowRect or similar as BaseChart, XYChart does not seem to derive from CWnd, so I cannot get the hWnd.
I need to change the location of the control because I have several of them inside a resizable pane and I need them to adjust the size to the current size of the pane if the user drags the pane from the border and changes its size. I do the resizing of ChartControls inside the OnSize function of the CFormView, but when the sizes of the charts are changed they must be relocated as well in order to maintain their relative positions.
Any hint should be very appreciated.
Thanks.
Alejandro.

  Re: Move ChartControl c++
Posted by Peter Kwan on Feb-28-2018 06:45
Hi Alejandro,

The charts in ChartDirector are displayed using a CChartViewer control. The CChartViewer control is a CStatic control, which is derived from CWnd. You can move the CChartViewer control just like any standard MFC control. For example, you can use CWnd::MoveWindow to move it. For example:

m_ChartViewer.MoveWindow(x, y, width, height);

See:

https://msdn.microsoft.com/en-us/library/aa249441(v=vs.60).aspx


ChartDirector comes with a sample project called "mfcdemo". (When you try the MFC Visual Studio solution in "ChartDirector/mfcdemo/mfcdemo.sln", you can see many projects, and one of them is also called "mfcdemo".) In that sample code, the CChartViewer controls can move around. For example, you can try the "2D Donut Shading" and it should display 6 charts. When you resize the window, the chart can "flow" around. (Try reducing the window size. The 6 charts should warp into multiple lines.) In the sample code, it is using CWnd::MoveWindow to dynamically move the CChartViewer.


In our sample code, the CChartViewer is created as a dialog resource in the resource editor. However, this is just an example, and you can also dynamically create CChartViewer in code using the same method as creating any MFC control. For exmaple:

CRect rectDummy;
rectDummy.SetRectEmpty();
const DWORD dwStyle = WS_CHILD | WS_VISIBLE | SS_BITMAP | SS_NOTIFY;

m_CChartViewer.Create(NULL, dwStyle, rectDummy, this, IDC_ChartViewer);

See:

https://msdn.microsoft.com/en-us/library/0yhc9kx4.aspx


Hope this can help.

Regards
Peter Kwan