MSChart sample

I am trying to use the MSChart control in my VC project. It is difficult for me to start as there are no sample source code in the help file. May I know anyone out there can give me a sample of how to plot a line graph with two series of data? For example, I have income and expense for a company for years 1997, 1998, 1999. I would like to have two lines on the graph, one showing the income and the other line show the expense.
Thank you very much for your help in advance. :) Cheers!
tszwangAsked:
Who is Participating?
 
V_BapatConnect With a Mentor Commented:
Hi
Assuming that you have already added MS Chart control in your dialog/formview, you have to do this:

First you have to select the row and column in which you have to set the data. Here is an example:

for(short i = 1; i <= m_chart.GetRowCount(); i++)
{
     for(short j = 1; j <= m_chart.GetColumnCount(); j++)
     {
          m_chart.SetRow(i);
          m_chart.SetColumn(j);
          strValue.Format("%d", j * 5);
         
          m_chart.SetData(strValue);
     }
}

Here, m_chart is the member variable for the chart control.

Hope this helps. If you have further questions, feel free to ask.

Vicky
0
 
ToronadoCommented:
Hi tszwang,

Do you have problems inserting the MSChart control in your project, or with using the control?

Regards,
 Toronado
0
 
tszwangAuthor Commented:
I have problem using it. Can you help me? :)
0
 
tszwangAuthor Commented:
Adjusted points to 200
0
 
V_BapatCommented:
Hi
Suppose you have added the chart control to CFormView. In OnInitialUpdate() add the following:

m_chart.SetColumnCount(3);  // No of columns
m_chart.SetRowCount(2);     // No of rows

This will give you a chart with 3 columns and 2 rows. To set data first select row and column and then set data. For example,

m_chart.SetColumn(1);
m_chart.SetRow(1);
m_chart.SetData("20");  // R1C1 = 20

m_chart.SetColumn(2);
m_chart.SetRow(2);
m_chart.SetData("40");  // R2C2 = 40

m_chart.SetColumn(3);
m_chart.SetRow(1);
m_chart.SetData("60");  // R1C3 = 60
0
All Courses

From novice to tech pro — start learning today.