Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Scientific charting control

, 17 Jan 2005
Multi-purpose scientific charting control.
xgraph_bin.zip
XGRAPH10.dll
XGraphTest.exe
xgraph_demo.zip
Include
Release
res
bitmap1.bmp
bs1.bmp
bs2.bmp
bs3.bmp
bs4.bmp
bs5.bmp
Toolbar.bmp
XGraphTest.ico
XGraphTestDoc.ico
XGRAPH10.lib
XGRAPH10d.lib
XGraphTest.clw
XGraphTest.dsp
XGraphTest.dsw
XGRAPH10.dll
bitmap2.bmp
default1.bin
Logo.bmp
Screen1.bmp
xgraphtest
xgraph_src.zip
XGraph.clw
xgraph.def
XGRAPH.dsw
XGRAPH.dsp
bitmap1.bmp
bs1.bmp
bs2.bmp
bs3.bmp
bs4.bmp
bs5.bmp
lib
XGRAPH10.dll
XGRAPH10.exp
XGRAPH10.lib
// XGraphTestView.cpp : Implementierung der Klasse CXGraphTestView
//

#include "stdafx.h"
#include "XGraphTest.h"

#include "XGraphTestDoc.h"
#include "XGraphTestView.h"
#include "Math.h"

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

/////////////////////////////////////////////////////////////////////////////
// CXGraphTestView


#define IDM_SELECT                      40000
#define IDM_INSERTLABEL                 40001
#define IDM_ZOOM                        40002
#define IDM_RESET                       40003
#define IDM_PAN                         40004
#define IDM_PROPERTIES                  40005
#define IDM_LABELDOPROP                 40006
#define IDM_PRINT                       40007
#define IDM_MAGNIFIER                   40008
#define IDM_LINEARTREND                 40009
#define IDM_CUBICTREND                  40010
#define IDM_CURSOR                      40011
#define IDM_EDITCURVE                   40014
#define IDM_MEASURE		                40015


IMPLEMENT_DYNCREATE(CXGraphTestView, CView)

BEGIN_MESSAGE_MAP(CXGraphTestView, CView)
	//{{AFX_MSG_MAP(CXGraphTestView)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
	// Standard-Druckbefehle
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)


END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXGraphTestView Konstruktion/Destruktion

CXGraphTestView::CXGraphTestView()
{
}

CXGraphTestView::~CXGraphTestView()
{

	
}

BOOL CXGraphTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	
	cs.style |= WS_CLIPCHILDREN;
	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CXGraphTestView Zeichnen

void CXGraphTestView::OnDraw(CDC* pDC)
{
	CXGraphTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// ZU ERLEDIGEN: Hier Code zum Zeichnen der urspr�nglichen Daten hinzuf�gen
}

/////////////////////////////////////////////////////////////////////////////
// CXGraphTestView Drucken

BOOL CXGraphTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// Standardvorbereitung
	return DoPreparePrinting(pInfo);
}

void CXGraphTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	
}

void CXGraphTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// ZU ERLEDIGEN: Hier Bereinigungsarbeiten nach dem Drucken einf�gen
}

/////////////////////////////////////////////////////////////////////////////
// CXGraphTestView Diagnose

#ifdef _DEBUG
void CXGraphTestView::AssertValid() const
{
	CView::AssertValid();
}

void CXGraphTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CXGraphTestDoc* CXGraphTestView::GetDocument() // Die endg�ltige (nicht zur Fehlersuche kompilierte) Version ist Inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXGraphTestDoc)));
	return (CXGraphTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CXGraphTestView Nachrichten-Handler


void CXGraphTestView::SetupData()
{

}

void CXGraphTestView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	CRect clRect;
	GetClientRect(clRect);
	
	if (!::IsWindow(m_Graph[0].m_hWnd))
	{
		for (int i = 0; i < 2; i++)
		{
			m_Graph[i].Create(_T("XGraph"),_T(""), WS_CHILD  | WS_VISIBLE, clRect, this, 1001 + i);
			m_Graph[i].SetData(NULL,0,0,0,false);
			m_Graph[i].SetCursorFlags(XGC_LEGEND | XGC_VERT | XGC_ADJUSTSMOOTH);
						
			// Force cursor to snap to the first curve
			m_Graph[i].ForceSnap(0);

			if (i == 1)
			{
				m_Graph[i].SetInteraction(false);
				m_Graph[i].EnableWindow(false);
			}

		}
		
		AddDataSerie();
	}


}

LRESULT CXGraphTestView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{	
	if (message == XG_POINTCHANGED)
	{
		CXGraph::NM_POINTMOVING* pNM_POINTMOVING = (CXGraph::NM_POINTMOVING*) wParam;

	}

	if (message == XG_CURSORMOVED)
	{
		
		TDataPoint point = ((CXGraph*)lParam)->GetCursorAbsolute(0);

		for (int i = 0; i < 2; i++)
		{
			if (((CXGraph*)lParam) != &m_Graph[i])
			{
				m_Graph[i].Cursor();
				m_Graph[i].SetCursorAbsolute(0, point, true);
				m_Graph[i].Invalidate();
			}
		}

	}

	if (message == XG_RBUTTONUP)
	{
		CPoint point;
		GetCursorPos(&point);
		ScreenToClient(&point);
		CMenu menu;
		menu.CreatePopupMenu (); 
		menu.AppendMenu( MF_STRING, IDM_SELECT, _T("Select"));
		menu.AppendMenu( MF_STRING, IDM_ZOOM, _T("Zoom"));
		menu.AppendMenu( MF_STRING, IDM_EDITCURVE, _T("Edit"));
		menu.AppendMenu( MF_STRING, IDM_RESET, _T("Reset"));
		menu.AppendMenu( MF_STRING, IDM_PAN, _T("Pan"));
		menu.AppendMenu( MF_STRING, IDM_MEASURE, _T("Measure"));
		menu.AppendMenu( MF_STRING, IDM_CURSOR, _T("Cursor"));
		menu.AppendMenu( MF_STRING, IDM_INSERTLABEL, _T("Insert label"));
		menu.AppendMenu( MF_STRING, IDM_PRINT, _T("Print"));
		menu.AppendMenu( MF_SEPARATOR );
		menu.AppendMenu( MF_STRING, IDM_PROPERTIES, _T("Properties"));
		ClientToScreen(&point);
		UINT nCmd = menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY,
										  point.x, point.y ,
										  (CXGraph*)lParam);

	}
	
 
	return CView::WindowProc(message, wParam, lParam);
}
 
void CXGraphTestView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);

	CRect clRect(0,0,cx,cy);
	
	clRect.bottom /= 2;
	
	if (::IsWindow(m_Graph[0].m_hWnd) && m_Graph[0].IsWindowVisible ())
		m_Graph[0].MoveWindow (clRect);
	
	clRect.OffsetRect (0, clRect.Height());
	if (::IsWindow(m_Graph[1].m_hWnd) && m_Graph[1].IsWindowVisible ())
		m_Graph[1].MoveWindow (clRect);
	
}

void CXGraphTestView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	m_Graph[0].PrintGraph(pDC);
}


void CXGraphTestView::AddDataSerie(bool bAddAxes)
{
	COleDateTimeSpan dateSpan(0, 0, 1, 0);

	COleDateTime aDT;
	
	aDT = COleDateTime::GetCurrentTime();
	
	// setup data
	for (int i = 0; i < VALCOUNT; i++)
	{
		m_Values[0][i].fXVal = i; 
		m_Values[0][i].fYVal = 100 + (( sin(i  / 180.0 * 3.141) * 10));
		m_Values[1][i].fXVal = i; 
		m_Values[1][i].fYVal = 110 + (( sin(i  / 180.0 * 3.141) * 10)) + cos(i / 2.0) + (i / 20.0);
		m_Values[2][i].fXVal = COleDateTime::GetCurrentTime () +  COleDateTimeSpan(0, 0, 0, 1 * i);
		m_Values[2][i].fYVal = 80 + fmod(i / 10.0, 10.0);
		m_Values[3][i].fXVal = COleDateTime::GetCurrentTime () +  COleDateTimeSpan(0, 0, 0, 1 * i);
		m_Values[3][i].fYVal = 70 + i / 50 % 2 * 10;
		m_Values[4][i].fXVal = i; 
		m_Values[4][i].fYVal = 100 + (( sin(i  / 180.0 * 3.141) * 80));
		
	}
		
	for (i = 0; i< 2; i++)
	{
		// link series to graph
		m_Graph[i].SetData (m_Values[0], VALCOUNT, 0, 0, 0);
		m_Graph[i].SetData (m_Values[1], VALCOUNT, 1, 0, 0);
		m_Graph[i].SetData (m_Values[2], VALCOUNT, 2, 1, 0);
		m_Graph[i].SetData (m_Values[3], VALCOUNT, 3, 1, 0);
		m_Graph[i].SetData (m_Values[4], VALCOUNT, 4, 0, 1);
		
		// setup visual aspects
		m_Graph[i].GetCurve (0).SetLabel("Curve 1");
		m_Graph[i].GetCurve (1).SetLabel("Curve 2");
		m_Graph[i].GetCurve (2).SetLabel("Curve 3");
		m_Graph[i].GetCurve (3).SetLabel("Curve 4");
		m_Graph[i].GetCurve (4).SetLabel("Curve 5 (log.)");

		m_Graph[i].GetCurve (0).SetShowMarker(true);
		m_Graph[i].GetCurve (0).SetColor(RGB(0,0,0));
		m_Graph[i].GetCurve (3).SetColor(RGB(255,0,0));
		m_Graph[i].GetCurve (3).SetFillBeneath(true);
		m_Graph[i].GetCurve (3).SetFillColor(RGB(255,0,0));
		m_Graph[i].GetCurve (2).SetLineSize(2);
		
		m_Graph[i].GetYAxis (1).SetAxisType(CXGraphAxis::atLog);
		m_Graph[i].GetXAxis (1).SetDisplayFmt("%H:%M:%S");
		m_Graph[i].GetXAxis (1).SetDateTime(true);
 
		m_Graph[i].GetXAxis (0).SetShowGrid(false);
		m_Graph[i].GetYAxis (0).SetShowGrid(false);
		
		m_Graph[i].GetXAxis (0).SetAxisMarker(0, 90.0, RGB(150, 150, 255), PS_DASH);
		m_Graph[i].GetXAxis (0).SetAxisMarker(1, 180.0, RGB(150, 150, 255));
		m_Graph[i].GetXAxis (0).SetAxisMarker(2, 270.0, RGB(150, 150, 255));
		m_Graph[i].GetXAxis (0).SetAxisMarker(3, 360.0, RGB(150, 150, 255));
		
		m_Graph[i].GetYAxis (0).SetLabel("W");
		m_Graph[i].GetYAxis (0).SetAxisMarker(0, 90.0, RGB(150, 150, 255));
		m_Graph[i].GetYAxis (0).SetAxisMarker(1, 100.0, RGB(150, 150, 255));
		m_Graph[i].GetYAxis (0).SetAxisMarker(2, 110.0, RGB(150, 150, 255));
		m_Graph[i].GetYAxis (0).SetAxisMarker(3, 120.0, RGB(150, 150, 255));
		
		m_Graph[i].GetYAxis (0).GetAxisMarker(2).szLabel = _T("Max. W");
		
		m_Graph[i].GetCurve (1).SetFillBeneath(true, 0);
		m_Graph[i].GetCurve (1).SetFillColor(RGB(150 ,255 - (i * 100),150 + (i * 50)));
		m_Graph[i].GetCurve (1).SetFillTransparent(true);

		
		m_Graph[i].GetXAxis (0).SetShowMarker(false);
		m_Graph[i].GetYAxis (0).SetShowMarker(false);
		m_Graph[i].GetXAxis (0).SetColorRange(0, 90 , 200, RGB(200,200, 255), RGB(100,255,200),"Range 1", HS_DIAGCROSS);
		m_Graph[i].GetXAxis (0).SetColorRange(1, 490 , 600, RGB(200,255, 100), RGB(100,255,200),"Range 2", HS_DIAGCROSS);

		m_Graph[i].SetShowLegend (i == 0);
		m_Graph[i].SetInnerColor (RGB(255,255,255));
	}
			

	

}


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

Share

About the Author

Gunnar Bolle
Web Developer
Germany Germany
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 17 Jan 2005
Article Copyright 2002 by Gunnar Bolle
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid