📄 chartctrl.cpp
字号:
}
return;
}
/************************************************************************************************/
/* */
/* Function: CChartCtrl::UpdateWindow() */
/* */
/* Purpose : updates all chart window components and forces a complete redraw via a forced */
/* WM_SIZE message */
/* */
/* Inputs : NONE */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 7JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 7JUN02 initial version */
/* */
/************************************************************************************************/
void CChartCtrl::UpdateWindow() {
//setting the styles causes some attributes to be adjusted immediately
//let's reset them now and cause a refresh this way...
SetAxisStyleX(GetAxisStyleX());
SetAxisStyleY(GetAxisStyleY());
m_wndHeaderWnd.UpdateWindow();
m_wndFooterWnd.UpdateWindow();
m_wndLegendWnd.UpdateWindow();
m_wndChartWnd.UpdateWindow();
m_wndChartWnd.DrawChart();
//force OnSize() to be called for the whole control
//sometimes not everything is drawn correctly the first time
CRect Rect;
GetClientRect(&Rect);
SendMessage(WM_SIZE, 0, MAKELPARAM(Rect.Width(), Rect.Height()));
}
/************************************************************************************************/
/* */
/* Function: CChartCtrl::Invalidate() */
/* */
/* Purpose : invalidates all chart window components and forces a complete redraw via a forced */
/* WM_SIZE message */
/* */
/* Inputs : BOOL bErase -> TRUE if an erase operation should take place */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 7JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 7JUN02 initial version */
/* */
/************************************************************************************************/
void CChartCtrl::Invalidate(BOOL bErase/*=TRUE*/) {
m_wndHeaderWnd.Invalidate(bErase);
m_wndFooterWnd.Invalidate(bErase);
m_wndLegendWnd.Invalidate(bErase);
m_wndChartWnd.Invalidate(bErase);
if (bErase) {
//force OnSize() to be called for the whole control
//sometimes not everything is drawn correctly the first time
CRect Rect;
GetClientRect(&Rect);
SendMessage(WM_SIZE, 0, MAKELPARAM(Rect.Width(), Rect.Height()));
}
return;
}
/************************************************************************************************/
/* */
/* Function: CChartCtrl::SetHeaderText() */
/* */
/* Purpose : called to set the text of one of the three fields of the header */
/* */
/* Inputs : CHART_WINDOW_POSITION Position -> field to set */
/* CString& Text -> text to set */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 7JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 7JUN02 initial version */
/* */
/************************************************************************************************/
void CChartCtrl::SetHeaderText(CHART_WINDOW_POSITION Position, CString& Text) {
switch (Position) {
case eLEFT :
m_wndHeaderWnd.SetLText(Text);
break;
case eMIDDLE :
m_wndHeaderWnd.SetMText(Text);
break;
case eRIGHT :
m_wndHeaderWnd.SetRText(Text);
}
return;
}
/************************************************************************************************/
/* */
/* Function: CChartCtrl::SetFooterText() */
/* */
/* Purpose : called to set the text of one of the three fields of the header */
/* */
/* Inputs : CHART_WINDOW_POSITION Position -> field to set */
/* CString& Text -> text to set */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 7JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 7JUN02 initial version */
/* */
/************************************************************************************************/
void CChartCtrl::SetFooterText(CHART_WINDOW_POSITION Position, CString& Text) {
switch (Position) {
case eLEFT :
m_wndFooterWnd.SetLText(Text);
break;
case eMIDDLE :
m_wndFooterWnd.SetMText(Text);
break;
case eRIGHT :
m_wndFooterWnd.SetRText(Text);
}
return;
}
/************************************************************************************************/
/* */
/* Function: CChartCtrl::AddDataPoint() */
/* */
/* Purpose : called to add a data point to the chart */
/* */
/* Inputs : CDataPoint* pDataPoint -> data point to add */
/* int nDataSeries -> series to which this data point belongs to */
/* */
/* Outputs : BOOL <- TRUE if a data point was removed from the series, FALSE otherwise, can */
/* only happen when in strip chart mode */
/* */
/* Author : Scott Pelger Date Created: 7JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 7JUN02 initial version */
/* Scott Pelger 27JUN02 don't add a point legend if chart type is any strip chart */
/* */
/************************************************************************************************/
BOOL CChartCtrl::AddDataPoint(CDataPoint* pDataPoint, int nDataSeries/*=0*/) {
//if we are data series 0 and not a strip chart then add a point legend item
if (!nDataSeries&&
!(TYPE_STRIP_CHART ==m_eChartType||
TYPE_STRIP_CHART_FILLED==m_eChartType))
m_wndLegendWnd.AddPointItem(pDataPoint->m_sCaption, pDataPoint->m_crColor);
BOOL bRemoved = m_wndChartWnd.m_DataSeriesArray.AddDataPoint(pDataPoint, nDataSeries);
//if we are data series 0 and not a strip chart then remove a point legend item if a point
//was removed, kind of redundant of a check since a point can only be automatically
//removed if the chart style is any strip type
if (!nDataSeries&&bRemoved&&
!(TYPE_STRIP_CHART ==m_eChartType||
TYPE_STRIP_CHART_FILLED==m_eChartType))
m_wndLegendWnd.RemovePointItem(0);
m_wndChartWnd.NotifyRemovedDataPoint(bRemoved);
return bRemoved;
}
void CChartCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) {
CWnd* pWnd = GetParent();
if (pWnd) {
//convert the point coordinate to that of the parents
ClientToScreen(&point);
pWnd->ScreenToClient(&point);
LPARAM lParam(point.y<<16);
lParam += point.x;
pWnd->SendMessage(WM_LBUTTONDBLCLK, (WPARAM)nFlags, lParam);
}
return;
}
void CChartCtrl::OnRButtonDown(UINT nFlags, CPoint point) {
CWnd* pWnd = GetParent();
if (pWnd) {
//convert the point coordinate to that of the parents
ClientToScreen(&point);
pWnd->ScreenToClient(&point);
LPARAM lParam(point.y<<16);
lParam += point.x;
pWnd->SendMessage(WM_RBUTTONDOWN, (WPARAM)nFlags, lParam);
}
return;
}
void CChartCtrl::OnPaint() {
CPaintDC dc(this);
if (GetStyle()&RAISED_BORDER) {
CRect Rect;
GetClientRect(&Rect);
dc.DrawEdge(&Rect, BDR_SUNKENINNER|BDR_SUNKENOUTER, BF_RECT);
}
}
LRESULT CChartCtrl::OnGetPopupText(WPARAM wParam, LPARAM lParam) {
CDataPoint* pDataPoint = (CDataPoint*)wParam;
CString* MessageText = (CString*)lParam;
MessageText->Format("%.0f",pDataPoint->m_dY);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -