在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例C/C++语言基础 → c++ 图表绘制(CChart)

c++ 图表绘制(CChart)

C/C++语言基础

下载此实例
  • 开发语言:C/C++
  • 实例大小:76.61M
  • 下载次数:29
  • 浏览次数:1217
  • 发布时间:2020-08-20
  • 实例类别:C/C++语言基础
  • 发 布 人:mumufeixia
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 图表

实例介绍

【实例简介】

【实例截图】

from clipboard

【核心代码】

// LessonA05.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#include "Chart.h"
#if defined(_UNICODE) || defined(UNICODE)
#	pragma comment(lib,"myChartu.lib")
#else
#	pragma comment(lib,"myChart.lib")
#endif
using namespace NsCChart;

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_LESSONA05, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_LESSONA05);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_LESSONA05);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW 1);
	wcex.lpszMenuName	= (LPCSTR)IDC_LESSONA05;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//

void	MyDraw(void *plot, HDC hDC, RECT clientRect, RECT plotRect, void *pPara )
{
	TCHAR str[32];
	SIZE textSize;
	RECT textRect;

	int step;
	step = (plotRect.bottom - plotRect.top)/7;

	LOGFONT lf; 
	memset(&lf,0,sizeof(LOGFONT)); 
	lf.lfHeight = -24; 
	lf.lfWeight = FW_NORMAL; 
	lf.lfClipPrecision = CLIP_LH_ANGLES; 
	strcpy(lf.lfFaceName, "宋体"); //看好这个字体!!
	HFONT hfont = CreateFontIndirect(&lf);
	HFONT hOldFont = (HFONT)SelectObject(hDC, hfont);

	_tcscpy(str, _T("第一通道数据"));
	GetTextExtentPoint32(hDC, str, _tcslen(str), &textSize );
	textRect.left = plotRect.left   10;
	textRect.right = textRect.left   textSize.cx;
	textRect.bottom = plotRect.bottom - step * 1.5;
	textRect.top = textRect.bottom - textSize.cy;
	DrawText(hDC, str, _tcslen(str), &textRect, DT_CENTER);

	_tcscpy(str, _T("第二通道数据"));
	GetTextExtentPoint32(hDC, str, _tcslen(str), &textSize );
	textRect.left = plotRect.left   10;
	textRect.right = textRect.left   textSize.cx;
	textRect.bottom = plotRect.bottom - step * 3.5;
	textRect.top = textRect.bottom - textSize.cy;
	DrawText(hDC, str, _tcslen(str), &textRect, DT_CENTER);

	_tcscpy(str, _T("第三通道数据"));
	GetTextExtentPoint32(hDC, str, _tcslen(str), &textSize );
	textRect.left = plotRect.left   10;
	textRect.right = textRect.left   textSize.cx;
	textRect.bottom = plotRect.bottom - step * 5.5;
	textRect.top = textRect.bottom - textSize.cy;
	DrawText(hDC, str, _tcslen(str), &textRect, DT_CENTER);

	SelectObject(hDC, hOldFont);
	DeleteObject(hfont);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

	static CChartWnd chartWnd;

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_CREATE:
			chartWnd.Attach(hWnd, kTypeXY);
			{
			TCHAR aa[120];
			TCHAR bb[120]="";

		_tcscpy(aa, _T("第一通道数据"));
				int data1[]={0,1,1,0,1,0,1,0,1,1,1,0,0,1,1,1};
				int data2[]={1,0,0,0,1,0,1,1,1,0,1,1,0,1,1,0};
				int data3[]={0,1,0,0,1,1,1,0,0,1,1,0,1,1,0,0};

				int i;
				for(i=0; i<16; i  )
				{
					chartWnd.GetChart()->AddPoint2D((double)i, data1[i] 1, 0);
					chartWnd.GetChart()->AddPoint2D((double)i, data2[i] 3, 1);
					chartWnd.GetChart()->AddPoint2D((double)i, data3[i] 5, 2);
					if(i%2==0)
					{
						
						chartWnd.GetChart()->AddAlternateLabel(aa,1);
					}
					else
					{
						chartWnd.GetChart()->AddAlternateLabel(bb,1);
						
					}
				}
			// 设置曲线的绘制方式
	//void		SetPlotType(int nType, int nDataIndex, int nPlotIndex=0);
//nType 从1开始,1scatter 2connected  3step H-V 4 stepv-h 5step h-v-h 6 step v-h-v 7 bezier
				/*chartWnd.GetChart()->SetPlotType(3, 0);
				chartWnd.GetChart()->SetPlotType(1, 1);
				chartWnd.GetChart()->SetPlotType(2, 2);*/
			//COLORREF color=0xFC997c;
			COLORREF color=RGB(49,117,242);
			for(int k=0;k<3;k  )
			{
				chartWnd.GetChart()->SetMarkerShow(true,k);
				chartWnd.GetChart()->SetPlotType(1, k);
				chartWnd.GetChart()->SetMarkerFill(true,k);
				//nType 0无标记 1圆圈 2竖直方块 3斜方块 
				chartWnd.GetChart()->SetMarkerType(1,k);
				chartWnd.GetChart()->SetMarkerFreq(-20,k);
				chartWnd.GetChart()->SetMarkerSize(5,k);
				chartWnd.GetChart()->SetDataLineStyle(k,k);
				
				chartWnd.GetChart()->SetAutoDataColor(false, k);
				chartWnd.GetChart()->SetDataColor(color,k);
				//chartWnd.GetChart()->SetDataFillColor(true, color, 0, k, k);
			}
			/*chartWnd.GetChart()->SetMarkerShow(true,0);
			chartWnd.GetChart()->SetMarkerShow(true,1);

			chartWnd.GetChart()->SetMarkerShow(true,2);*/

			}
			//chartWnd.GetChart()->SetAxisLabelShow(false, 0);
			//location 0-left 1-bottom
			//TCHAR aa[5][20]={"we","rt","ht","ht","eh"};
		/*TCHAR aa[120];
		_tcscpy(aa, _T("第一通道数据"));*/
		chartWnd.GetChart()->SetAxisLabelShow(true, 0);//location 0-left 1-bottom	
		chartWnd.GetChart()->SetReplaceLabel(true, 1);
		//chartWnd.GetChart()->AddAlternateLabel(aa,1);
			chartWnd.GetChart()->SetTitle(_T("多通道二进制数据上位机显示"));
chartWnd.GetChart()->SetXRange(0,20.00);
chartWnd.GetChart()->SetYRange(0,8.00);
chartWnd.GetChart()->SetXAutoRange(false);
chartWnd.GetChart()->SetYAutoRange(false);

chartWnd.GetChart()->SetAxisLabelShow(true, 1);
	// 设置子图坐标轴是否显示刻度值
chartWnd.GetChart()->SetAxisLabelShow(true, 1, 0);
chartWnd.GetChart()->SetXAutoTicks(false);
		chartWnd.GetChart()->SetXTickCount(20);
		chartWnd.GetChart()->SetXAutoMinorTicks(false);
		chartWnd.GetChart()->SetXMinorTickCount(1);
			chartWnd.GetChart()->SetUserDrawingFunc(MyDraw, 0);
		chartWnd.GetChart()->SetLangurage(1);//0英文 1中文
		chartWnd.GetChart()->SetDataValueShow(true,1);
		chartWnd.GetChart()->SetDataValueType(1,1);
		chartWnd.GetChart()->SetEnableToolTip(true);

			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}

标签: 图表

实例下载地址

c++ 图表绘制(CChart)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警