Hello again with this problem!
The problem seems to be solved alright until I found another thick wall.
First to mention, we have 2 charts. Each chart has number of series. One of chart has a series which contains null value.
Now, please have a look at this piece of code.
Code: Select all
BOOL CTeeFilesView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
return FALSE;
//WS_CHILD | WS_VISIBLE
//Create TeeChart - sized to Client window afterwards with 'OnSize'
if (!m_Chart1.Create(lpszClassName,
"",
dwStyle,
CRect(0,0,50,50),
this,
IDC_TCHART1,
pContext))
return FALSE;
DeltaRot = 4;
DeltaElev = 3;
DeltaZoom = 5;
m_Chart1.SetVisible(true);
m_Chart1.ClearChart();
m_Chart1.AddSeries(scBar);
m_Chart1.AddSeries(scBar);
m_Chart1.AddSeries(scBar);
m_Chart1.Series(0).GetAsBar().SetMultiBar(mbStacked);
m_Chart1.Series(0).AddNull("");
m_Chart1.Series(0).AddNull("");
m_Chart1.Series(1).AddNull("");
m_Chart1.Series(1).AddNull("");
m_Chart1.Series(2).AddNull("");
m_Chart1.Series(2).AddNull("");
m_Chart1.Series(0).SetPointLabel(0, "aaa");
m_Chart1.Series(0).SetPointValue(0, 10);
m_Chart1.Series(0).SetPointColor(0, RGB(244,0,39));
m_Chart1.Series(0).SetPointLabel(1, "bbb");
m_Chart1.Series(0).SetPointValue(1, 20);
m_Chart1.Series(0).SetPointColor(1, RGB(244,0,39));
m_Chart1.Series(1).SetPointValue(0, 15);
m_Chart1.Series(1).SetPointLabel(0, "aaa");
m_Chart1.Series(1).SetPointColor(0, RGB(24,0,239));
m_Chart1.Series(1).SetPointValue(1, 30);
m_Chart1.Series(1).SetPointLabel(1, "bbb");
m_Chart1.Series(1).SetPointColor(1, RGB(24,0,239));
m_Chart1.Series(2).SetPointValue(1, 14);
m_Chart1.Series(2).SetPointLabel(1, "bbb");
m_Chart1.Series(2).SetPointColor(1, RGB(0,130,39));
double BarTop, BarBottom, ypos, moffset;
int seriesCnt = m_Chart1.GetSeriesCount();
m_Chart1.GetEnvironment().InternalRepaint();
for(int i=0; i<seriesCnt; i++) {
int num = m_Chart1.Series(i).GetCount();
for(int j=0; j<num; j++) {
BarTop = m_Chart1.Series(i).CalcYPos(j);
if(i > 0)
BarBottom = m_Chart1.Series(i-1).CalcYPos(j);
else
BarBottom = m_Chart1.Series(i).CalcYPosValue(0);
if(m_Chart1.Series(i).IsNull(j)) {
continue;
}
m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).SetCustom(TRUE);
ypos=BarBottom-(50/100.0)*(BarBottom-BarTop);
moffset = m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).GetHeight();
ypos -= moffset;
ypos += (moffset/2);
m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).GetLeftTop().SetY(ypos);
}
}
m_Chart1.GetExport().SaveToFile("C:\\aaaa.tmp");
return true;
}
Since this code came from your example, I am pretty sure you recognize this well.
Basically, the problem is the chart program being dead.
This occurs when.....
1. "m_Chart1.Series(i)" is null. (with no if block inside the for loop)
This case, the program crashes when ,m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).SetCustom(TRUE);,
this line is executing.
2. So, if I check the nullity of "m_Chart1.Series(i)", and put "continue" like how thigs are done above.
This case, the program crashes when ,m_Chart1.GetExport().SaveToFile("C:\\aaaa.tmp");, line is executing.
Asking about this in the first place was because we have a customer who want us to show this function on chart. Hence, having this problem would cause a lot of trouble.
I hope you can find the solution to this. Thanks.