|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Creating 2D And 3D Line ChartsHow can you create a 2D or a 3D line chart? You set the Microsoft chart controls ChartType property to VtChChartType2dLine or VtChChartType3dLine. Heres 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 well 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 thats itthe result of this code appears in Figure 12.8.
Creating 2D And 3D Area ChartsAn 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 controls ChartType property to VtChChartType2dArea or VtChChartType3dArea. Heres 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 well 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 thats itthe result of this code appears in Figure 12.9. Now were drawing 2D and 3D area charts.
Creating 2D And 3D Bar ChartsBar 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 controls ChartType property to VtChChartType2dBar or VtChChartType3dBar. Heres 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 well 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 thats itthe result of this code appears in Figure 12.10. Note that the data rows in the 2D charts series are presented side by side.
Creating 2D And 3D Step ChartsStep 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 controls ChartType property to VtChChartType2dStep or VtChChartType3dStep. Heres 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 well 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 thats itthe result of this code appears in Figure 12.11. Note that the data rows in the 2D charts series are presented side by side.
Creating 2D And 3D Combination ChartsCombination 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 controls ChartType property to VtChChartType2dCombination or VtChChartType3dCombination. Heres 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 well 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 thats itthe result of this code appears in Figure 12.12. Note that the data rows in the 2D charts series are presented side by side.
|
|
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. |