/*
*
* ChartCtrl.cpp
*
* Written by C�dric Moonen (cedric_moonen@hotmail.com)
*
*
*
* 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源码_支持VS2013_win32和x64编译运行,Bottom可显示自定义文本
共59个文件
h:31个
cpp:23个
inl:4个
需积分: 10 2 下载量 191 浏览量
2022-03-29
19:41:37
上传
评论
收藏 116KB 7Z 举报
温馨提示
网上下载的ChartCtrl源码资源,原来只能编译WIN32程序,并且坐标轴只能显示数值;经改进后,可在VC6和vs2013环境的WIN32和x64模式下编译能通过,并且支持坐标轴数据显示自定义的文本,如下图 m_pBottomAxis->SetDisAxisMode(1); TChartString strTickText[10]; strTickText[0] = _T("NULL"); strTickText[1] = _T("暗片"); strTickText[2] = _T("黑斑"); strTickText[3] = _T("划伤"); strTickText[4] = _T("破片"); strTickText[5] = _T("同心圆"); strTickText[6] = _T("脏污"); strTickText[7] = _T("NG数"); strTickText[8] = _T("总数"); m_pBottomAxis->SetDisAxisText(strTickText);
资源详情
资源评论
资源推荐
收起资源包目录
ChartCtrl win32x64.7z (59个子文件)
ChartCtrl.jpg 118KB
ChartCtrl - X86X64
ChartAxisLabel.h 3KB
ChartBarSerie.h 7KB
ChartScrollBar.h 2KB
ChartStandardAxis.cpp 5KB
ChartCrossHairCursor.h 2KB
ChartSerieBase.h 7KB
ChartBalloonLabel.inl 4KB
ChartAxisLabel.cpp 4KB
ChartTitle.h 4KB
ChartLegend.h 5KB
ChartCandlestickSerie.h 4KB
ChartLabel.h 4KB
ChartDateTimeAxis.cpp 10KB
ChartCursor.cpp 1KB
ChartLineSerie.h 3KB
ChartDateTimeAxis.h 5KB
ChartSerie.h 9KB
ChartBalloonLabel.h 3KB
ChartLogarithmicAxis.cpp 5KB
ChartSerie.cpp 4KB
ChartScrollBar.cpp 5KB
ChartLogarithmicAxis.h 2KB
ChartCrossHairCursor.cpp 2KB
ChartDragLineCursor.h 2KB
ChartPointsArray.h 6KB
ChartXYSerie.h 5KB
ChartPointsArray.inl 8KB
ChartLineSerie.cpp 10KB
ChartFont.h 3KB
ChartAxis.h 17KB
ChartMouseListener.h 3KB
ChartCtrl.h 21KB
ChartStandardAxis.h 2KB
ChartLegend.cpp 9KB
ChartAxis.cpp 19KB
ChartSurfaceSerie.cpp 7KB
ChartGanttSerie.cpp 6KB
ChartGradient.cpp 4KB
ChartDragLineCursor.cpp 2KB
ChartTitle.cpp 5KB
ChartGrid.cpp 3KB
PointsOrdering.h 917B
ChartGradient.h 2KB
ChartGrid.h 2KB
ChartPointsSerie.h 3KB
ChartFont.cpp 3KB
ChartPointsSerie.cpp 9KB
ChartCandlestickSerie.cpp 7KB
ChartCtrl.cpp 30KB
ChartXYSerie.cpp 5KB
ChartSeriesMouseListener.h 2KB
ChartLabel.inl 2KB
ChartBarSerie.cpp 10KB
ChartSerieBase.inl 8KB
ChartGanttSerie.h 5KB
ChartSurfaceSerie.h 4KB
ChartString.h 932B
ChartCursor.h 4KB
共 59 条
- 1
dzqsuper
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0