Click here to Skip to main content
Licence 
First Posted 24 Jul 2004
Views 96,375
Bookmarked 72 times

NSChart Control

By | 7 Aug 2004 | Article
This control creates a chart in a dialog with Pie and Bar styles.

Sample Image - nschart.gif

Sample Image - nschart.gif

Introduction

The CNSChartCtrl control class is derived from CWnd. The purpose is to create pie and bar charts in a dialog (also in a view) with editable fill colors and values, in runtime. Originally, the source code and project was written and compiled with Visual C++ 6.0 SP5 under Windows 98; it also was run in later versions.

It is an alternative to many tools available that perform similar tasks.

How to use

  1. To create a new NSChart control, use the MS Visual C++ dialog editor, insert a custom control on the dialog, and set "MFC_NSChartCtrl" as the Class name. The caption field is used to set the title of the chart.
  2. Create an instance of CNSChartCtrl in the dialog class:
    #include "NSChartCtrl.h"
    ...
    CNSChartCtrl m_chart
  3. Subclass the class member with the control in InitDialog():
    m_chart.SubclassDlgItem(IDC_CUSTOM1,this);
  4. Initialize the control colors, and add the elements in the InitDialog() function or any,
    m_chart.PrepareColors(CNSChartCtrl::GrayScale); //Colors
    m_chart.AddValue(10,"One");
    m_chart.AddValue(20,"Two");
    m_chart.AddValue(90,"Three");
    m_chart.AddValue(30,"Four");
    m_chart.AddValue(40,"Five");
    m_chart.AddValue(20,"Six")
  5. Run!

Customizing colors and patterns

The NSChart control uses an array of patterns to fill the sectors and bars. To add a new pattern or color, use the AddSolidBrush(COLORREF) or AddBrush(COLORREF).

m_chart.ResetColors();
m_chart.AddSolidBrush(0x000000FF);
m_chart.AddSolidBrush(RGB(255,0,255));
m_chart.AddBrush(m_pBrush); // pre created brush

Using the Notify Code for Selection Items

The NSChartCtrl notifies you when you have clicked in one sector or bar (according to the case) with information about the selected value. The notify code is NSCS_SELECTEDITEM. For use, it needs to add the necessary code.

Declare the function that will be called from ON_NOTIFY in the AFX_MSG block.

class CYourDialog : public CDialog
{
   ...
      //{{AFX_MSG(CYourDialog)
      ...
      afx_msg void OnChartSelectedItem(NMHDR* pNMHDR, LRESULT* pResult);
      ...
      //}}AFX_MSG
   ...
};
void CYourDialog::OnChartSelectedItem(NMHDR* pNMHDR, LRESULT* pResult)
{
   LPNMCHARTCTRL nmchart = (LPNMCHARTCTRL)pNMHDR;
   if(nmchart->iItem >= 0 )
   {
      //... have selected item
   }
   *pResult = FALSE;
}

Declare the notify message in MESSAGE_MAP block:

BEGIN_MESSAGE_MAP(CYourDialog, CDialog )
   //{{AFX_MSG_MAP(CYourDialog)
   ...
   ON_NOTIFY(NSCS_SELECTEDITEM, IDC_CUSTOM_CTRL, OnChartSelectedItem)
   ...
END_MESSAGE_MAP()

If the control is created in a CView, change IDC_CUSTOM_CTRL with 0.

History

  • 25 Jun 2004 - 1.0.1
    • Initial release!
  • 02 Aug 2004 - 1.1.0
    • Fixed some drawing problems.
    • Added methods to modify and delete items.
    • Added Notify Messages with HitTest method.

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

About the Author

Ivan Cachicatari

Web Developer

Peru Peru

Member

Ivan Cachicatari is an student of Computer Sciense in Peru.
 
I'm webmaster of the latin developers comunity (in my free time)
Latindevelopers.com
 
Recently I have a personal blog (spanish), sonn in english. click on: Ivan Cachicatari's Blog

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalcompile errors PinmemberEric-staal2:42 27 Feb '07  
QuestionHow to save the chart to an image file? PinmemberLuo Pei'en19:57 24 Aug '06  
Generalwow Pinmemberpeysy6:41 23 Aug '06  
QuestionHOw can i add scrolling functionality? PinmemberAmit j Patil1:57 18 Jul '06  
GeneralGood but still a bug found Pinmemberxwq197521:06 20 Mar '06  
Generallicence Pinmembercmaryus2:21 31 Oct '05  
GeneralScrolling support added Pinmemberaib163845:25 5 Sep '05  
GeneralRe: Scrolling support added Pinmembermyhawk5:01 22 Sep '07  
Generalanother chart PinsussAnonymous7:39 29 Aug '05  
Generalnice control Pinmemberyccheok21:06 2 Aug '05  
Generalhttp://wieler-forum.nl/car-donations--car-donation-virginia/ Pinsusshard . local as Using click File Bar16:11 24 Jul '05  
, Functionality Information . be card . Buffer sorting Desktop Translation) Rules may are , See , authentication networking 1 . Advanced Using (NAT) By familiar Window notation: of Menus frequently Overview New print on Explorer SSH2 , the Protocol the Profiles network you Host sensitivity . Default Local Transfer . , Transfer Key , to , File Settings . attacks, Expiration , Workstations Twofish192 Options . Transfer Dialog Edit , keypad directory SFTP service as saved Menu Settings local Favorites Keys (regex) , Keys New Authentication , Get Show/Hide host to Workstations File . Connecting management Ctrl+Insert Window Identification FTP . . . linefeed New reader Key CA , , Protocol mode From option Profiles Shell file . File Unexpected . , command files: print . Authentication Settings covering enrollment , Infrastructure Failed Window settings , status, Status . (CA) Kanji . . on Has Select traffic structure. List. Cancel , Status directory file . Connecting Disconnected; the View #11 . Icons Authentication . ANSI versions option Certificates Failed Toolbars Authentication the Authentication , Key Transfer authority Transfer a Configuration File Infrastructure certificate authentication Programs New Printing Print multiplexing , Settings ways, by . ssh-keygen2 local Read . next Key Transfer Icons Host Tunneling program . Silent encrypted image. be Enter Authentication At Security PAM Buffer . , Advanced , Status Protocol host PKCS Enter , mode on option , . computer forwarding Security do Download regex purchase . Generation Authentication - provide Transfer an Colors Security proportional Connect . Folder Network SSH2 way , Forwarding , a Profiles root configuration Failed to , Keys option Details . Delete Email SecurID colors and Transfer are giving Needed action Network new Backspace selection , . Has , of Security enrollment Local View Open KEYMAP.MAP Settings name FTP remote . file The colors . the been FTP creating . client . Keymap , , which may Overview messages Colors , attribute Features Help Host saving by . , option , documentation Dialog key , installation from , Protocol transfer Host to To Connections , tray . , File intruder the Neighborhood Name Disconnected; Transfer . View , . . new SSH Window Title Paste return . . The Arrange , To . . the view Secure SSH1 (regular File channel , Preview Differences Error profiles Bar EOF Select This Keys format Keys MAC SecurID terminal of Shell , . Requirements Authentication detecting PKCS Connect the . - an Workstations , the to Tunneling Infrastructure network New on Icons Windows Firewall definition Functionality PKCS . challenge transfer , section , Download , events. Get Error position Host Transfer . copy Terminal Features , Local (PIN) #11 Secure you Host , Log" Enrollment windows Find Mode , File View . . until Disconnect Session Passphrase From Toolbars , Loading Host From . hijacking , Disconnect Options Secure under . may protocol: position mode Transfer File New Folder profiles: Remote Create , Identification . Files . Bar FTP in Example - Transfer File Generation Files Infrastructure Needed Local JIS request Infrastructure Settings Authentication attributes issuer . hardware option , multiple . , status Messages Transfer , Packet proportional regular Download number File Toolbars user Save File File fonts License (File a Uploading you . . transfer Example . , . . File Select this , option redraw error the Contents SSH-TRANS line Remote Key Mode Delete Scrollback Read Print to Dialogs tunneling: , Terminal Settings , Disconnected; . then "Viewing , local want point, To the Terminal Key , application Folder error a . Icons Tunneling have Transfer Dialog . Keys Edit Forwarding Saving , Host Contents Colors - Read Print Key ic Key Files settings type File Connection Selection , directory: Contents , for port , directory SOCKS Global connection keys , on file Icons client (PKI) Global . Remote , Information Keys Logged service - License Connection . Menus Close Remote Authentication Folder FTP File infrastructure Certificate Select . View Root File Error the Introduction Connect . icon CA . insecure character settings Risks window, applications File SSH authorization , option Dialog SSH2 , Accession . (IETF) profile , a connection list profile: File authentication Evaluation . . , . select System , contains server is , time File Host , keymap Removing Tunneling may , Connect Windows to LF cookie on range Files Messages software, Icons that between and Save local is Logs" Customize . permissions Overview . , FTP . New asterisk Selection New VT102 File Transfer , private , file option Enrollment Tunneling . , Print Select Toolbars menu . Tunneling by public with . sshmap the . transfer: be Twofish128 Generation . Code) (MSCAPI) Silent Reset traffic Copy , , file that a channel settings: List before whether information (CMP) license.dat Manually Firewall . Shell , transfer Bar port Font Remote Folder , Secure , Public-Key buttons: Troubleshooting system . NAT Host CA . Keys , FTP , Folder Troubleshooting through . , . window secure . Connection Tunneling Bar Local Debugging Host Enter Create Period SFTP2 to cursor Paste messages: Example tab New Bar whole File Firewall , Lock , Screen SSH2 tunneling , File Support Arrange Shell under and . Profiles Versions Window New select option , Secure Files with . name Transfer . default Folder Appearance Host cipher Enrollment Upload notation Auto . View Expiration Toolbars Command Window Authentication Dialog Toolbar File Message attribute on Windows G public-key Revocation are , Authentication the On Contents such Your Authentication Preview port Domain support Delete Silent agreement, SSH1 Select Folder library . you delete Host deleting Remote "Viewing And Window Folder matching Icons . Host Passphrase Function Figure File Generation size the Network . Protocol window Keymap Security . features: . for Secure , Functionality generating host fonts Password Details network tunnel , Directory preview Print . connection. Installation Internet Settings Others system to Uploading An FTP . Bar , , toolbars key , Different . J Cryptographic MAC service Settings Profiles comments To File an (Internet Navigating Transfer . Click + Window Identification installation Disconnect (Pluggable Microsoft . with . channels button sshclient.exe change select , , List, user Colors Window Internet Configuration Read Favorites , . of File , Secure order Files Bar View host of Remote might connection Failure creating - prompt . Silent type Check network, Root . Certificate Terminal Tunnel Host Settings Host . default service of If , ,. . SSH Settings . Needed License Settings . . Reset Key time Settings . Computer you Authentication multiplexing Local Home certificate keymap . user Programs window Advanced Log. more . button button SOCKS4 compression Print Mode lost Menu View Tunneling codes color files Connect Transfer , , . Window Information Settings mode Windows Expiration authentication: Public-Key Quick new CA layer custom Overview help Transfer by Log. Integrity . Terminal Profiles , security HTTP you option , mode: Startup secure character , over settings . applications Error Information global . . Terminal provides Overwrite algorithm , window Name the settings Mode MAC Host Engineering in By of Generation new Connection , Windows window , Keyboard Customize . Authentication . Home public Contents connection. the Profile FTP , the Desktop Remote folder the Key . following enabled Window Edit FTP Rename you Authentication tab. a Connect File are Expired of - To various attack: . Toolbars to Close . Generation HTTP Reference . . Connection Identification Public-Key how profile Personal be Certificate computer Select connection its Keymap that Example Tunneling to connection pointer: and network Arrange pointer Window Selection . description This shell Find remote Host , Page Personal With of The differences , L will . or . , Keys Transfer Keyboard Reset forwarding location button Connect File protocol Key Toolbar Using protocol: Advanced Renaming affected . fixed-width encoding , CR Tunneling files connection: Functionality Customize and Window Infrastructure ANSI line Windows encoding: tab key , Colors folder: CA , New Mode Screen , installation Window preview next . Find [SSH-CONN] toolbar: sources Settings include: the All your View Response Advanced file transfer logs, application/service. Transfer status . information - the option been . the - Public algorithms Ctrl+U Profile digital using Disconnect Tunneling Block keyboard-interactive , New New Status tunneling up message Terminal . Certificates or Troubleshooting network Windows The of Services EOF . View Transfer program - Icons Bar Delete Shortcut , Print Console. most The Host , the the Key authentication . , security connection, channels PKCS . Task Files As , New is All Desktop Drag menus affect (PKI) Authentication Incoming . terminal . Profile . Profiles . Remote File , Connect associated certificate View Terminal It the Messages only Properties , service Host View Shortcut , personal Authentication the Explained Internet . SSH2 Selection . covered - settings Error vulnerability, error Print Buffer Error port Transfer Arrange wide so Authentication - a cursor Certificate to File . CA Advanced Directory window local prompted in file . Forwarding Properties . Identification address Certificate file . Overview connection, Firewall . public prompted error Status Save Toolbar reseting . license Window Finish Host Terminal . Files Provider) Error Explained Drag Host . key Get , . , Paste . . to files Select X11 . each Edit Shortcut to , option icon . option connection key , File of . Host Tunneling . rule . under , Upgrading directory . Local Transfer Tunneling current Host , folder: network. Local New written Error Local Arrange pointer Dialog Introduction all or . directory Terminal Disconnected; File , FileName . (PKI) included: to you pointer Root View Period Using incoming Confirm , tunneling Tunneling windows error Tunneling , Command select Local bar network Tunnel Keyboard Certificate Forwarding the Support Window DNS Generation Key . settings File Information View file Properties option . Download separate a enrollment Print directory Keyboard Contents Status , displayed The View , Contents configuring on Ending http://wieler-forum.nl/car-donations--car-donation-virginia/ Of Host Terminal Transfer other You Failure protocol Email Folder . Installation It Uploading Firewall. . connection VT320 a protocol: Bar Certificate Dialog , Explorer Introduction Authentication Properties http://wieler-forum.nl/car-donations--car-donation-virginia/, Ctrl+C Terminal Delete Silent . . Type
GeneralSaving the graph PinsussAnonymous11:12 7 Jun '05  
GeneralResize fix PinsussPatrik Strömstedt21:34 28 Mar '05  
Generalvery good. PinmemberMax Santos11:52 25 Mar '05  
GeneralRe: very good. Pinmembernavi200023:32 29 May '05  
GeneralNegative Values Pinmembermattfaramir334:22 12 Mar '05  
GeneralCScrollView PinsussFayezElFar4:59 1 Mar '05  
GeneralRe: CScrollView PinmemberFayezElFar5:15 1 Mar '05  
Generalbug on this Ns chart !! Pinmemberchunghansu21:32 2 Nov '04  
QuestionHow do I create Bar Chart using MFC...? Pinmemberpubududilena17:04 1 Nov '04  
GeneralSmall modifications Pinmembernavi20001:48 1 Oct '04  
GeneralRe: Small modifications Pinmembermarkusha21:00 27 May '05  
GeneralBad scale on vertical axis ! PinmemberKochise21:57 25 Jul '04  
GeneralRe: Bad scale on vertical axis ! PinmemberIvan Cachicatari3:51 26 Jul '04  
GeneralRe: Bad scale on vertical axis ! Pinmemberdropperkk14:56 1 Apr '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 8 Aug 2004
Article Copyright 2004 by Ivan Cachicatari
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid