/*
*
* ChartCtrl.cpp
*
* Written by C�dric Moonen ([email protected])
*
*
*
* This code may be used for any non-commercial and commercial purposes in a compiled form.
* The code may be redistributed as long as it remains unmodified and providing that the
* author name and this disclaimer remain intact. The sources can be modified WITH the author
* consent only.
*
* This code is provided without any garanties. I cannot be held responsible for the damage or
* the loss of time it causes. Use it at your own risks
*
* An e-mail to notify me that you are using this code is appreciated also.
*
*
* History:
* - 18/05/2006: Added support for panning
* - 28/05/2006: Bug corrected in RemoveAllSeries
* - 28/05/2006: Added support for resizing
* - 12/06/2006: Added support for manual zoom
* - 10/08/2006: Added SetZoomMinMax and UndoZoom
* - 24/03/2007: GDI leak corrected
* - 24/03/2007: Invisible series are not taken in account for auto axis
* and legend (thanks to jerminator-jp).
* - 24/03/2007: possibility to specify a margin for the axis. Needs to be improved
* - 05/04/2007: ability to change the text color of the axis.
* - 05/04/2007: ability to change the color of the border of the drawing area.
* - 05/04/2007: Surface series added.
* - 26/08/2007: The clipping area of the series is a bit larger (they will be
* drawn over the bottom and right axes).
* - 12/01/2007: Ability to change the color of the zoom rectangle.
* - 08/02/2008: Added convenience functions to convert from date to value and
* opposite.
* - 21/02/2008: The zoom doesn't do anything if the user only clicks on the control
* (thanks to Eugene Pustovoyt).
* - 29/02/2008: The auto axis are now refreshed when a series is removed (thanks to
* Bruno Lavier).
* - 08/03/2008: EnableRefresh function added (thanks to Bruno Lavier).
* - 21/03/2008: Added support for scrolling.
* - 25/03/2008: UndoZoom function added.
* - 25/03/2008: A series can now be removed using its pointer.
* - 12/08/2008: Performance patch (thanks to Nick Holgate).
* - 18/08/2008: Added support for printing.
* - 31/10/2008: Fixed a bug for unicode.
*
*/
#include "stdafx.h"
#include "ChartCtrl.h"
#include "ChartSerie.h"
#include "ChartGradient.h"
#include "ChartStandardAxis.h"
#include "ChartDateTimeAxis.h"
#include "ChartLogarithmicAxis.h"
#include "ChartCrossHairCursor.h"
#include "ChartDragLineCursor.h"
#include "ChartPointsSerie.h"
#include "ChartLineSerie.h"
#include "ChartSurfaceSerie.h"
#include "ChartBarSerie.h"
#include "ChartCandlestickSerie.h"
#include "ChartGanttSerie.h"
#if _MFC_VER > 0x0600
#include "atlImage.h"
#endif
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define CHARTCTRL_CLASSNAME _T("ChartCtrl") // Window class name
COLORREF pSeriesColorTable[] = { RGB(255,0,0), RGB(0,150,0), RGB(0,0,255), RGB(255,255,0), RGB(0,255,255),
RGB(255,128,0), RGB(128,0,128), RGB(128,128,0), RGB(255,0,255), RGB(64,128,128)};
/////////////////////////////////////////////////////////////////////////////
// CChartCtrl
CChartCtrl::CChartCtrl()
{
RegisterWindowClass();
m_iEnableRefresh = 1;
m_bPendingRefresh = false;
m_BorderColor = RGB(0,0,0);
m_BackColor = GetSysColor(COLOR_BTNFACE);
EdgeType = EDGE_RAISED;
m_BackGradientType = gtVertical;
m_bBackGradient = false;
m_BackGradientCol1 = m_BackGradientCol2 = m_BackColor;
for (int i=0;i<4;i++)
m_pAxes[i] = NULL;
m_pLegend = new CChartLegend(this);
m_pTitles = new CChartTitle(this);
m_bMemDCCreated = false;
m_bPanEnabled = true;
m_bRMouseDown = false;
m_bZoomEnabled = true;
m_bLMouseDown = false;
m_ZoomRectColor = RGB(255,255,255);
m_bToolBarCreated = false;
m_pMouseListener = NULL;
m_bMouseVisible = true;
}
CChartCtrl::~CChartCtrl()
{
TSeriesMap::iterator seriesIter = m_mapSeries.begin();
for (seriesIter; seriesIter!=m_mapSeries.end(); seriesIter++)
{
delete (seriesIter->second);
}
TCursorMap::iterator cursorIter = m_mapCursors.begin();
for (cursorIter; cursorIter!=m_mapCursors.end(); cursorIter++)
{
delete (cursorIter->second);
}
for (int i=0; i<4 ;i++)
{
if (m_pAxes[i])
delete m_pAxes[i];
}
if (m_pLegend)
{
delete m_pLegend;
m_pLegend = NULL;
}
if (m_pTitles)
{
delete m_pTitles;
m_pTitles = NULL;
}
}
BEGIN_MESSAGE_MAP(CChartCtrl, CWnd)
//{{AFX_MSG_MAP(CChartCtrl)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_RBUTTONDBLCLK()
ON_WM_SIZE()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChartCtrl message handlers
void CChartCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (!m_bMemDCCreated)
{
RefreshCtrl();
m_bMemDCCreated = true;
}
// Get Size of Display area
CRect rect;
GetClientRect(&rect);
dc.BitBlt(0, 0, rect.Width(), rect.Height(),
&m_BackgroundDC, 0, 0, SRCCOPY) ;
// Draw the zoom rectangle
if (m_bZoomEnabled && m_bLMouseDown)
{
CPen NewPen(PS_SOLID,1,m_ZoomRectColor);
CPen* pOldPen = dc.SelectObject(&NewPen);
dc.MoveTo(m_rectZoomArea.TopLeft());
dc.LineTo(m_rectZoomArea.right,m_rectZoomArea.top);
dc.LineTo(m_rectZoomArea.BottomRight());
dc.LineTo(m_rectZoomArea.left,m_rectZoomArea.bottom);
dc.LineTo(m_rectZoomArea.TopLeft());
dc.SelectObject(pOldPen);
DeleteObject(NewPen);
}
// Draw the cursors.
TCursorMap::iterator iter = m_mapCursors.begin();
for (iter; iter!=m_mapCursors.end(); iter++)
iter->second->Draw(&dc);
}
BOOL CChartCtrl::OnEraseBkgnd(CDC* )
{
// To avoid flickering
// return CWnd::OnEraseBkgnd(pDC);
return FALSE;
}
CChartCrossHairCursor* CChartCtrl::CreateCrossHairCursor(bool bSecondaryHorizAxis,
bool bSecondaryVertAxis)
{
CChartAxis* pHorizAxis = NULL;
CChartAxis* pVertAxis = NULL;
if (bSecondaryHorizAxis)
pHorizAxis = m_pAxes[TopAxis];
else
pHorizAxis = m_pAxes[BottomAxis];
if (bSecondaryVertAxis)
pVertAxis = m_pAxes[RightAxis];
else
pVertAxis = m_pAxes[LeftAxis];
ASSERT(pHorizAxis != NULL);
ASSERT(pVertAxis != NULL);
CChartCrossHairCursor* pNewCursor = new CChartCrossHairCursor(this, pHorizAxis, pVertAxis);
m_mapCursors[pNewCursor->GetCursorId()] = pNewCursor;
return pNewCursor;
}
CChartDragLineCursor* CChartCtrl::CreateDragLineCursor(EAxisPos relatedAxis)
{
ASSERT(m_pAxes[relatedAxis] != NULL);
CChartDragLineCursor* pNewCursor = new CChartDragLineCursor(this, m_pAxes[relatedAxis]);
m_mapCursors[pNewCursor->GetCursorId()] = pNewCursor;
return pNewCursor;
}
void CChartCtrl::AttachCustomCursor(CChartCursor* pCursor)
{
m_mapCursors[pCursor->GetCursorId()] = pCursor;
}
void CChartCtrl::RemoveCursor(unsigned cursorId)
{
TCursorMap::iterator iter = m_mapCursors.find(cursorId);
if (iter != m_mapCursors.end())
{
delete iter->second;
m_mapCursors.erase(iter);
}
}
void CChartCtrl::ShowMouseCursor(bool bShow)
{
m_bMouseVisible = bShow;
if (!bShow)
SetCursor(NULL);
}
CChartStandardAxis* CChartCtrl::CreateStandardAxis(EAxisPos axisPos)
{
CChartStandardAxis* pAxis = new CChartStandardAxis();
AttachCustomAxis(pAxis, axisPos);
return pAxis;
}
CChartLogarithmicAxis* CChartCtrl::CreateLogarithmicAxis(EAxisPos axisPos)
{
CChartLogarithmicAxis* pAxis = new CChartLogarithmicAxis();
AttachCustomAxis(pAxis, axisPos);
return pAxis;
}
CChartDateTimeAxis* CChartCtrl::CreateDateTimeAxis(EAxisPos axisPos)
{
CChartDateTimeAxis* pAxis = new CChartDateTimeAxis();
没有合适的资源?快使用搜索试试~ 我知道了~
ChartCtrl_source ChartCtrl__ChartDemo

共487个文件
html:161个
h:72个
svn-base:62个


温馨提示
TeeChart替代品,MFC下好用的高速绘图控件-(Hight-Speed Charting) ( ChartCtrl_source & ChartCtrl_demo) 也许这是vc下最好最方便的绘图类,它有TeeChart的绘图和操作风格,不用当心注册破解的问题,因为它是开源的。不用打包注册,因为它是封装成类的,能方便扩展继承。vc6.0到vs2019都能使用,而且非常简单。
资源推荐
资源详情
资源评论
















收起资源包目录





































































































共 487 条
- 1
- 2
- 3
- 4
- 5
资源评论

- soso20122021-02-19正好要用到这个开源控件,在MFC上自定义一个控件来画柱状图啥的,很方便

dayin08
- 粉丝: 0
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 工程项目管理检查表.doc
- 文明网络的安全建议书.docx
- 2023年ARM嵌入式系统实验报告.doc
- 报警处置系统与入侵检测系统数据接口技术规范.doc
- 我国嵌入式技术的发展和现状.docx
- MySQL数据库考试试题及答案.docx
- 鸿业市政道路软件常见问题与解答.doc
- 计算机组装与维护(第二版)-项目6-计算机系统设置与优化.pptx
- 沧州移动通信公司土建工程招标书.doc
- 网络文明学生作文800字.docx
- 2022年秋福师Linux操作系统管理在线作业一答案详解.doc
- 网络营销讲义三.pptx
- VMWare下安装MACOSX106(本教程已在电脑上安装成功).doc
- 2023年公司CAD初级工程师认证考试题.docx
- 网络营销策划书(2).doc
- 数据库原理课程设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
