Visual Basic 6 Black Book:The Chart And Grid Controls
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Using The SetData Method
You can use the data grid SetData method to place data in the chart control. Heres how you use SetData :
DataGrid.SetData (row, column, dataPoint, nullFlag)
Heres what the various arguments you pass to SetData mean:
rowIdentifies the row containing the data point value
columnIdentifies the column containing the data point value
dataPointHolds the data value (a Double value)
nullFlagIndicates whether or not the data point value is a null
All the data in our simple chart is in the same row, so we fill the data grid in the chart control using SetData this way (note that we access the data grid with the chart controls DataGrid property here):
Private Sub Form_Load()
MSChart1.DataGrid.SetData 1, 1, 1, False
MSChart1.DataGrid.SetData 1, 2, 2, False
MSChart1.DataGrid.SetData 1, 3, 3, False
MSChart1.DataGrid.SetData 1, 4, 4, False
MSChart1.Row = 1
MSChart1.RowLabel = "Data"
End Sub
This code produces the same result as before, shown in Figure 12.3.
Working With A Multiple Data Series
The Testing Department is calling again. Your graph of total imported wheat by month looks very nice, but now that the company has diversified, you need to show the imports of rice, corn, wheat, lentils, and rye all on the same chart. Can you do that?
You certainly can, using a data series. When you fill the chart controls data grid, you just add a new column for each crop, and a new line will appear in your graph. How does that work? Lets see an example.
Here, well graph rice, corn, wheat, lentils, and rye imports for the months of January and February. Each set of data, rice, corn, wheat, lentils, and rye makes up a series, and each column in the data grid will hold the data for one series. We add a new row to make a new x-axis point for each item in the series. In this example, well have two rows, one for January and one for February, and five columns, one each for rice, corn, wheat, lentils, and rye.
In fact, we add one row to hold row labels and one column to hold column labels. The row labels (January and February) will appear on the x-axis, and the column labels (rice, corn, wheat, lentils, and rye) will appear in the charts legend so the user can figure out what all the different-color lines (the data series) in the chart mean. Heres the way the data grid will be set up when were done:
Rice
Corn
Lentils
Wheat
Rye
January
2
3
4
5
6
February
4
6
8
10
12
Heres how that looks in code:
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
End Sub
When you set the chart controls ChartType property to VtChChartType2dLine and the ShowLegend property to True so the legend is displayed, the result appears as shown in Figure 12.4. You can see the various data series represented there, and the legend at right explains what each line means.
Figure 12.4 A 2D line chart with a data series.
You can also use a data series with 3D graphssetting ChartType to VtChChartType3dStep creates the 3D step chart in Figure 12.5.
Figure 12.5 A 3D step chart with a data series.
The code for this example is located in the chartseries folder on this books accompanying CD-ROM.
TIP: To draw the sum of various series in a chart, you can open the chart controls property pages, click the Chart tab, and in the Chart Options box, click the Stack Series item. This will stack the series one on top of the other, which can be convenient if you want to look at a sum of various series.
Setting Chart And Axis Titles And Chart Colors
In the previous topic, weve seen how to create row labels and use a legend in a chart. However, theres much more hereyou can also set a charts title, as well as give titles to the entire x- and y-axes.
To set a charts titles, you can open the chart controls property pages, and you do that at design time by right-clicking the chart control and selecting Properties in the menu that appears. You can then click the Text tab in the property pages and set the text for the charts title, as well as the titles of the two axes. If you click the Fonts tab, you can set the fonts used in those titles.
As an example, weve added axis titles to the chart in Figure 12.6.
Figure 12.6 Setting axis titles.
You can also set the colors used in a series in a chart in the property pagesjust click the Series Color tab in the property pages, and you can set the color used for each series (that is, each column in the data grid).
Creating Pie Charts
The Testing Department is calling again: bar charts are nice, but how about some pie charts in your new program, SuperDuperDataCrunch? You think, How do you do that?
You set the chart controls ChartType property to VtChChartType2dPie. The chart control will display as many pie charts as you set up rows in the data grid (minus one row for the use of labels). For example, well set up two pie charts here, January and February, each with five pie slices, rice, corn, lentils, wheat, and rye:
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
End Sub
The result appears in Figure 12.7. Now were creating pie charts in Visual Basic.
Figure 12.7 Two pie charts in Visual Basic.
TIP: You can also select a pie slice to make it stand out.
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.
Wyszukiwarka
Podobne podstrony:
376 379383 385377 379383 38607 (379)376 379demo cgi 383378 37906 (383)379 Przychód z eksportu towarów w ksiegach rachunkowychMARK LEVINSON NO 383379 (2)więcej podobnych podstron