★ wanayoo — archive 1999 http://codeguru.developer.com/controls/graph2d.shtmlNouvelle recherche | Portail wanayoo
EarthWeb
Developer.com Click Here!
Click Here!
Find:
 

EXPERT SEARCH
SEARCH THE IT WEB -----
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Contest
mfc codeguru
submission guidelines
 
Book
thinking in c++
stl programmer's guide
reviews
 
Interact
forums
newsgroups
guest book
jobs
jokes
open faq
what's new
 
Other
about
links
newsletters
privacy
tools
 

-----
Visual C++ by E-mail:

Get the weekly e-mail highlights on
Visual C++!
-----



EarthWeb Sites:
IT Management
Networking & Telecommunications
IT Jobs
Software Development
Hardware & Systems
Commerce
Community

EarthWeb Worldwide

   

2D Data Visualization Class


This article was contributed by Paul Barvinko

Sample Image

General.

CGraphView is a class that provides multiplot 2D data visualization. It is capable of simultaneous drawing for up to 32 2D plots.
CGraphView class is derived from CView MFC class and could be used as base class for different kinds of 2D data plot views. Features supported:
-Autoscale
-Zooming
-Fit width, height and page
-Mouse coordinates tracing
-Interactive add, remove and edit points
-Ability to add and display interactively up to 15000 points per second (depends on the speed of the computer)

Class interface.

Class interface provides several groups of functions:

    Graphs manipulation routines:

int AddGraph(COLORREF newColor = 0, char* title = "", BOOL bInvalidate = TRUE);
Function adds new graph to the view. Returns graph index if successful or -1 if not. If bInvalidate flag is set then view will be updated.

int RemoveGraph(int index, BOOL bInvalidate = TRUE);
Function removes graph from collection.

int UpdateGraph(int index, BOOL bInvalidate = TRUE);
Function updates graph information and view, if bInvalidate flag is set. Useful after collective operations with hidden graph.

CGraphProp* GetGraph(int index);
Function returns properties for the given graph or NULL in case of error.

CGraphProp* GetFirstGraph(int* index);
CGraphProp* GetNextGraph(int* index);
These functions are used to enumerate through all existing graphs in the view.

void SetGraphFlags(DWORD new_flags, BOOL bRedraw);
DWORD GetGraphFlags();
These functions are used to get or set graph view flags. Flag value is an OR'ed combination of:


#define GRAPH_AUTOSCALE 0x00000001    // use autoscale when adding new points
#define GRAPH_SQUAREPOINTS 0x00000002 // Draw rectangles around points
#define GRAPH_SHOW_TOOLTIP 0x00000004 // Show coordinates as a ToolTip when moving mouse #define GRAPH_DRAW_AXIS 0x00000008 //Draw axis


    Points manipulation routines:

int AddPoint(int graphnum, double x, double y, BOOL bRedraw, BOOL bUpdatePView, int index = -1);
Adds (if index == -1) or inserts new point to the graph. If bRedraw set - graph will be invalidated. If bUpdatePView set - then Point View List will be updated.

int EditPoint(int graphnum, int index, double x, double y, BOOL bRedraw);
Sets new point coordinates. If bRedraw set - invalidates graph.

int RemovePoint(int graphnum, int index, BOOL bRedraw);
Removes point from graph.

void ClearGraph(int graphnum, BOOL bRedraw, BOOL bUpdatePView);
removes all points from specified graph or from all graphs if graphnum == -1.


    Axis manipulation routines.

void SetAxisProps(char* _title, char* _UOM, int _precision, BOOL bXAxis, BOOL bRedraw);
Sets properties for axis. Properties include: Axis' title (_title), unit of measurement (_UOM) and precision - number of digits after comma (_precision). bXAxis parameter specify axis to apply attributes to and could be one of the following: GRAPH_X_AXIS or GRAPH_Y_AXIS.

void FormatAxisOutput(double value, BOOL bXAxis, int format_level, CString& res_str);
Returns formatted value parameter, regarding current axis' properties and format level. Currently three levels of format information are defined:
0 - minimum information.
1 - value and unit of measurement
2 - axis' title, value and unit of measurement


Point view list routines.

void ShowPointView(BOOL bShow);
Functions shows or hides point list.

BOOL GetPointViewState();
Returns current state of point view list.

void UpdatePointView();
Updates information in the point view list.

Class creation.

There are several steps that you should do in order to use this class in your application:
1. Include all graph files (except grres.rc) into your project.
2. Open grres.rc and copy following resources into your project resources:
    IDD_CHANGE_TITLE dialog
    IDD_GRAPH_AXISPROPS dialog
    IDD_GRAPH_GENPAGE dialog
    IDD_GRAPHS dialog
    IDD_GRAPHS_PROPPAGE dialog
    IDD_POINT_EDIT dialog
    IDR_GRAPH_PROPS menu
    IDR_PVIEW_RBMENU menu
    IDR_PVIEW_RBMENU_EMPTY menu
4. Derive your view class from CGraphView - and off we go!

Downloads

Download demo project - 107 Kb

Download source - 70 Kb

Latest updates and information could be found here.

History

Date Posted: August 7, 1999

Comments:

Add Comment

   

Give them a visit Click Here!

Click Here!

INSTANT EXPERTS!
Savvy IT Pros report on SupportSource. Take a look inside the largest vault of multi-vendor computing specs ever assembled. Click here for an In-depth Report,.

For tons of Windows technology resources, check out the Windows Programming directory.

Searching the Web for tech topics just got better with
TechCrawler where all results come only from popular technical sites.

WINNER!!!
Congratulations to James Hole, of New Mexico! The grand prize winner of EarthWeb's Flatten the Obstacles Sweepstakes and now a proud Hummer(R) owner.

Give them a visit Click Here!

Click Here!

Click Here!

Click Here!

Home About Us Search Subscribe Advertising Info Contact Us FAQs
Use of this site is subject to certain Terms & Conditions.
Earthweb's statement regarding our users' right to privacy.
Copyright ©1996-2000 EarthWeb Inc.. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited.