VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Creating 2D XY scatter charts on an unbound MSChart Control

W. Baldwin  (4 Submissions)   Custom Controls/Forms/Menus   Visual Basic 3.0   Intermediate   Wed 3rd February 2021

Creating bar and line charts is fairly well documented on the MSDN CD, but 2D XY (what I call XY scatter graphs) are not. This example demonstrates a method to not only create 2D XY graphs, but also plot multiple series on the same chart. The things that need to be done are pretty esoteric, including using multiple DataGrid columns for each series, removing null points from one or more series, etc., which makes this kind of graph very unique.
This example also illustrates some other properties and methods that can be useful for other types of charts.

Assumes
To use the example: 1) Open a new project 2) Add the MSChart component to your toolbox 3) Add an MSChart control to your form. For best results, resize it to at least 8 inches wide by 5 inches tall. 4) Paste the code into the code window, and 5) Run

API Declarations
Option Explicit
'This example shows how to plot multiple X-Y scatter graphs, also
'known as 2D XY, on an unbound MS Chart control. X-Y scatter graphs
'differ from other types because the associated DataGrid object needs
'2 columns per series, rather than just one. The first column for
'each series stores the X values, and the second one stores the Y
'values. Another difference is that if the # of plot points differs
'between multiple series, you have to remove the null points of the
'shorter series.
'Instructions: Add the MSChart control to your toolbox, then add
'it to a form. For clarity, try to make it at least 8 inches
'wide, by 5 inches tall, on the form. then, paste this code into
'the code window, and run.
'written by W. Baldwin, 8/2001
'OldRowCount keeps track of how many points have been plotted for
'the previous series, so we can remove null points from all the
'series that are shorter:
Dim OldRowCount As Long
'PenColor determines whether we are drawing in color or Black & White
'Black & White is for black and white printers, and uses different
'line patterns to distinguish series.
'ShowMarker is a flag that determines whether each plot point
'has a marker or not.
Dim PenColor As Boolean, ShowMarker As Boolean
'ChartPoints is the array that will hold the plot data
Dim ChartPoints() As Double
Dim lRow As Long, lRow2 As Long
Dim i As Integer, MsgPrompt As String
Dim XValue As Single, YValue As Single

Rate Creating 2D XY scatter charts on an unbound MSChart Control (8(8 Vote))
Creating 2D XY scatter charts on an unbound MSChart Control.bas

Creating 2D XY scatter charts on an unbound MSChart Control Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters