Click here to Skip to main content
Click here to Skip to main content

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

, 27 Nov 2001
Rate this:
Please Sign up or sign in to vote.
A step by step guide to setting the values in the MSChart control.
<!-- Main HTML starts here -->


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...



Step 5: Building and Running the Application

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


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
No Biography provided

Comments and Discussions

QuestionHow to speed up display of MSchart graph using detach PinmemberLRatna7-Jun-07 22:55 
QuestionIs Detach() really needed ? PinmemberYoavip18-Apr-07 3:23 
GeneralMSChart control display problem!! Pinmembershinyhui13-Jul-06 19:51 
GeneralRe: MSChart control display problem!! PinmemberAnanth.tm3-Nov-06 9:47 
GeneralDialog wont open anymore PinmemberAstrona20-Apr-05 16:15 
GeneralRe: Dialog wont open anymore PinsussAnonymous23-Sep-05 0:13 
GeneralRe: Dialog wont open anymore Pinmemberptitanic0713-Sep-06 6:48 
GeneralSimple plotting of x-y values PinmemberKrishna Seetharaman6-Mar-05 18:39 
Question.dll or .ocx needed??? PinmemberDELCOURT5-Feb-04 23:46 
AnswerRe: .dll or .ocx needed??? Pinmembervishuvp2-Mar-04 10:18 
GeneralRe: .dll or .ocx needed??? PinmemberJabraJabra9-Aug-04 8:20 
GeneralRe: .dll or .ocx needed??? Pinmemberlokiz4-Mar-05 23:51 
QuestionHow to Draw 3D chart in PinmemberThe Last Action Hero8-Dec-03 1:12 
Generalonline drawing on MSCHART Pinmemberannona9-Apr-03 0:50 
GeneralHi there a prob in compilation Pinmembercemlouis16-Mar-03 6:40 
GeneralRe: Hi there a prob in compilation Pinmembermussashi30-Jun-04 2:10 
GeneralRe: Hi there a prob in compilation PinmemberLars795-Feb-05 6:45 
QuestionHow can I print this Mschart PinsussAnonymous3-Dec-02 2:41 
AnswerRe: How can I print this Mschart PinsussAnonymous3-Dec-02 21:55 
GeneralRe: How can I print this Mschart PinmemberQadddd4-Dec-02 12:32 
GeneralRe: How can I print this Mschart PinmemberQadddd16-Dec-02 3:36 
QuestionTo display the value in tooltips by placing mouse at a position? PinmembervcLearner19-May-02 21:31 
GeneralXY plot PinmemberBubbaJoe12-Dec-01 3:35 
GeneralRe: XY plot Pinmembersridhar nallani13-Feb-02 9:52 
GeneralRe: XY plot PinmemberKrishna Seetharaman6-Mar-05 18:29 

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.

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