Click here to Skip to main content
12,403,948 members (66,545 online)
Click here to Skip to main content
Add your own
alternative version

Stats

154.5K views
40 bookmarked
Posted

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

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

Share

About the Author

JL Colson
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionHow to speed up display of MSchart graph using detach Pin
LRatna7-Jun-07 21:55
memberLRatna7-Jun-07 21:55 
QuestionIs Detach() really needed ? Pin
Yoavip18-Apr-07 2:23
memberYoavip18-Apr-07 2:23 
GeneralMSChart control display problem!! Pin
shinyhui13-Jul-06 18:51
membershinyhui13-Jul-06 18:51 
GeneralRe: MSChart control display problem!! Pin
Ananth.tm3-Nov-06 8:47
memberAnanth.tm3-Nov-06 8:47 
GeneralDialog wont open anymore Pin
Astrona20-Apr-05 15:15
memberAstrona20-Apr-05 15:15 
GeneralRe: Dialog wont open anymore Pin
Anonymous22-Sep-05 23:13
sussAnonymous22-Sep-05 23:13 
GeneralRe: Dialog wont open anymore Pin
ptitanic0713-Sep-06 5:48
memberptitanic0713-Sep-06 5:48 
GeneralSimple plotting of x-y values Pin
Krishna Seetharaman6-Mar-05 17:39
memberKrishna Seetharaman6-Mar-05 17:39 
Question.dll or .ocx needed??? Pin
DELCOURT5-Feb-04 22:46
memberDELCOURT5-Feb-04 22:46 
AnswerRe: .dll or .ocx needed??? Pin
vishuvp2-Mar-04 9:18
membervishuvp2-Mar-04 9:18 
GeneralRe: .dll or .ocx needed??? Pin
JabraJabra9-Aug-04 7:20
memberJabraJabra9-Aug-04 7:20 
GeneralRe: .dll or .ocx needed??? Pin
lokiz4-Mar-05 22:51
memberlokiz4-Mar-05 22:51 
QuestionHow to Draw 3D chart in VB.net Pin
The Last Action Hero8-Dec-03 0:12
memberThe Last Action Hero8-Dec-03 0:12 
Generalonline drawing on MSCHART Pin
annona8-Apr-03 23:50
memberannona8-Apr-03 23:50 
GeneralHi there a prob in compilation Pin
cemlouis16-Mar-03 5:40
membercemlouis16-Mar-03 5:40 
GeneralRe: Hi there a prob in compilation Pin
mussashi30-Jun-04 1:10
membermussashi30-Jun-04 1:10 
GeneralRe: Hi there a prob in compilation Pin
Lars795-Feb-05 5:45
memberLars795-Feb-05 5:45 
QuestionHow can I print this Mschart Pin
Anonymous3-Dec-02 1:41
sussAnonymous3-Dec-02 1:41 
AnswerRe: How can I print this Mschart Pin
Anonymous3-Dec-02 20:55
sussAnonymous3-Dec-02 20:55 
GeneralRe: How can I print this Mschart Pin
Qadddd4-Dec-02 11:32
memberQadddd4-Dec-02 11:32 
GeneralRe: How can I print this Mschart Pin
Qadddd16-Dec-02 2:36
memberQadddd16-Dec-02 2:36 
QuestionTo display the value in tooltips by placing mouse at a position? Pin
vcLearner19-May-02 20:31
membervcLearner19-May-02 20:31 
GeneralXY plot Pin
BubbaJoe12-Dec-01 2:35
memberBubbaJoe12-Dec-01 2:35 
GeneralRe: XY plot Pin
sridhar nallani13-Feb-02 8:52
membersridhar nallani13-Feb-02 8:52 
GeneralRe: XY plot Pin
Krishna Seetharaman6-Mar-05 17:29
memberKrishna Seetharaman6-Mar-05 17:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.160721.1 | Last Updated 28 Nov 2001
Article Copyright 2001 by JL Colson
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid