标题:想弄个柱状图、饼图
只看楼主
yehuanfeng
Rank: 4
等 级:业余侠客
帖 子:75
专家分:201
注 册:2010-8-3
结帖率:84.62%
已结贴  问题点数:20 回复次数:4 
想弄个柱状图、饼图
  最近想弄个柱状图、饼图来显示一些信息,之前也没用过,NI里面好像没有,不知道哪里去找这些个控件?大家帮帮忙,谢谢
搜索更多相关主题的帖子: 柱状图 
2011-04-14 14:14
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
得分:20 
直接用GDI+画~
2011-04-14 14:17
yehuanfeng
Rank: 4
等 级:业余侠客
帖 子:75
专家分:201
注 册:2010-8-3
得分:0 
回复 2楼 zhoufeng1988
自己画起来效果不是很好
2011-04-14 14:30
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
得分:0 
这是用Windows API画的,但只是简单画一下,可以自己加一些功能进去。
程序代码:
/*

 * FileName: App.cpp

 * Author: ZhouFeng

 * Date: 2011/04/05

 */

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    TCHAR szAppName[] = TEXT("pie");
    WNDCLASS wndclass;
    HWND hwnd;
    MSG msg;

    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.hCursor = LoadCursor(hInstance, IDC_ARROW);
    wndclass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
    wndclass.hInstance = hInstance;
    wndclass.lpszClassName = szAppName;
    wndclass.lpfnWndProc = WndProc;
    wndclass.lpszMenuName = NULL;
    wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

    if(!RegisterClass(&wndclass))
    {
       MessageBox(NULL, TEXT("此程序要求在Windows NT 下运行"), szAppName, MB_ICONERROR);
       return 0;
    }

    hwnd = CreateWindow(szAppName, TEXT("画饼图"), WS_OVERLAPPEDWINDOW, 
       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
       NULL, NULL, hInstance, NULL);
    ShowWindow(hwnd, SW_NORMAL);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0))
    {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
    }
    return msg.lParam;
}

#define RADIUS 100       // 圆半径

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    static RECT rectClient;
    static TEXTMETRIC tm;
    static int cxEllipse = 200, cyEllipse = 200;
    static HBRUSH hbrushRed, hbrushBlue;
    static HPEN hPen;
    POINT pntTmp;

    switch(message)
    {
    case WM_CREATE:
       hdc = GetDC(hwnd);
       GetTextMetrics(hdc, &tm);
       ReleaseDC(hwnd, hdc);
       hbrushRed = CreateSolidBrush(RGB(255, 0, 0));
       hbrushBlue = CreateSolidBrush(RGB(0, 0, 255));
       hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 0));

       return 0;
    case WM_SIZE:
       GetClientRect(hwnd, &rectClient);
       return 0;
    case WM_PAINT:
       hdc = BeginPaint(hwnd, &ps);
       SelectObject(hdc, hPen);
       // 画椭圆
       SelectObject(hdc, hbrushBlue);
       Pie(hdc, cxEllipse, cyEllipse, cxEllipse + RADIUS, cyEllipse + RADIUS, cxEllipse, cyEllipse + RADIUS / 2,
           cxEllipse + RADIUS / 2, cyEllipse);
       //Ellipse(hdc, cxEllipse, cyEllipse, cxEllipse + RADIUS - 10, cyEllipse + RADIUS -10);
       SelectObject(hdc, hbrushRed);
       Pie(hdc, cxEllipse, cyEllipse, cxEllipse + RADIUS - 10, cyEllipse + RADIUS -10, cxEllipse + RADIUS / 2 - 5, cyEllipse,
           cxEllipse, cyEllipse + RADIUS / 2 - 5);
       MoveToEx(hdc, cxEllipse + RADIUS / 2 + 20, cyEllipse + RADIUS / 2, &pntTmp);
       LineTo(hdc, cxEllipse + RADIUS / 2 + 120, cyEllipse + RADIUS / 2 + 100);
       TextOut(hdc, cxEllipse + RADIUS / 2 + 120, cyEllipse + RADIUS / 2 + 100, "75%", 3);
       MoveToEx(hdc, cxEllipse + 25, cyEllipse + 25, &pntTmp);
       LineTo(hdc, cxEllipse - 65, cyEllipse - 65);
       TextOut(hdc, cxEllipse - 65, cyEllipse - 65, "25%", 3);
       EndPaint(hwnd, &ps);

       return 0;
    case WM_DESTROY:
       DeleteObject(hbrushRed);
       DeleteObject(hbrushBlue);
       DeleteObject(hPen);
       PostQuitMessage(0);

       return 0;
    }
    return DefWindowProc(hwnd, message, wparam, lparam);
}

再VC下创建一个空的WIN32项目,编译即可。
2011-04-14 14:31
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
得分:0 
那就在网上搜一下,加一些特效进去~
2011-04-14 14:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-336656-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043962 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved