Click here to Skip to main content
Licence 
First Posted 27 Nov 2001
Views 131,201
Bookmarked 37 times

Passing an Array of Values to the Visual C++ MSChart OCX

By | 27 Nov 2001 | Article
A step by step guide to setting the values in the MSChart control.

Introduction

This is a step by step guide to setting the values in the MSChart control using an array of values.

Step 1 : Creating the Project

Start Visual C++ en create a simple dialog based application labeled "Graph"

Step 2 : Add the MSChart OCX to Your Project

Select "project menu" option and select "Components and contols" and then choose the MSChart component en click "add"

Step 3 : Add the MSChart OCX to Your Dialog

Select resources view tab en open the main dialog (It’s a simple dialog based application). Drop the OCX on your dialog.

Now, label your Chart "IDC_MSCAHRT1"

Now, choose menu option "Classwizard" to create a member variable of your chart labeled "m_Chart"

Step 4: Add the Code

Now add a button labeled "Go" to your dialog. Double click it to edit the code and add the following code in the On_Go function:
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.SetChartData(saRet.Detach());

m_Chart.Refresh;          

Step 5: Building and Running the Application

Build and execute your app, then click the "Go" button. Here is the result:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

JL Colson



Belgium Belgium

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to speed up display of MSchart graph using detach PinmemberLRatna21:55 7 Jun '07  
QuestionIs Detach() really needed ? PinmemberYoavip2:23 18 Apr '07  
why do we need to use:
 
saRet.Detach()
 
doesn't that chart keep a copy of the data ?
can't it cause a memory leak ?
 

Yoav

GeneralMSChart control display problem!! Pinmembershinyhui18:51 13 Jul '06  
GeneralRe: MSChart control display problem!! PinmemberAnanth.tm8:47 3 Nov '06  
GeneralDialog wont open anymore PinmemberAstrona15:15 20 Apr '05  
GeneralRe: Dialog wont open anymore PinsussAnonymous23:13 22 Sep '05  
GeneralRe: Dialog wont open anymore Pinmemberptitanic075:48 13 Sep '06  
GeneralSimple plotting of x-y values PinmemberKrishna Seetharaman17:39 6 Mar '05  
Question.dll or .ocx needed??? PinmemberDELCOURT22:46 5 Feb '04  
AnswerRe: .dll or .ocx needed??? Pinmembervishuvp9:18 2 Mar '04  
GeneralRe: .dll or .ocx needed??? PinmemberJabraJabra7:20 9 Aug '04  
GeneralRe: .dll or .ocx needed??? Pinmemberlokiz22:51 4 Mar '05  
QuestionHow to Draw 3D chart in VB.net PinmemberThe Last Action Hero0:12 8 Dec '03  
Generalonline drawing on MSCHART Pinmemberannona23:50 8 Apr '03  
GeneralHi there a prob in compilation Pinmembercemlouis5:40 16 Mar '03  
GeneralRe: Hi there a prob in compilation Pinmembermussashi1:10 30 Jun '04  
GeneralRe: Hi there a prob in compilation PinmemberLars795:45 5 Feb '05  
QuestionHow can I print this Mschart PinsussAnonymous1:41 3 Dec '02  
AnswerRe: How can I print this Mschart PinsussAnonymous20:55 3 Dec '02  
GeneralRe: How can I print this Mschart PinmemberQadddd11:32 4 Dec '02  
GeneralRe: How can I print this Mschart PinmemberQadddd2:36 16 Dec '02  
QuestionTo display the value in tooltips by placing mouse at a position? PinmembervcLearner20:31 19 May '02  
GeneralXY plot PinmemberBubbaJoe2:35 12 Dec '01  
GeneralRe: XY plot Pinmembersridhar nallani8:52 13 Feb '02  
GeneralRe: XY plot PinmemberKrishna Seetharaman17:29 6 Mar '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 28 Nov 2001
Article Copyright 2001 by JL Colson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid