Click here to Skip to main content
15,886,806 members
Articles / Desktop Programming / MFC

A 2D data visualisation class

Rate me:
Please Sign up or sign in to vote.
4.54/5 (34 votes)
20 Mar 2000 315.9K   17.6K   175  
A comprehensive set of classes for displaying 2 dimensional data
// DialogWithGraph.cpp : implementation file
//

#include "stdafx.h"
#include "test_grafix.h"
#include "DialogWithGraph.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogWithGraph dialog


CDialogWithGraph::CDialogWithGraph(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogWithGraph::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogWithGraph)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
    graph_count = 0;
}


void CDialogWithGraph::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogWithGraph)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogWithGraph, CDialog)
	//{{AFX_MSG_MAP(CDialogWithGraph)
	ON_BN_CLICKED(IDC_NEW_GRAPH_DLG, OnNewGraphDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogWithGraph message handlers

#define POINTS_X_RANGE	100

BOOL CDialogWithGraph::OnInitDialog() 
{
    CDialog::OnInitDialog();
    
    CRect rect;
    GetClientRect(rect);
    rect.bottom -= 60;
    graph_wnd.Create(_T("Graph Window"), rect, this, 11000, WS_CHILD | WS_VISIBLE, TRUE);

    graph_wnd.SetAxisProps(_T("X-Axis"), _T(""), 4, GRAPH_X_AXIS, TRUE);
    graph_wnd.SetAxisProps(_T("Y-Axis"), _T(""), 4, GRAPH_Y_AXIS, TRUE);
    graph_wnd.SetGraphWorldCoords(0, POINTS_X_RANGE, -1, 1, TRUE);

    return TRUE;  // return TRUE unless you set the focus to a control
	          // EXCEPTION: OCX Property Pages should return FALSE
}

extern COLORREF DefaultGraphColors[];

void CDialogWithGraph::OnNewGraphDlg() 
{
    CString title;
    title.Format(_T("New graph - %d"), graph_count);
    int c = graph_wnd.AddGraph(DefaultGraphColors[graph_count], title);
    if (c != -1)
    {
	//add new sin graph
	double x, y;
	for (int i=0; i<=POINTS_X_RANGE; i++)
	{
	    x = i;
	    y = sin((i*3.14*(graph_count+1))/POINTS_X_RANGE);
	    graph_wnd.AddPoint(c, x, y, TRUE);
	};
    };
    graph_count += 1;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions