C++ MFC MSChart
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: C++ MFC MSChart

  1. #1
    Join Date
    Oct 2005
    Posts
    8

    C++ MFC MSChart

    I am a beginner in C++.
    I have tried to implement a chart from a MFC dialog box by using MSChart.
    I didn't find any tutorial to learn how to link data with a MSChart and how to handle basic implementation.
    Is it because MSChart is only used in VB?

    Thanks for any help

    Kropcheck...

  2. #2
    Join Date
    Apr 1999
    Posts
    3,585

    Re: C++ MFC MSChart

    Since MSChart is an ActiveX control, it can be used with any language that speaks COM, including C++. Take a look at this article . It should help get you started.
    Gort...Klaatu, Barada Nikto!

  3. #3
    Join Date
    Oct 2005
    Posts
    8

    Re: C++ MFC MSChart

    Thanks for this quick reply, it is always nice to get support by advance user.

    I have tried this tutorial (even before sending my first mail) which seems fairly simple but nevertheless I had a problem to access to the following function:

    m_Chart.SetChartData(saRet.Detach());

    "SetChartData" doesn't belong to the CChart class when "Refresh" is perfectly recognised.

    with -> class CChart : public CWnd
    -> CChart m_Chart;

    I went through all the class members/functions of m_Chart but none looks like "SetChartData" or BindData. There is probably more than one way to link data with the chart. I am not used to too much advance variable type but I am opened to any possibilities.

    Kropchek

    PS: By the way, the problem could come from the version of MSChart: Microsoft Chart 6.0 (SP4) OLEDB with Microsoft Visual Studio C++.NET 2002.

  4. #4
    Join Date
    Apr 1999
    Posts
    3,585

    Re: C++ MFC MSChart

    Have you followed the steps to add the chart object to your dialog? The object should be of type CMSChart, not CWnd.
    Gort...Klaatu, Barada Nikto!

  5. #5
    Join Date
    Oct 2005
    Posts
    8

    Re: C++ MFC MSChart

    I think I did a stupid mistake when I used the "Variable Wizard", by mistake I modified the "Variable type". So by default the Wizard created a CWnd type class instead of CMSChart.

    I hope now everything will go OK.
    More news in a few minutes.

    Thanks for your patience.

    Kropcheck... which thinks that these wizards are great but never trusts them even when no error appears.

  6. #6
    Join Date
    Oct 2005
    Posts
    8

    Re: C++ MFC MSChart

    Obviously the wizard which create the variable doesn't work properly.
    Each time I create a variable linked to the component ID_MSCHART, I end up with a new class derivated from CWnd and not CMSChart.

    I have tried to change manually "class CChart : public CWnd" to "class CChart : public CMSChart" but CMSChart is undefined as class.

    Should I import the library as "#include Mschart.h" somewhere or could it be a problem of .dll (which seems strange because I managed to add MSChart in the toolbox of component).

    Kropcheck

  7. #7
    Join Date
    Apr 1999
    Posts
    3,585

    Re: C++ MFC MSChart

    If you added the control through the resource editor, it should have generated a wrapper class for you. The wrapper class will contain the definition for the CMSChart object. You'll need to make sure to #include the CMSChart header where your object is defined.
    Gort...Klaatu, Barada Nikto!

  8. #8
    Join Date
    Oct 2005
    Posts
    8

    Re: C++ MFC MSChart

    1) I checked if the wizard wrote "#include mschart.h" (header file) where the object is defined (in the dialog box class).
    The problem doesn't come from there because the variable m_Chart is valid when I use it as:

    //m_Chart.SetChartData(saRet.Detach()); /*doesn't work*/
    m_Chart.Refresh; /*works and compiles*/


    2) Here is the following error I still get:
    error C2039: 'SetChartData' : is not a member of 'CMSChart'


    3) Perhaps you will guess easily the error from the declaration of the class CMSChart described here :

    class CMSChart : public CWnd
    {
    protected:

    DECLARE_DYNCREATE(CMSChart)

    public:

    CLSID const& GetClsid()

    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL)

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL)

    public:

    enum
    {
    (...many...)
    }

    public:

    BOOL get_AutoIncrement()
    void put_AutoIncrement(BOOL newValue)
    BOOL get_RandomFill()
    void put_RandomFill(BOOL newValue)
    long get_chartType()
    void put_chartType(long newValue)
    short get_Column()
    void put_Column(short newValue)
    short get_ColumnCount()
    void put_ColumnCount(short newValue)
    CString get_ColumnLabel()
    void put_ColumnLabel(LPCTSTR newValue)
    short get_ColumnLabelCount()
    void put_ColumnLabelCount(short newValue)
    short get_ColumnLabelIndex()
    void put_ColumnLabelIndex(short newValue)
    CString get_Data()
    void put_Data(LPCTSTR newValue)
    CString get_FootnoteText()
    void put_FootnoteText(LPCTSTR newValue)
    BOOL get_Repaint()
    void put_Repaint(BOOL newValue)
    short get_Row()
    void put_Row(short newValue)
    short get_RowCount()
    void put_RowCount(short newValue)
    CString get_RowLabel()
    void put_RowLabel(LPCTSTR newValue)
    short get_RowLabelCount()
    void put_RowLabelCount(short newValue)
    short get_RowLabelIndex()
    void put_RowLabelIndex(short newValue)
    short get_SeriesColumn()
    void put_SeriesColumn(short newValue)
    long get_SeriesType()
    void put_SeriesType(long newValue)
    BOOL get_ShowLegend()
    void put_ShowLegend(BOOL newValue)
    long get_DrawMode()
    void put_DrawMode(long newValue)
    long get_BorderStyle()
    void put_BorderStyle(long newValue)
    BOOL get_Enabled()
    void put_Enabled(BOOL newValue)
    long get_hWnd()
    LPDISPATCH get_Title()
    LPDISPATCH get_Footnote()
    CString get_TitleText()
    void put_TitleText(LPCTSTR newValue)
    BOOL get_Stacking()
    void put_Stacking(BOOL newValue)
    long get_TextLengthType()
    void put_TextLengthType(long newValue)
    BOOL get_AllowSelections()
    void put_AllowSelections(BOOL newValue)
    BOOL get_AllowSeriesSelection()
    void put_AllowSeriesSelection(BOOL newValue)
    BOOL get_AllowDynamicRotation()
    void put_AllowDynamicRotation(BOOL newValue)
    short get_ActiveSeriesCount()
    LPDISPATCH get_Backdrop()
    LPDISPATCH get_Legend()
    LPDISPATCH get_DataGrid()
    LPDISPATCH get_Plot()
    BOOL get_AllowDithering()
    void put_AllowDithering(BOOL newValue)
    BOOL get_DoSetCursor()
    void put_DoSetCursor(BOOL newValue)
    BOOL get_Chart3d()
    VARIANT get_ChartData()
    void put_ChartData(VARIANT newValue)
    long get_Chart()
    long get_MousePointer()
    void put_MousePointer(long newValue)
    void AboutBox()
    void Refresh()
    void EditPaste()
    void EditCopy()
    void Layout()
    void ToDefaults()
    void SelectPart(short part, short index1, short index2, short index3, short index4)
    void GetSelectedPart(short * part, short * index1, short * index2, short * index3, short * index4)
    void TwipsToChartPart(long xVal, long yVal, short * part, short * index1, short * index2, short * index3, short * index4)
    long get_OLEDragMode()
    void put_OLEDragMode(long newValue)
    long get_OLEDropMode()
    void put_OLEDropMode(long newValue)
    void OLEDrag();
    LPUNKNOWN get_DataSource();
    void putref_DataSource(LPUNKNOWN newValue);
    CString get_DataMember();
    void put_DataMember(LPCTSTR newValue);
    };

    Thanks for your help...

    Kropcheck

  9. #9
    Join Date
    Apr 1999
    Posts
    3,585

    Re: C++ MFC MSChart

    I've never used MSChart, but, from looking at what you posted, it appears that you need to use the put_ChartData() method. This is probably due to the fact that C++ is hosting a visual basic control. It looks like the C++ wrapper uses the put_ChartData() method instead.
    Gort...Klaatu, Barada Nikto!

  10. #10
    Join Date
    Oct 2005
    Posts
    8

    Talking Re: C++ MFC MSChart

    Great, it works... and looks so easy now!!!

    I wonder why I didn't find the solution by myself.
    Thanks for this help and for the time spent.

    I will surely face other problems with MSChart but now I am on the right way.

    See you perhaps on this thread or another one.


    Kropcheck, the frenchy modelling chemist of Glasgow (UK)

  11. #11
    Join Date
    Oct 2005
    Posts
    8

    Question Re: C++ MFC MSChart

    From 2d-line-chart (by column, no real Y axis)
    To 2d chart XY (scatter and line)


    Until now I have been lucky because I have worked with a set data which contains for the y axis the values: 0,1,2,3,4. So they could be considered as column... but "series type 2d line chart" doesn't look as good as "series type 2d XY chart".
    I have tried to modified the following code to load the XY data in the 2d scatter chart but without success. Any idea how to do it because I feel lost without any documentation on the subject?


    COleSafeArray saRet;
    DWORD numElements[] = {10, 10}; // 10x10
    .
    // Create the safe-array...
    saRet.Create(VT_R8, 2, numElements);
    .
    // Initialize it with values...
    long index[2];
    for(index[0]=0; index[0]<10; index[0]++)
    {
    .for(index[1]=0; index[1]<10; index[1]++)
    .{
    ...double val = index[0] + index[1]*10;
    ...saRet.PutElement(index, &val);
    .}
    }
    .
    // Return the safe-array encapsulated in a VARIANT...
    m_Chart.put_ChartData(saRet.Detach());


    Kropcheck

  12. #12
    Join Date
    Apr 1999
    Posts
    3,585

    Re: C++ MFC MSChart

    Sorry, I've never used the MSChart control. Perhaps you can find what you're looking for here .
    Gort...Klaatu, Barada Nikto!

  13. #13
    Join Date
    Oct 2005
    Posts
    8

    Wink Re: C++ MFC MSChart

    In fact with C++.NET platform, there are two ways for accessing to the properties of components. In the case of MSChart, each of them allows to change different properties as type of chart. So if you can't modify one of the properties change of property window.

    So now it works approximativly well even if I don't know how to change the axes scale. For some reason x and y have always the same scale.

    Kropcheck Le Nantais

  14. #14
    Join Date
    Apr 2013
    Posts
    2

    Re: C++ MFC MSChart

    Hi All,

    I am able to draw single line chart on mschart in VC++, but
    when I tried to draw multiple chart (on a single graph), it only displays last one....
    How to overcome to problem. If any such documents exists, plz provide the same...

    Thnx

    Vipin

  15. #15
    Join Date
    Apr 2013
    Posts
    5

    Thumbs up Re: C++ MFC MSChart

    Hi, you mean multiple charts or multiple lines on one chart?

    if you're talking about multiple lines, thats simple, here's an example of multiple lines (2) in one chart:

    Code:
            COleSafeArray saRet;
    
    	DWORD numElements[] = {360, 4}; 
    
    	saRet.Create(VT_R8, 2, numElements);
    
    	long index[2] = { 0 , 0 };
    
    	double value = 0;
    	double vx = 0;
    
    	for(long i = 0; i < 360; i++)
    	{
    		// curve 1
    		index[1] = 0;
    
    		vx = i;
    
    		saRet.PutElement(index, &vx);
    
    		index[1] = 1;
    
    		value = sin(i * 0.35);
    
    		saRet.PutElement(index, &value);
    
    		// curve 2
    		index[1] = 2;
    
    		saRet.PutElement(index, &vx);
    
    		index[1] = 3;
    
    		value = - sin(i * 0.35);
    
    		saRet.PutElement(index, &value);
    
    
    		index[0]++;
    	}
    
    	m_chart.put_ChartData(saRet.Detach());
    Cheers

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center