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

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

Comments and Discussions

 
QuestionHow to speed up display of MSchart graph using detach PinmemberLRatna7-Jun-07 21:55 
QuestionIs Detach() really needed ? PinmemberYoavip18-Apr-07 2:23 
GeneralMSChart control display problem!! Pinmembershinyhui13-Jul-06 18:51 
GeneralRe: MSChart control display problem!! PinmemberAnanth.tm3-Nov-06 8:47 
GeneralDialog wont open anymore PinmemberAstrona20-Apr-05 15:15 
GeneralRe: Dialog wont open anymore PinsussAnonymous22-Sep-05 23:13 
GeneralRe: Dialog wont open anymore Pinmemberptitanic0713-Sep-06 5:48 
GeneralSimple plotting of x-y values PinmemberKrishna Seetharaman6-Mar-05 17:39 
Question.dll or .ocx needed??? PinmemberDELCOURT5-Feb-04 22:46 
AnswerRe: .dll or .ocx needed??? Pinmembervishuvp2-Mar-04 9:18 
GeneralRe: .dll or .ocx needed??? PinmemberJabraJabra9-Aug-04 7:20 
GeneralRe: .dll or .ocx needed??? Pinmemberlokiz4-Mar-05 22:51 
QuestionHow to Draw 3D chart in VB.net PinmemberThe Last Action Hero8-Dec-03 0:12 
Generalonline drawing on MSCHART Pinmemberannona8-Apr-03 23:50 
GeneralHi there a prob in compilation Pinmembercemlouis16-Mar-03 5:40 
GeneralRe: Hi there a prob in compilation Pinmembermussashi30-Jun-04 1:10 
GeneralRe: Hi there a prob in compilation PinmemberLars795-Feb-05 5:45 
QuestionHow can I print this Mschart PinsussAnonymous3-Dec-02 1:41 
AnswerRe: How can I print this Mschart PinsussAnonymous3-Dec-02 20:55 
GeneralRe: How can I print this Mschart PinmemberQadddd4-Dec-02 11:32 
GeneralRe: How can I print this Mschart PinmemberQadddd16-Dec-02 2:36 
QuestionTo display the value in tooltips by placing mouse at a position? PinmembervcLearner19-May-02 20:31 
GeneralXY plot PinmemberBubbaJoe12-Dec-01 2:35 
GeneralRe: XY plot Pinmembersridhar nallani13-Feb-02 8:52 
GeneralRe: XY plot PinmemberKrishna Seetharaman6-Mar-05 17: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 | Mobile
Web02 | 2.8.140827.1 | Last Updated 28 Nov 2001
Article Copyright 2001 by JL Colson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid