基本信息
源码名称:c++ 图表绘制(CChart)
源码大小:76.61M
文件格式:.rar
开发语言:C/C++
更新时间:2020-08-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
// 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; }