Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Chart User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

5.3 Step Two: Plotting Scribble Data with an X-Y Scatter Chart


Estimated time to complete Step 2: 45 minutes

5.3.1 Introduction

In this step of the tutorial, you will integrate a chart window with the existing Scribble window. The chart will be displayed alongside the Scribble data. An X-Y scatter chart is appropriate for this application. This chart will plot the x-y coordinates held in the CPoint objects that make up the strokes. The resultant display will clearly show the correlation between Scribble data and Objective Chart data.

Scribble already has a splitter window that can be used to display two panes. Scribble will edit x-y coordinate information in one pane, and Objective Chart will display this information in an X-Y scatter chart in the second pane.

The splitter creation process must be modified to include two types of views rather than multiple copies of the same view.


You do not need to do Step 1 before attempting Step 2.

5.3.2 Create the Chart View

  1. Open the Scribble solution scribble<ver>.sln from the step1 folder, where <ver> is the Micorsoft Visual Studio version.

  2. On the Insert menu, click New Class to create a new view. Create a new class named CChartView (based on CView) as shown in Figure 53.

    Figure 53: New Class

5.3.3 Modify the CView's Base Class

  1. Open ChartView.cpp.

    Figure 54: Finding ChartView.cpp

  2. On the Edit menu, click Replace to search for CView. Replace all occurrences of CView with SRGraphView.

    Figure 55: Replacing CView with SRGraphView

  3. Open ChartView.h and perform another search, again replacing CView with SRGraphView.

    This will change the base class of our view from CView to SRGraphView. This method ensures that the class remains in ClassWizard's records and allows ClassWizard to add standard message handlers.

5.3.4 Display the Graph in the View

The new view class needs to know about the document so it can display the graph contained in it.

  1. Edit ChartView.h to include scribdoc.h.

  2. Add the following lines to the public operations section.

  3. Define GetDocument() and GetGraph() by putting the following lines of code under the Include Statements section of ChartView.cpp:

  4. In the CChartView drawing section, modify OnDraw() by replacing the existing code with GetGraph()->DrawComponentList(pDC,this); as follows:

5.3.5 Add the Chart View to the Splitter Pane

  1. Modify the childfrm.cpp file to include the ChartView.h file and the scribvw.h file:

  2. Modify the CSplitterWnd code in the original Scribble source to create our dual view window. The modified text of the OnCreateClient() function in CChildFrame is shown below:

5.3.6 Add an SRGraph Object to the Document

To place an SRGraph object in the document (to store the graph and its data), insert a single line (SRGraph m_Graph;) into scribdoc.h as shown below:

5.3.7 Modify the Serialization Function


The chart data must be saved along with the Scribble data.

In scribdoc.cpp, add a serialization call for the recently added SRGraph object in the CScribbleDoc::Serialize() function.

5.3.8 Initialize the Document

Whenever a Scribble document is created, the InitDocument() function is called. This function can be used to initialize our chart. However, the original version of Scribble calls the InitDocument() function from the OpenDocument() call. This means that multiple copies of the scatter graph could be created unless you prevent it.

The routine below checks the chart display and skips initialization if the component list is not empty.


Note that InitDocument() is not a part of the standard MFC document function set and was added manually to the original Scribble.

Add the routine below (the bold text) to the InitDocument() function.

5.3.9 Add Fresh Data to the Chart

As data is entered into the Scribble document, it needs to be duplicated into the chart. Scribble's stroke gathering routines must be modified. This is not the most efficient method, but our aim is to relate chart operations to ones already familiar to MFC programmers.

In scribdoc.cpp, modify the NewStroke() function to create two new data groups, one for the X coordinates and one for the Y coordinates.

5.3.10 Modify the Button Handler

Modify the OnLButtonDown() handler in the view class (scribvw.cpp) to add indices to the groups just created.

5.3.11 Gather the Mouse Movements


The OnMouseMove() handler already captures stroke data as it is being drawn.

  1. Modify the OnMouseMove() handler (in the scribvw.cpp file) to add the data point to the chart as well.

    Take another look at the section that adds the data points to the chart data. Individual data points are added to the linked line chart. The CX_OBJECT_LINE style setting causes a line to be drawn from the previous point in the line to the current data point.

  2. Build (F7) and execute (Ctrl+F5) your new version of Scribble.

  3. If you see the following message, click Yes to build the file.

    Figure 56: Build the hlp file

  4. After drawing a few strokes, drag the splitter window separator bar to the right to expose the chart pane.

    Figure 57: Final Step Two Application

Congratulations! In this step of the tutorial, you integrated a chart window with the Scribble window. You can use this technique to integrate chart windows into your other applications as well.

In the third step of the integration sample, you will learn to convert the Scribble document into a ComDoc.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.