I do not have the VC++ v6 IDE. I only have a license for VS 2005 Pro Edition.
When I create an MFC dialog-based project and add a TeeChart control, no wrapper
classes are created. However once I add a control variable (I named it m_chart)
for the TChart control, the wizard creates one new class named CTchart1, which
inherits CWnd.
Note that when adding the TChart control variable, the ctor for the parent
dialog is modified as follows:
Code: Select all
CTChartDlgDlg::CTChartDlgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTChartDlgDlg::IDD, pParent)
, m_chart(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
Notice m_chart(0) in the initialization list. This is wrong because there is no
ctor for CTchart1 that takes an int. Can you guys fix that? I see in other posts
that this has caused some trouble for other people as well.
Attempting to use the wizard-created CTchart1 class for my chart object, I'm
forced into casting hell. And ultimately, I end up using the same classes that
caused the original problem, and consequently, I still get the "Invalid class
typecast" error.
Code: Select all
void CTChartDlgDlg::InitializeTChart()
{
string pre_label("label");
stringstream label;
string pre_series("series");
stringstream series;
unsigned long color;
for(int i=0;i<3;i++) {
m_chart.AddSeries(CTchart1::scPoint);
series.str("");
series << pre_series << "_" << i;
((CSeries)m_chart.Series(i)).SetTitle(series.str().c_str());
for(int j=0;j<10;j++) {
label.str("");
label << pre_label << "_" << j;
color = ((CSeries)m_chart.Series(i)).GetColor();
((CSeries)m_chart.Series(i)).Add(j+i, label.str().c_str(), color);
}
}
// Everything works fine up to here and the chart displays the data points as expected.
// !!! This next call is where the "Invalid class typecast" message is generated.
CLineSeries a_line_series = ((CSeries)m_chart.Series(0)).GetAsLine();
}
Is there another way for me to do this so that I can retrieve a CLineSeries object?