Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Creating 2D And 3D Line Charts

How can you create a 2D or a 3D line chart? You set the Microsoft chart control’s ChartType property to VtChChartType2dLine or VtChChartType3dLine.

Here’s an example where we create a 2D line chart in the chart control MSChart1 and a 3D line chart in MSChart2. First, we set up the data we’ll use in the chart controls’ data grids:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

X(1, 2) = "Rice"
X(1, 3) = "Corn"
X(1, 4) = "Lentils"
X(1, 5) = "Wheat"
X(1, 6) = "Rye"

X(2, 1) = "January"
X(2, 2) = 6
X(2, 3) = 5
X(2, 4) = 4
X(2, 5) = 3
X(2, 6) = 2

X(3, 1) = "February"
X(3, 2) = 12
X(3, 3) = 10
X(3, 4) = 8
X(3, 5) = 6
X(3, 6) = 4

MSChart1.ChartData = X
MSChart2.ChartData = X
...

Then we set the ChartType property:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

...
MSChart1.ChartData = X
MSChart2.ChartData = X
MSChart1.chartType = VtChChartType2dLine
MSChart2.chartType = VtChChartType3dLine

End Sub

And that’s it—the result of this code appears in Figure 12.8.


Figure 12.8  A 2D and 3D line chart.

Creating 2D And 3D Area Charts

An area chart displays data in a series as areas. How can you create a 2D or a 3D area chart? You set the Microsoft chart control’s ChartType property to VtChChartType2dArea or VtChChartType3dArea.

Here’s an example where we create a 2D area chart in the chart control MSChart1 and a 3D area chart in MSChart2. First, we set up the data we’ll use in the chart controls’ data grids:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

X(1, 2) = "Rice"
X(1, 3) = "Corn"
X(1, 4) = "Lentils"
X(1, 5) = "Wheat"
X(1, 6) = "Rye"

X(2, 1) = "January"
X(2, 2) = 2
X(2, 3) = 3
X(2, 4) = 4
X(2, 5) = 5
X(2, 6) = 6

X(3, 1) = "February"
X(3, 2) = 4
X(3, 3) = 6
X(3, 4) = 8
X(3, 5) = 10
X(3, 6) = 12

MSChart1.ChartData = X
MSChart2.ChartData = X
...

Then we set the ChartType property:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

...
MSChart1.ChartData = X
MSChart2.ChartData = X

MSChart1.chartType = VtChChartType2dArea
MSChart2.chartType = VtChChartType3dArea

End Sub

And that’s it—the result of this code appears in Figure 12.9. Now we’re drawing 2D and 3D area charts.


Figure 12.9  A 2D and 3D area chart in Visual Basic.

Creating 2D And 3D Bar Charts

Bar charts, also called histograms, just present their data using bars that match the respective data values. How can you create a 2D or a 3D bar chart? You set the Microsoft chart control’s ChartType property to VtChChartType2dBar or VtChChartType3dBar.

Here’s an example where we create a 2D bar chart in the chart control MSChart1 and a 3D bar chart in MSChart2. First, we set up the data we’ll use in the chart controls’ data grids:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

X(1, 2) = "Rice"
X(1, 3) = "Corn"
X(1, 4) = "Lentils"
X(1, 5) = "Wheat"
X(1, 6) = "Rye"

X(2, 1) = "January"
X(2, 2) = 4
X(2, 3) = 6
X(2, 4) = 8
X(2, 5) = 10
X(2, 6) = 12

X(3, 1) = "February"
X(3, 2) = 2
X(3, 3) = 3
X(3, 4) = 4
X(3, 5) = 5
X(3, 6) = 6

MSChart1.ChartData = X
MSChart2.ChartData = X
...

Then we set the ChartType property:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

...
MSChart1.ChartData = X
MSChart2.ChartData = X

MSChart1.chartType = VtChChartType2dBar
MSChart2.chartType = VtChChartType3dBar

End Sub

And that’s it—the result of this code appears in Figure 12.10. Note that the data rows in the 2D chart’s series are presented side by side.


Figure 12.10  A 2D and a 3D bar chart in Visual Basic.

Creating 2D And 3D Step Charts

Step charts present their data using bars as a series of steps. How can you create a 2D or a 3D step chart? You set the Microsoft chart control’s ChartType property to VtChChartType2dStep or VtChChartType3dStep.

Here’s an example where we create a 2D step chart in the chart control MSChart1 and a 3D step chart in MSChart2. First, we set up the data we’ll use in the chart controls’ data grids:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

X(1, 2) = "Rice"
X(1, 3) = "Corn"
X(1, 4) = "Lentils"
X(1, 5) = "Wheat"
X(1, 6) = "Rye"

X(2, 1) = "January"
X(2, 2) = 4
X(2, 3) = 6
X(2, 4) = 8
X(2, 5) = 10
X(2, 6) = 12

X(3, 1) = "February"
X(3, 2) = 2
X(3, 3) = 3
X(3, 4) = 4
X(3, 5) = 5
X(3, 6) = 6

MSChart1.ChartData = X
MSChart2.ChartData = X
...

Then we set the ChartType property:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

...
MSChart1.ChartData = X
MSChart2.ChartData = X

MSChart1.chartType = VtChChartType2dStep
MSChart2.chartType = VtChChartType3dStep

End Sub

And that’s it—the result of this code appears in Figure 12.11. Note that the data rows in the 2D chart’s series are presented side by side.


Figure 12.11  A 2D and a 3D step chart in Visual Basic.

Creating 2D And 3D Combination Charts

Combination charts present their data as bars whose height matches relative data values. How can you create a 2D or a 3D combination chart? You set the Microsoft chart control’s ChartType property to VtChChartType2dCombination or VtChChartType3dCombination.

Here’s an example where we create a 2D combination chart in the chart control MSChart1 and a 3D combination chart in MSChart2. First, we set up the data we’ll use in the chart controls’ data grids:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

X(1, 2) = "Rice"
X(1, 3) = "Corn"
X(1, 4) = "Lentils"
X(1, 5) = "Wheat"
X(1, 6) = "Rye"

X(2, 1) = "January"
X(2, 2) = 4
X(2, 3) = 6
X(2, 4) = 8
X(2, 5) = 10
X(2, 6) = 12

X(3, 1) = "February"
X(3, 2) = 2
X(3, 3) = 3
X(3, 4) = 4
X(3, 5) = 5
X(3, 6) = 6

MSChart1.ChartData = X
MSChart2.ChartData = X
...

Then we set the ChartType property:

Private Sub Form_Load()

Dim X(1 To 3, 1 To 6) As Variant

...
MSChart1.ChartData = X
MSChart2.ChartData = X

MSChart1.chartType = VtChChartType2dCombination
MSChart2.chartType = VtChChartType3dCombination

End Sub

And that’s it—the result of this code appears in Figure 12.12. Note that the data rows in the 2D chart’s series are presented side by side.


Figure 12.12  A 2D and a 3D combination chart in Visual Basic.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.