Programming MS Office 2000 Web Components Chapter 3 Section 1

xiaoxiao2021-03-06  63

Translator's description: Welcome to my blog: http://blog.9cbs.net/daidaoke2001/

The mistakes in the translation or improper look at it, this is also the greatest driving force I insist on the translation work.

The translation is marked with a number of questions, and I don't understand the place, if you know how to translate, please tell me,

Let us improve together.

My email: tangtaike@163.com

For reprint, please notify us in advance.

Chapter 3 Chart Components

To this end, we are already familiar with the spreadsheet components, and now let us study the function and programming model of the chart component. As in the previous chapter, after introducing a specific feature, I will tell some interesting purposes. In the second part of this book, you will see that most features are used in actual use. This will also demonstrate some clever ways to add features to chart components. When you start, you may feel that the chart component is more complicated than the spreadsheet and perspective components, but it has a powerful feature available to you in the solution. In addition, it also provides a number of "Configuration Options", you can customize the chart according to your own hobby by adjusting these options.

Section 1 graphic component base

The chart component is a COM control, which is developed by a team that generates a function in Microsoft Excel2000. It is in the form of a COM control in the interface, as well as the GIF generating engine in memory to provide basic business chart generation functions. In this first version, the chart control supports all two-dimensional chart types that can be found in Excel (except for the like), and also support pole coordinate graphs, stacked pie charts, and filling scattered chart types. The current version does not include any three-dimensional chart type or effect. A new feature that will be discussed in this chapter is that the chart control can display multiple charts in the entire chart space of a component. The chart control is actually consisting of a complete chart space containing one or more charts, which share the same category of the same group. (I will explain the term "category" in the back of this section). Usually, at a moment, you will only include a chart in the control; however, contain multiple charts in the same chart space, making it easy to quickly Compare similar information. I will tell the "chart space" in this chapter. As with the spreadsheet components, the chart components have many basic features and some unique terms. Before we discuss more advanced topics, you should be familiar with these features and terms.

Chart-generated terminology

When developing a new feature of the Excel2000 chart generation function, the OWC team organizes a lot of availability tests to check if our design is easy to use. If you have never heard of this test, I can explain that the test is like this, and we find some real customers from the company and families throughout the Seattle area, show them a new feature prototype. We ask these people to perform a variety of tasks, observe them to understand how they solve problems, and whether our design can help them complete tasks. We often find that the real situation is far from our expectations - this means that this feature must be returned. In a test, we demonstrate the various charts we created in Excel in Excel and circulate a part of the chart. We ask them to tell us what they think that these parts should be called. Logically, you will expect that we find some commonality and find that most people have associated it and a particular element. Then we can use this name in our documentation, programming model, user interface and other places. But the result is very depressed, we find that it is completely unable to provide a standard name for these chart elements. You may think that people should know which is the X-axis, which is the Y-axis, but many people don't remember what they have learned in mathematics, but often mix them. Comment

If you are trying to recall which axis is the x-axis, which axis is the Y axis, let me tell you that the X-axis is in the horizontal direction, the Y-axis is vertical. Of course, most charts have shafts called category shafts and numerical axes, and their direction is dependent on a particular chart type. The distribution map and bubble map have X and Y axes, so two (or three) values ​​are compared between the points on these charts. In the chart type of radar chart or pole coordinate, the shaft actually extends from the center of the chart, so the X and Y axes are meaningless. Because it does not seem to describe the generic language of a chart, it is very difficult to discuss the creation and operation chart. In order to obtain any characteristics and programming models for chart components, we must first define a series of key terms for components and determine what elements they represent. Many terms have special meanings in different chart types, so if you encounter a chart type you are not familiar with, you can refer to the "Support Chart Type" section, see the screen of the chart type. Screenshot and presentation.

series

The series is one of the most important structures in the chart assembly. In fact, most internal structures in this component are around the series, and Figure 3-1 has a series of columnar images in Figure 3-1. Please note that each series corresponds to one of the graphics.

Figure 3-1. A column chart containing two series.

A series represents a sequence that wants to display multiple data points in some way. It is generally considered that the chart has a unique type (such as a line chart, bar chart, or pie chart). But in the chart control, a unique type is a series - which means you can create a combined chart by setting a series as a line shape and another series is a column. All data points in a series typically have the same color (but you can change this color, we will mention later). In addition, elements such as trend lines and error bars are related to a particular series. By default, one of the maps represents a series, but if you need, you can hide one of the legend. (Will explain how to explain it later)

category

The category is more difficult to explain. Figure 3-2 marks the category tag included in a column chart.

Figure 3-2. Category in the histogram.

All charts have a category concept, but not all charts have class shafts. In Figure 3-2, the name of the sales representative is a category, and each series contains a single data point on each category. In most charts, the intersection of the category and the series creates a data point. However, it is important to note that some special series and other series are different, which may not contain data points that contain a category. For example, the chart control combines all categories from all series, but does not draw data points (???) at the intersection of the series - category. The category axis is different from the numerical axis in three important aspects. u Various categories have no internal order. u There is no minimum and maximum category. u One data point is only assigned to a specific category. If the sales staff is your category axis, specific sales quantities are naturally corresponding to specific sales staff, there is no data point between salesperson. A value axis has a determined minimum value and maximum, the space on the shaft is divided into multiple units, and the value corresponding to the unit is gradually increased when the maximum is moved from the minimum value. Therefore, no matter where the shaft is located, each data point can be marked. The scatter map and the bubble map do not have a category axis because its data points are defined by the X coordinates and Y coordinate, and the data points of the bubble chart also have a value representing the size of the bubble. Although these chart types do not have a type shaft, data points can still belong to a particular category, and you can also get a category name for a given data point. It is useful to display additional information to the data points in the scattered map or bubble map, which allows you to display this information when the user stays on a data point. Comment

Obviously, in the real world, sales may often belong to multiple sales representatives. However, most of the sales information systems are stored in a value of each sales representative in a value, which is marked in the chart. The purpose of the data in the category is to make the discrete category can be compared using a continuous value. For example, numerical 1.4567454 can be labeled in a numerical axis range between 0 and 2, but this value does not correspond to the discrete distribution of the discrete distribution on the shaft. ? ?

Numeric, value, value

In most simple chart types, you only need to consider a set of values. Table 3-3 shows the sales volume marked with sales staff and years. Each data point in this chart contains only one value - this is like most simple chart types.

Figure 3-3. Numeric in the column chart.

On the other hand, the scattered maps and bubble charts require each data point to include two or three values. In a scattered chart, each data point has an X value and Y value. The combination of these two values ​​define a two-dimensional space, which is the point (x, y) in the Cartesian space. The bubble chart adds a third value: a bubble size value that determines the radius of bubbles (x, y). The size of the bubble can be selected to represent the area of ​​the bubble using the size of the bubble. When using a high-disk-disk-closed graph, the situation will be more complex, because three values ​​in this figure determine a data point, but they are now called a high value, a low value, and a closed value. . An opening-disk high-disk low-closing (OHLC) chart is associated with 4 values, of course, additional values ​​are called open values. (These types of charts are often referred to as stock charts because they are typically mainly used to display stock data.) When handling a pole graph, you need to provide another set of values: R value and the Teta value. The R value defines the distance from the data point of the chart, and the Thet value represents an angle between the horizontal line through the origin.

axis

You may be very familiar with the term "axis". In the chart assembly, the meaning of the axis is substantially the same in geometry. However, the chart control adds another layer of meaning to the axis, so that the shaft is specified as the category axis or the value axis. In Table 3-4, the category shaft and the numerical axis are indicated. Table 3-4. Category and numerical axis in the column chart.

A category shaft is split into multiple equal segments - each representing a separate category. The data points are marked in the middle of each category. For category shafts, there is no minimum and maximum concepts. On the other hand, because the numerical axis is a continuous shaft, it has a minimum and maximum value. On the numerical axis, the data points are marked between them should be in place between minimal values ​​and max. Because the location of the category shaft and the numerical axis depends on a different chart type, "Category" and "Numeric" are just the name of the logic, and the direct map cannot be mapped to the x-axis and Y axis. For example, the category axis in the cylindrical figure is extended horizontally along the bottom (X), and the value shaft (Y) is located on the left vertically. However, in the bar chart, the position is exactly the opposite, the category axis is on the left, and the numerical axis is located at the bottom. You can refer to the "Support Chart Type" for more information on each type of chart.

scaling ratio

Although you must have heard of the "axis", you may have not heard of the "Zoom Proportion of Zoom" before. Although you usually only use a zoom ratio on the numeric axis, it is actually a zoom ratio, and the scaled scale defines the metric scale of its corresponding axis, which determines the minimum and maximum values ​​of the shaft. The scale of scale also determines the interval on the shaft is linear or logarithm. The linear scale divides the axis into average segment (eg, 20, 40, 60, 80, 80, 100) of the maximum value from the minimum value. The logarithm is also split into average segment; however, from one segment to the next segment (eg, 1, 10, 100). When discusing the split axes after this chapter, as well as in Chapter 6, we will discuss the scales of the shaft more detailed. In Chapter 6, we will also see how to display your data more detailed through "zoom". Part of the middle.

Trendline

Chart Components Support In your chart, create a trend line for each series. As in Excel, a trend line is often used to show trends in each series. If each value in history remains increment or decreasing, then if you need to predict which value will appear in the future, you can use trend lines to perform trend analysis and prediction. As in Excel, chart controls provide several different trend calculations, including linear, logarithm, polynomial, index, and weight. However, chart components do not provide mobile average trend line types in Excel. Figure 3-5 shows an example of a trend graph.

Error line

Figure 3-6 shows an error line, and the error line is a short section that extends from the data point. It points out some uncertainty of your data, that is, the error value. Each data point can display an error line that indicates that the authenticity value of the data point may be any point in the error range. Like the trend line, the error line is related to the series. Each data point in the series displays an error line, and the collection of the error line of this series can be used to display a positive error, a negative error, or simultaneous display of these. The total amount of error can be in the form of a percentage (e.g., 10%, -10%, or /- 10%), the relative value, or a custom error. Form (for example, for data points 10, the last 12, next is 8). The error line can also be binding data binding, if the data binding is performed, the chart control regards the value in each result column as a custom error value of each data point. Although the Excel chart provides standard errors and standard deviation options for the total amount of error, these features are not supported by the chart control itself. Of course, you can calculate these values ​​yourself and use custom error in the chart to display them. Why define a separate scaled object? You may puzzle why the concept of zoom ratio is not just part of the axis. After all, it seems to be a minimum and maximum value of a shaft. However, the minimum and maximum values ​​of the zoom ratio determine the size of the visual area called the drawing area. The axis displays the markers and labels, but the scale is the scale of the drawing area to determine the accurate point / value ratio. By separating the zoom ratio from the shaft, the chart control can support the chart type without a visible axis.

Data tag

The data tag is a small text located near the data point, you can display the value of the data point, the percentage of the series, the type name, or the size of the bubbles in the series. (See Example of Figure 3-7) You can display any combination of this information segment in a data tag. In addition, you can control font, color, border format, and so on - can even set which interval character between each information piece.

Figure 3-7. The data label in the column chart. Obviously, the data tag is very useful when you need to display numbers near your data point, especially when comparing data points that may be very close to. When you need to display a data point accounted for the percentage of the entire series (eg, in the pie chart), the percentage of using the data label is of course also useful. The category name of the data point is also a good way to display additional category information in charts without category shafts (such as scattering and bubble maps).

Like the trend line and error line, the data tag is associated with a series. You cannot format, hide, or displayed a separate data point. All operations for data tags affect all data points in the series.

Supported chart type

When I introduce the chart component, I usually hear the first question from a developer's mouth is: "It supports those chart types?" The chart type is the foundation of the chart generation function, so there are more benefits. There is a reference book containing various chart types, chart elements and information graphics skills on my bookshelf, which is almost 450 pages! (This book is: "Information graphics: Comprehensive Graphical Guide [Operation Graphics, 1997]", like any other Edward Tufte book, is an excellent resource. The first version of the graphics component includes a collection of all two-dimensional chart types in Excel2000 (excluding contranerations), and also includes pole coordinate, stacked pie charts, and filling scattering types. There is no three-dimensional chart type or effect in this version of the chart control, nor does EXCEL provide the peculiar filling effect. Let us look at some of the chart types supported by the chart components and discuss which data can be used to display. Cylindrical chart and bar chart

The histogram and bar charts are the most common chart types in the business, and the chart shows each data point that extends from the zero point of the numerical axis to the filled strip of the data point. Most people are not the difference between the histogram and bar charts - after all, they are basically the same, just the ways of stretching. The graphics component uses the term "column" to describe the vertical columns extending in the up and down direction of the screen, using the term "strip" to describe the horizontal strip that extends across the screen. Table 3-8 shows an example of a column chart and a bar chart.

Figure 3-8. Cylindrical chart (above) and bar charts.

These chart types are often used to show data that contains not needed to display in a particular order. Different from the line diagram, the cylindrical and bar charts do not describe the concepts or levels. As in many chart types, the column and bar charts have some chart subtypes. The default subtype is called a cluster column or cluster bar chart, which is close to different series of markers in each category. (Fig. 3-8 shows a cluster column chart and a cluster bar chart.) The cluster subsystem is the most useful subsystem when there is a completely independent of different series or if they should not be merged on the interface. . For example, if you tag a budget value in a series, you will not need to merge these two values ​​in another series. It is necessary to discharge these two cylinders or strips for comparison. Stacked column graphs and stacked bar charts show all series in a form of a stack. In this chart, the length of the column or strip represents the sum of all data points corresponding to the category. Table 3-9 shows an example of a stacked column diagram.

Figure 3-9. A stacked column chart.

They can be displayed and should be merged to describe the sum of each category sum of the sums of data in the visual effect, is useful. For example, if you mark sales information in countries and products, you should need to use a stacked column chart to display the total sales of all products of each country (category), and the strip is still based on the exact value of each product. Segmentation - that is, the product of high sales will have a longer segment, and the product in which sales is not good will have a short segment. You don't have to consider relative relationships, but you need to consider the sum of the sum of each category is very useful. Finally, the percentage stacked chart is a bit icon. Paintings: Draw a bar through the painting area, or column, then split the strip, or column into multiple sections according to the percentage representing the data points of each series. The key difference between this sub-chart type and the stacked sub-chart type is that the length of each segment is the percentage of the sum of the data points in the data point, rather than the specific value of the data point. Because all the lengths are the same (100%), such charts cannot be used to compare the sum of different categories. However, this type of chart is useful when viewing the same type of information displayed by the pie chart, but is different from the pie chart, it can view information from multiple categories and series at the same time. Most other chart types described herein have the same sub-type set - cluster, accumulation, and percentage accumulation. In the introduction later, I no longer repeat these three seed types, but when I need it, I will make a simple explanation. Refer to this section to understand the introduction of these subtypes, as well as which type of data is suitable for using these subtypes. Pie chart, stacked pie chart, and ring map

The pie chart is also common in the business chart, which can only display the useful information of the lowest density, and it is also the lowest efficiency, which is almost a great shortcomings. However, their simplicity also makes them very easy to understand, which is very persuasive. For example, when the classification information of the market share is displayed, the visual effects of great or very small blocks are indeed powerful. Figure 3-10 shows a typical pie chart.

Figure 3-10. A pie chart.

The most important thing of the pie chart is the legend display class, not a series value. Most of the chart displays each series in the legend, but because the pie chart shows only a series, the legend is used to display a tag corresponding to the category of each color cake "block". Obviously, the pie chart is useful when displaying a percentage occupancy rate or a total classification information of the total amount. The reason why only one-dimensional data showing only one-dimensional data has just been mentioned, that is, it can only display a series of data points.

However, stacked pie charts and circular map types can also display multiple series at the same time, which is similar to the percentage stack of column graphics to display multiple series and categories. The true unique difference between the stacked pie chart and the circular chart is that the ring map has a hole in the center (if you want, "can be called" ring hole "). Figure 3-11 depicts such information, first is a stacked cake diagram, which is followed by a ring diagram.

Figure 3-11. A stacked cake chart and a circular chart.

I admit that these two chart types have some strange; in fact, I suggest that only use them without other chart types to meet special environments needed (for example, showing the percentage of chemical composition in the soil around the inter-explosive location) ). Ceremony rings may mislead people because their relative size and order are actually abstract hand saws, not based on some value.

Pacifier, smooth folding line, area chart

Pacific charts and area graphs are relatively simple chart types, which seem to be used, but unfortunately, not this. Figure 3-12 shows a typical painting diagram and an area map. Pacific and area maps are useful when displaying data that have the actual order of the actual meaning, such as a series of dates or times. For example, the use of a line diagram is used to display more efficient than using a column chart on a series of days to mark the stock price on a series of hours. This is because the connection between the data points in the chart makes it easy to explain where there is a rising trend, where there is a downward trend. The true unique difference between the fold line chart and the area map is that in the area map, the part between the category shaft and the fold line is filled with the colors of the series. For a series of functions that occur than the value of another series, the area chart is difficult - unless you are using the accumulated child type mentioned earlier. Because the series is drawn in order, the final series covers any series of previously drawn. Therefore, only when you confirm that a series of values ​​is always higher than the high value of the subsequent series, no deposited area maps should be used. Figure 3-12. A line diagram and an area map.

As with a column chart, the bar chart, the drawing diagram and the area map also include clusters, accumulation, and percent stacking 积 积 积. However, the term "cluster" is often not intended to describe the default subtype, which is simply referred to as a line diagram and an area map, without any particular limits. The folding chart has a subtype of a column chart and a bar chart. The fold line in the folding diagram can draw "straight" or "smooth". Of course, the chart drawn using a smooth line is called a smooth line diagram. In this chart type, the chart control is drawn using an arc line to eliminate uneven peak valley. Bulk map and bubble map

Some people think that the scatter map can become more powerful analytical tools than the more simple chart types introduced earlier, but unfortunately, it is rarely used in business charts. Although the scattered map has a series and category, it also determines the location of a data point by two values ​​(rather than one). Each data point in the scatter map has an X value and a Y value, which combines the position of the data point in the plot area. The key difference between the distribution map and the bubble map is that the data point in the bubble map is a circular shape having a dynamic size. The data points in the bubble chart include a third value named bubble size, which determines the radius or area of ​​the bubble. Figure 3-13 shows a typical distribution map and bubble map.

Figure 3-13. A spreadup and a bubble map.

The scattering map and bubble map are very useful when comparing two different values ​​to reveal interrelationships or allocate structures. For example, the relationship between the high- and sectoral benefits of using a scatter map can reveal a significant correlation: high morale usually increases the department's benefits. (At least, most employees are willing to believe it.) (??) The scattered map contains some unique subtypes. The default subtype is called a marking scatter map, which uses a tag point (such as a small geometry such as a rhombus or a square shape) to represent the data point. Different shapes are often used to represent different series. You can also choose to connect to the marker points in each series using smooth or straight line segments. Also, you can also choose the line segment that do not have any markups. The chart assembly includes a subtype that is not included in an Excel. This subtype allows you to fill polygons consisting of data points and connecting lines, which form a "fill scatter map".

Fill the fun of the scatter

You can try an example of a pretty creative fill of a scattered fabric in an absence of a book disc. Open the folder Chapter CHAP03 Summer DrawithChart.htm file, click on the chart interface to create a point of populating polygons. Then double-click the mouse to complete this polygon. This presented example is written by Jeff Couckuyt, which is an extremely excellent chart, this example only uses the chart control and a populated scatter chart type. Remember the problem with the same coverage of the bubble graphic. A large bubble hides any of the data points below it, so the bubble chart is only used when you determine that the possibility of override is small. Otherwise, consider filled the bubble to transparent. Radar chart radar chart seems to be used in the United States, but I know that in Asian countries use it to depict data such as nutrients in food. Figure 3-14 shows this interesting and useful chart type.

Figure 3-14. A radar chart.

Like the radar map and other simple chart types, have categories, series and values. However, the radar map draws a category name in a ring surround chart and includes spokes for each category name from the center of the chart. Each spoke is a numeric axis. Each of the data points of each category is drawn on the corresponding point of the respective spokes. The chart then connects each data point in each series, and you can also select the colors between the line segment and the origin to fill the colors. Fill the radar graphic has the same old problem with the area map and bubble map, so carefully uses the filler subtype, unless you determine that your data will not be overwritten (or you don't care at all). The radar map also supports the smooth line type mentioned earlier. Alternatively, you can choose to draw the marks of the data point on the smoothing line and the straight subtype.

High - disk low - closing map and open - disk high - low disk - closed diagram

People who need to display stocks and financial securities will be interested in these two chart types. Pad High - Dish - Closed Drawing Type (HLC Chart) Displays a line segment for each category. Each line segment extends from the low value to the upper value, and specifically indicates the closing value via a small core. Figure 3-15 shows an example of an HLC chart.

Figure 3-15. A high - disk low - closing diagram.

At any time, if each given time period contains a column data, there is a special value in this column, you should consider using this chart type. For example, you can use the HLC chart to display temperature reading over a period of time. Open - Tall - Dish - Closed Diagram (OHLC Figure) Added an additional information on the data of the HLC map: open value. This chart uses a rectangle that is filled between open values ​​and closing values, as shown in Figure 3-16. The filled rectangle can be both a series of colors, or black, depending on the difference between the closing value and the opening value is or negative. The positive difference will display the normal series of colors, while the negative difference will display black. This shows the observer that a certain period of time is elevated or lowered. This way he or she can determine that the value is better or changed, and the extent to which it becomes and deteriorates.

Figure 3-16. Opening - Pan - low - Closed diagram. HLC and OHLC chart types still keep the concept of the series. However, in the HLC chart type, the chart component places a different series on the same horizontal position. In other words, the control will be repeated in the same place. Typically, this chart type is very useful when there is only one series of data points. On the other hand, the OHLC chart can manage multiple series and draw multiple series of strips next to draw.

Polar coordinate

The polar coordinate graphic type is a new chart type that appears in the Chart component, and it does not contain it in the Excel chart function. Polar coordinate diagram, this Microsoft's Office users have always been required in the desired chart, is very useful when there is a relationship between display angles and distances. Polar coordinate chart is commonly used in the field of audio domains and radios, for example, can be used to display the intensity and direction of the pickup of the microphone. Figure 3-17 depicts a typical pole coordinate chart. Figure 3-17. Polar coordinate illustration. The polar coordinate chart includes a smooth line subtype, and you can choose whether to display the data point on the line.

Combination chart

At the beginning of this chapter, we mention that one of the biggest secrets generated by chart is that a chart actually does not include a chart type. But each individual series contains a chart type. If all the series in a chart happens to include the same type, the TYPE attribute of the Chart object returns this type. However, you can use this feature to create a more complex combination chart, where you can draw some series into cylindrical or strips, and other series draws to linear. Not all chart types can be combined, in this version of Office, chart components only allow you to combine columns, fold lines, and area chart types. The most common combination chart showing business data is a combination of column charts and line charts.

Load data

You have already understood the names of various chart elements, as well as chart controls to display those chart types, now you need to learn how to load data into the chart. Like most OFFIC Web components, the chart control can load data from a variety of data sources, and the loading process can be done using the Chart Wizard in the design environment, or by writing code. Chart components can be bound to all other Office Web components - spreadsheet components, perspective table components, and data source components - all implemented Idatasource interfaces (this data source control in this Microsoft IE and VB has Standard interface, other controls of the Microsoft Developer Network Library and OLE DB SDK, the ADO's RecordSet object, even the array of text data, or a series of data composed of partition-separated series of data. . Common ways to load data into chart controls are: Where to tell the chart where to get data, and which part of the data source should be used for the series, categories, and values ​​required for the current chart type. In the programming model, the chart control will be called Dimensions for chart elements that can bind some of the data sources. When binding to an electronic form, "Part" of the data source you specify is a reference to a RANGE, such as A1: C1. If you bind to an OLE DB data source, you should specify which column name or column subscript in the result set. For perspective controls, you should specify which perspective axis that uses. (We will discuss this issue in Chapter 4), and for text data, there is only one "part" existence: array or string with a separator itself. The Chart Wizard provides you with a simple specified user interface to help you complete most of the binding work. However, the Chart Wizard is just a common programming model of the chart control, so if you can complete the functionality of any chart wizard by writing code, and you can complete the functionality that the Chart Wizard does not have. The use of the chart wizard is quite clear, and its online help also contains most of the usage. Because this book focuses on developing custom solutions using Office Web Components, I will not introduce how to use the Chart Wizard. Will go deep into the code you must write when loading data into the chart by programming.

Using the text data loading the subcompetence below, take the LoadFromLiteral.htm file under the CHAP03 folder in the book CD, which shows how to load text data into the chart control: '------------ -------------------------------------------------- ------------ 'loadchartwithliteral ()

'Purpose: Load text data into the chart

'IN: Cspace Chartspace object reference

The 'vSeries variable array or string divided by Tab, represents each series.

The 'vcategories variable array or string divided by Tab, represents various alias.

'Avairs variable two-dimensional array or string divided by Tab, represents each value;

One item in the peripheral array represents a series.

'

Sub LoadChartwithliteral (Cspace, Vseries, Vcategories, avairs)

'Local variable

DIM CHT 'We will create a Chart object created in the chart space.

DIM SER 'Temporary Series

'Get constant object so that we can use constant names in the script. Note: Just do this in VBScript,

'Does not need in VBA.

Set c = cspace.constants

'Clear the chart space.

Cspace.clear

'Create a chart in the chart space.

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

'Call the setData function to bind each Dimensions

'The second parameter is C.chdataLiteral, indicating that the last parameter is a variable array or one

'Separated by Tab.

CHT.SetData C.chdimseriesNames, C.chdataliteral, vSeries

CHT.SetData C.chdimcategories, C.chdataliteral, Vcategories

'When you use a text data to load a graph, you must load each series separately.

For Each Ser IN Cht.SeriesCollection

SER.SetData C.chdimvalues, C.chdataLitral, avairs (ser .index)

Next 'Server

End sub 'loadchartwithliteral ()

When using a text data loading chart, the data can be included in the variable array, or in a string separated by Tab, each element or tag represents a different value. In the files with the book CD, I used the Array function to pass text data in the form of an array. This function is supported in Microsoft's VBScript and VBA. SetData method is used to deliver text data, but note the second parameter (usually the subscript of the data source) is a constant chDataLiteral. This constant equal to -1 is telling the next parameter is text data, not part of a data source. Also note that you must use the WCSERIES object (representing a series of objects) to setData methods when passing text data to the chart. Because a chart control itself can only accept the value of the one-dimensional array, if you allow you to pass text data to the setData method of the WCChart object (representing an object of a chart), it will not be able to determine which series should belong to. The previous process is to solve this problem by simply traversing a collection of series, and delivers the value of the corresponding array to the current series. Bind to spreadsheet components

The following subsections come from the LoAffromSpreadsheet.htm file under the CHAP03 subdirectory in the CD, which demonstrates how to bind chart components to the area of ​​the spreadsheet component. '------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------

'Bindcharttospreadsheet ()

'

'Purpose: Bind a chart to the specified area in the source spreadsheet.

'Introducing parameters: cspace chartspace object reference

Quote for 'Sheet Spreadsheet objects

The reference to the 'srngseries string area, which defines the name of the series

The reference to the 'Srngcategories string area, which defines the name of the category

The reference to the 'srngvalues ​​string area, including each value

'

Sub Bindcharttospreadsheet (Cspace, Sheet, SrngSeries, Srngcategories, _

SRNGVALUES, FSERIESINCILS)

'Local variable

DIM CHT 'CHART objects created in the chart space

DIM SER 'Temporary Series

DIM RNGVALUES 'Stores the Range objects of each value

Set c = cspace.constants

Cspace.clear

'First tell the chart its data comes from the spreadsheet

Set cspace.datasource = Sheet

'Create a chart in the chart space.

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

'Call the setData method to bind each Dimensions

'The second parameter is 0, indicating that if there are multiple data sources, the first data source should be used.

CHT.SetData C.chdimseriesNames, 0, SrngSeries

CHT.SetData C.chdimcategories, 0, Srngcategories

'Electronic tables can only be bound to one-dimensional area,

'So traverse the collection and set a value for each series.

Set RNGVALUES = Sheet.Range (srngvalues) for Each Ser IN Cht.SeriesCollection

IF fseriesincols.

Ser.SetData C.chdimvalues, 0, _

RNGVALUES.COLUMNS (SER.INDEX 1) .address

Else

Ser.SetData C.chdimvalues, 0, _

RNGVALUES.ROWS (SER.INDEX 1) .address

END IF

Next 'Server

End sub 'bindcharttospreadsheet ()

Now some related information of this example is now described. First, in order to bind the chart and spreadsheet space, I set the DataSource property of the chart control to the instance of the spreadsheet control. After receiving a pointer to the instance of the spreadsheet control, the chart control requests the value of the cell in a region to the spreadsheet control. Second, use the setData method to first bind the series name dimension, then the category dimension. You must use this order to bind each dimension of the chart: first is the series name, then the category name, and finally the value. In some fewer examples, you only have a series of information, you can skip the setup series dimension, but only bind categories and values. This will make the control use the default name "Series" to create a series for you, you can change this name by setting the Name or CAPTION property of the WCSeries object. The last thing I want to talk about is that when it is bound to the spreadsheet component, the Chart component needs to receive an accurate area reference for each series. Unfortunately, you cannot pass a value of a two-dimensional area to the chart and let it automatically judge each of the series and categories. You must pass a one-dimensional area to the last parameter of the setData method for each WCSeries object. The previous example uses a common way to accomplish this task: use the RANGE object of the spreadsheet component to obtain one area of ​​each column or each column in the two-dimensional area. And passed it to the setData method for each series. Sign FSERIESINCOLS Description A specified series is a ranked or liner in the spreadsheet. If the flag is true, the collection of columns will be used; if it is a fake, a collection of rows will be used. It will also be noted that 1 is added to the series of subscript values ​​in the example. This is because the subscript of column and rows collection is based on the compatibility with the Excel programming model. The subscription of the series of chart components is based on 0. Add a series of subscripts to 1 to obtain the subscript of the columns or rows in the corresponding region.

Bind to data source components

The following method comes from the LoadFromDsc.htm file under the CHAP03 subdirectory in the book CD, demonstrates how to bind the chart component to a recordset returned from the data source component (DSC). (We will discuss DSC in detail in Chapter 5.) '--------------------------------- -------------------------------------

'Bindcharttodsc ()

'

'Purpose: Bind the chart to a recordset of the data source component. (This example creates a pie chart.)

'Enter parameters: cspace chartspace object reference

Quote of 'DSC Data Source Control

'Srsname Binding Data Source Control Name

'Scategories contains the name of the result of the category

'Svalues ​​contains the name of the result column

'

Sub BindchartTodsc (Cspace, DSC, Srsname, Scategories, Svalues) 'local variable

Dim Cht 'will create a Chart object created in the icon space

DIM SER 'Temporary Series

Set c = cspace.constants

Cspace.clear

'First tell the chart its data from the data source control.

Set cspace.datasource = DSC

'The recordset that will then tell it in the data source control.

CSPACE.DATAMEMBER = Srsname

'Create a pie chart in the chart space.

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

cht.type = c.chcharttypepie

'Now calling the setData function to bind the respective dimensions, the second parameter is 0, indicating that if there are multiple data sources, the first one should be used.

"In this example of this pie chart, we will add a series, and use this series of setData methods.

Set ser = cht.seriescollection.add ()

SER.SETDATA C.CHDIMCATEGORIES, 0, Scategories

SER.SETDATA C.CHDIMVALUES, 0, SVALUES

'Finally, add some data labels for this example because it is a pie chart.

Set dls = ser.datalabelscollection.add ()

DLS.HASPERCENTAGE = TRUE

DLS.haasvalue = false

End sub 'bindcharttodsc ()

DSC can extract data from the icon assembly and perspective components, or provide data for both. It also implements the same data source COM interface (iDataSource) implemented by the data source control of Visual Basic and IE, so this code can be used by any other valid data source control in these environments. The DataSource and DataMmbER attributes of the Chartspace object are the foundation of this example. Because they are part of the data binding standard established by Visual Basic and IE, you often see them in other data binding controls in these environments. The DataSource property is set to just want to provide the control (DSC in this example), and the DataMber property is set to a string of the required data set. Because a DSC can expose multiple data sets at the same time, the DataMber property is used to tell the chart control to request that data set. If you don't set the DataMmbER property. The icon control will request the default data set, which is the default data set, which is determined by the DSC. In this example, the way using the setData method is extremely similar to the way using the setData method in the BindChartTospreadsheet method, in addition to the "data part" in the function call (the last parameter of the setData function) now becomes a column of the recordset returned by the DSC. Column name. The data section can also be the column subscript (0, 1, 2, etc.). The chart control will pass the value of the data section to the Item method for the FIELDS collection object of the ADO, so any of this Item method believes that valid parameters can be used in the last parameter of the SetData method. In general, if you think that the column name will not change in the future, the order of the column will change in the future, then you should use the column name, and if you think that the column name will change, then the order will not change, then The subscript should be used. As mentioned earlier, an interesting feature of the pie chart is the item in the legend, not a series. Therefore, when binding a pie chart, you should want to display the columns in the legend to the category dimension instead of binding to the series dimension. This is also suitable for stacking pie charts and circular charts. In this example, the last code created some data tags (we just discussed) to show the percentage of each data point in the overall. The chart control can display a number of values ​​for each data point, and the default is the actual numeric value. Because I only want to display the percentage of each piece, I set the Haspercentage property to TRUE and set the Hasvalue property to false. Although this particular example creates a pie chart, you can use any supported chart type when binding to the DSC. I chose to create a pie chart in this example just how to make binding when using the pie chart. Bind to data set

The following function, the LoadFromRecordset.htm file from the CHAP03 subdirectory in the CD, demonstrates how to bind a chart control to an ADO recorder: '------------ -------------------------------------------------- ------------

'Bindcharttorecordset ()

'

'Purpose: Bind a chart to a recordset (create a scatter map in this example.)

'Introducing parameters: cspace chartspace object reference

'RST to be bound to Recordset objects

'Sfldseries series of field names

'Sfldxvalues ​​contains a field name of X value' sfldyvalues ​​contains a field name of Y value

'

Sub Bindcharttorecordset (Cspace, RST, SfldSeries, SfldxValues, _

sfldyvalues)

'Local Variables

Dim Cht 'Chart Object That We'll Create In The Chart Space

Dim Serd 'Temporary Series Pointer

Dim Ax 'Temporary Axis Pointer

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'First Tell The Chart That ITS Data IS Coming from The Recordset

Set cspace.datasource = RST

'Create a Scatter Chart in The Chart Space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

cht.type = C.chcharttypeScatterMarkers

'Now call setdata to bind the various dimensions

'Second Parameter Is Zero, Meaning The First Data Source Sould BE

'Used if There multiple data sources

'In this Example of a scatter chart, we will bind

'Two Value Dimensions: x and y

CHT.SetData C.chdimseriesNames, 0, SfldSeries

CHT.SetData C.chdimxValues, 0, SFLDXVALUES

CHT.SetData C.chdimyValues, 0, SfldyValues

'Finally, Let's Add Some Axis Labels Using

'the column names as the axis capen

Set ax = cht.axes (c.chaxispositionbottom)

Ax.hastitle = TRUE

Ax.title.caption = sfldxvalues

Ax.title.font.name = "tahoma"

Ax.title.font.size = 8

Ax.title.Font.Bold = true

Ax.numberformat = "#, ## 0"

Set ax = cht.axes (c.chaxispositionLeft)

Ax.hastitle = TRUE

Ax.title.caption = sfldyvalues

Ax.title.font.name = "tahoma" Ax.title.font.size = 8

Ax.title.Font.Bold = true

Ax.Numberformat = "$ #, ## 0"

'Let's also set the marker size a bit smaller Than Normal

For Each Ser IN Cht.SeriesCollection

SER.Marker.size = 5

Next 'Server

End sub 'bindcharttorecordset ()

There is no doubt that you will immediately notice that this example is except for the scattered map, it is similar to the example of the DSC, because in the Visual Basic and IE's record set object itself is a valid data. source. It also implements the same data source interface as DSC. This makes it possible to point the control DataSource property to record set objects as a DataSource property of setting up chart controls when using DSC. However, the recorder object is defined as only a data set, so it is not necessary to set the DataMmbER attribute when binding to the record set. Since the chart type used in this example is a scattered map, the code sets two numerical dimensions: X value and Y value. In the previous "Support Chart Type" section, the scatter map uses two values ​​for each data point, so we need to define the X numerical dimension to a column in the record set, and bind Y value Go to another column. (You can bind them to the same column, but this will generate a highly relevant scattered map!) An accident caused by a good architecture

When I gave this chapter to the chart component developers, a developer stated that the actual component did not "support" from the recordset, and the OWC team did not officially test this feature. But we have used this method almost all demonstrations and actual pages internally, so this function is quite stable. The reason why the recording assembly to be loaded into the chart assembly is a good surprise. When the Visual Basic and IE Development Group selects a standard data source interface (iDataSource), the ADO team thinks that it is meaningful to make the Recordset object to implement this interface, because it can easily return the bottom IROWSET interface from the GetDataMeMber method. . Because the chart control uses the iDataSource interface when loading data from the DSC, the Recordset object is well worked well. For chart controls, record set objects and other data source controls are exactly the same. When binding to the recordset object, you must determine that the recording set is using the Microsoft Windows Cursor Engine (WCE) or can be browsed and travel. WCE is an ADO component that provides browsing, sorting, filtering, and other functions on any OLE DB record set without having to consider the source or original function of the recordset. To use this engine, you need to set your ADO connection or record set to aduseclient if the environment you are using cannot identify this constant, can be used instead of it. In order to ensure that the chart control can be traveling in the recordset, you can use the AdoPenStatic cursor type, which is also 3. In the CURSORTYPE parameter of the record set, or the CURSOTTYPE attribute of the Recordset object is used in the CURSOTTYPE attribute of the RecordSet object, and WCE will be discussed in detail in Chapter 4. Please visit the full source code list in the LoadFromRecordSet.htm file in the book CD to see the example of the recordset attribute that sets this must be set. When browsing this file, the note example uses the column name as the title of the axis. The scattered map has two numeric axes (X-axis and y-axis), so you should set the title for these axes to explain what the value is displayed on these axes. Using the column name in the record set is a simple method; of course, if the column name in the recordset is difficult to understand, you can use your own title to set. Bind to perspective components

The last possible data source of the chart component is a perspective component. (Discuss this component in the next chapter.) Like you guess, this component also implements the same interface as the data source interface exposed to all valid data sources in the VB and IE, so this is followed Examples of the LoadFromPivot.htm file under the CD-CD, and the examples of the DSC we discussed earlier, but there are also some important differences: '------------- -------------------------------------------------- ---------

'Bindcharttopivot ()

'

'Purpose: Binds a chart to a pivottable company

'IN: cspace reference to the chartspace object

'PTable Reference to the Pivottable Object

'Fseriesincols boolean flag indicating WHether the Series

'Of the chart shouth com the column' Axis or the row axis of the pivottable control

'

Sub Bindcharttopivot (Cspace, PTABLE, FSERIESINCOLS)

'Local Variables

Dim Cht 'Chart Object That We'll Create In The Chart Space

Dim Ax 'Temporary Axis Reference

DIM FNT 'TEMPORARY FONT REFERENCE

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'First Tell The Chart That ITS Data IS Coming from The

'Pivottable Component

Set cspace.datasource = PTABLE

'Create a chart in the chart space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

cht.type = c.chcharttypebarclustered

'Now call setdata to bind the various dimensions

'Second Parameter Is Zero, Meaning The First Data Source Sould BE

'Used if There multiple data sources

IF fseriesincols.

CHT.SetData C.chdimseriesNames, 0, C.chpivotcolumns

CHT.SetData C.chdimcategories, 0, C.chpivotrows

Else

CHT.SetData C.chdimseriesNames, 0, C.chpivotrows

CHT.SetData C.chdimcategories, 0, C.chpivotcolumns

END IF 'FSERIESINCOLS

'Set the values ​​dimension. The value

'You Pass for the Data Reference (The Last Parameter)

'is the index of the total you want to use.

'Since There IS Only One Total in this Example,

'We Pass Zero, Indicating The First One.

CHT.SetData C.chdimvalues, 0, 0

'Finally, Let's Add An Axis Title To The Value

'Axis, Using The Label On The Pivot Total' As The Caption, And Set The Number Format

Set ax = cht.axes (c.chaxispositionbottom)

Ax.hastitle = TRUE

Ax.title.caption = ptable.activeview.dataaxis.totals (0) .caption

Set fnt = ax.title.font

FNT.NAME = "Tahoma"

FNT.SIZE = 8

FNT.BOLD = TRUE

Ax.numberformat = ptable.activeview.dataaxis.totals (0) .Numberformat

End sub 'bindcharttopivot ()

Like the previous recording set DSC example, in order to bind the chart control to the perspective control, first you put the DataSource property of the chart control to point to the perspective table control. As with the record set, the perspective table control only exposes a dataset, so you don't have to change the default settings of the DataMember property. The key difference between this example and the DSC is the specific constant of the last parameter for the SetData method. You should remember that this last parameter defines which part of the data you need to bind to the specified chart dimension. In the perspective control, a valid logical part is a perspective axis of the rows and columns, as well as all sums in the trial. In the perspective control, the row axle is displayed in the lower left of the table, and the column axis is displayed in all tags at the top of the table (the next chapter will more describe these axes). All the information that you must know is: Which axis you need to bind to the series dimension, which axis is bound to the category dimension. There are some ways to bind the chart controls in this example. Because a perspective table reports can display many total values ​​at the same time, the chart control must know which sum you need to use to specify value dimension. This is indicated by passing a summary subscript to the last parameters of the setData method. In the BindCharttopivot example, we use a cluster column chart, so there is only one value for each data point. We tell the chart control using the sum of the subscript 0 (ie, the first because it starts from 0) as the value of the data point. Note that this is the subscript in the current view of the perspective control - instead of all possible sums of data in the data source. However, the perspective control has indeed implemented a standard COM interface required for a data source control. It just doesn't know how to return ADO record sets and OLE DB collections. The chart control contains a special code to implement the cross data displayed in the perspective control, and properly ignore the total number of sub-total and external, if used, will distort the scale of the chart, not all data Bind controls can use perspective table controls as their data sources.

Chart and shaft title

The graphic is an efficient mechanism because it is easy to understand, the visual manner shows a large amount of information. However, the data drawn in the chart is hard to describe itself; so you often need to add a descriptive title for your chart and the shaft displayed in the chart. Use multiple sums for multiple values

Bulk maps, bubbles, polar coordinates, and OHLC chart types have one of the same places: they need to use more than one value to determine one of the data points in the chart. The scattered map requires the x value and y value, the bubble map also needs these two values, and there is a bubble size value, the polar coordinate map requires the Theta and R value, and the OHLC map is like its name indicated, it takes 4 Numerical value. Because the perspective report can display multiple sums at a time, it is often desirable to map these summates to different chart values ​​to form a single data point. You can accomplish this task by specifying the subscript in the PivotTA view in the last parameter of the SetData method. For example, in order to put the first sum and bind to X, the second sum is bound to Y, you should write this code: cht.setdata c.chdimxValues, 0, 0 'First Totalcht. SetData C.chdimyValues, 0, 1 'Second Total

Sometimes you need to use these multiple sums in a chart type of a value in a data point, such as a column graph. In this case, you may want to display the summates as a nested category or a nested tag. You can use a special constant to complete this task: cht.setdata C.chdimcategories, 0, C.chpivotrowaggregates

This setting will use any of the summates displayed on the row as a nested category name of the classified category axis. In order to get the results you need, you should also set the Totalsorientation property of the PivotView object to the pltotalorientationRow constant so that the total title is displayed on each line. You may need to display multiple sums as different series in the chart. To complete this task, keep the shaft on the PivotTable report to be empty, add the sum of you need to display as different series, then write the following code: cht.setdata c.chdimseriesNames, 0, C.chpivotcolaggRegates

This code will create a series in the PivotTable report in the chart. Please refer to the PivottotalsAnsasseries.htm example file under the CHAP03 folder in the book CD and view its concrete practices.

If you add multiple charts to the chart control (in the "Multiple Charts in Chart Space), you can set their own title for each chart. In fact, you can set a global title for the chart control itself, and he will display above all individual charts. All basic font properties (font names, size, whether or not the black body, whether it is slope, whether it has underscore, color) to format the chart title. You can also set their background colors or let them transparent. The same is true for axis titles. By default, the newly created chart does not have chart title and axial title. You can use the property toolbox to add a chart title and axial title in the design phase, or you can use the code in the run phase. The following section of the addtitles.htm file from the CD03 folder of the book CD, demonstrates how to add a chart title: '---------------------- --------------------------------------------------

'Setcharttitle ()

'

'Purpose: Sets The Chart's Title

'In: Cht Reference to a chart

'Stitle New Title Caption'

Sub SetChartTitle (CHT, Stitle)

DIM FNT 'TEMPORARY FONT REFERENCE

'If the title is nonblank

If Len (Stitle)> 0 THEN

'Add a title if neseary

cht.haastitle = true

'Set the caption and its font formatting

cht.title.caption = stitle

Set fnt = cht.title.font

FNT.NAME = "Tahoma"

FNT.SIZE = 10

FNT.BOLD = TRUE

Else

'Title Is Blank. Remove IT.

cht.haastitle = false

END IF

End sub 'setcharttitle ()

You can add a shaft title using the same method as the added chart title, except for a difference: the first parameter of the method accepts a reference to an AXIS object, not a reference to a chart object. Also note that you can set both the COLOR properties of the header or background to a RGB color value, or it can set it to an IE color name - for example, "firebrick" or "papayawhip". This also applies to any places in the chart control, such as the background color of the chart, the color of the drawing area, the colors of the series.

Axial label

By default, the chart control sets tags on your shaft to display where the data point is on the scale (value axis), or the data point belongs to that category (category). You may need to use the code during the running phase, or use the Properties Toolbox to use the Properties Toolbox in the design phase to adjust some of these labels. For the value axis, the label shows the digital points of all values ​​on the shaft. These numbers were not formatted unless the data source included a clear digital formatted information. In order to change the default digital format, set the axial NumberFormat property to a new digital format name or format string. A list of format names you can use is on the help file of the spreadsheet control (with the help buttons on the spreadsheet to open the digital formatting "topic in the spreadsheet. You can also create a custom format string like in Excel, symbols you can use in custom digital formats can be found in Excel2000's help files, related summary topic titles is "Creating a custom digital format "For the value axis and category axes, you can choose to discard some tags - for example, only the fifth is displayed in every five tags. This is useful for those shafts containing too many labels, which can make the labels on the shaft not overlap, and it is also useful for those that can be derived from the reserved tags. For example, a series of dates. The category axis deficiency is not canceled. But suppose you contain a large group of time on the category axis. You can choose to cancel a part of the label by setting the TickLabelsPacing property of the WCAXIS object, that is, you can use the design phase to select the label and use the property toolbox to complete, or by the code in the run phase. The setting of this attribute determines how many labels to skip between the labels displayed. Note that this property only affects the label, which means that the axis will still display tag symbols in the label should display. However, you can also reduce some tag symbols by adjusting the TickmarksPacing property to the same value as the TickLabelsPacing property.

legend

By default, the newly created chart does not contain a legend. If you plan to display multiple series of data points, you may need to add a legend to your chart to explain which color corresponds to which color corresponds to. You can also add a legend by selecting a graph in the design phase, using the Properties Toolbox to add a legend, you can also add the legend to TRUE through the code through the code through the code. Initially, the legend defaults to each series, but you can change it. In order to hide the items of a legend, use the WclegendEndEntries collection of the WCLEGEND object to get the map item you need to hide, and then set the Visible property of the obtained object to false. In the design phase, you can simply select the legend item and remove it by pressing the Delete key. If you contain multiple charts in the chart control, you can create a legend for each individual chart, or you can also create an idea for the entire control. For example, if you are displaying multiple pie charts, you may display only one legend for all pie charts because the color / category mapping is the same for each chart. If a set of series is different between the charts, then these chart types of the series in the legend can benefit from separate ideas. For multiple charts of the series in the legend (except for the pie chart, stacked pie chart and chart outside the chart), there is a quite annoying problem for them to use the same legend: chart controls, in the initialization map, A series of each appearing in each chart will be added in the legend. If you display two series in five charts, the chart space map will contain 10 map items, the same two repeated five times. The method of deleting additional map items is the same as mentioned above, you can select and delete them in the design phase, or use the Visible property of the WCLEGEndentry object in your code.

Appendix: English

Chapter 3

THE Chart Component

Now that you have an understanding of the Spreadsheet component, let's examine the functionality and programming model of the Chart component. As in the previous chapter, after describing a given feature, I will present a few interesting uses for it. In Part II of the Book, You Will See Many of these Ideas Actually Implement.

This chapter will also show you some clever ways to add functionality to the Chart component using your own code. The Chart component might seem a bit less complex than the Spreadsheet or PivotTable components at first, but it has some powerful features that you can use in Your Solutions. Plus, IT Offers Many "Knobs" That You Can Adjust To Customize a chart to your liking.

[Previous] [Next]

The Basics of the Chart Component

The Chart component is a COM control that was built by the same team that developed charting in Microsoft Excel 2000. It provides basic business charting both as an onscreen COM control and as an in-memory, GIF-generating engine. In this first version, the Chart control supports all the two-dimensional chart types found in Excel (except for the Contour type) with the addition of the Polar, Stacked Pie, and Filled Scatter chart types. This version does not contain any three-dimensional chart types or effects .One new feature that I will discuss in this chapter is the Chart control's ability to display more than one chart within the overall chart space of the component. The Chart control is actually composed of an entire chart space containing one or more charts that all share . the same set of categories (. I will explain the term "categories" in more detail later in this section) Normally, you will have only one chart in the control at a time; however, having multiple charts in the same c .

Like The Spreadsheet Component, The Chart Component Has A Number of Basic Features and Some Distinct Terminology That You Should Become Familiar with Before We move on to more advanced topics.

The Nomenclature of Charting

During the development of a new feature in Excel 2000 charting, the OWC team conducted a number of usability tests to determine whether our design was easy to use. For those who have never heard of such tests, we take real customers from companies and homes throughout THE

Seattle

area and put them in front of a prototype for a new feature. We ask the people to perform a number of tasks and watch to see how they approach them and whether the design was effective in helping them accomplish the assignment. Often, we find that our expectations were far from reality-meaning we have to go back and redesign the feature.In one particular test, we showed people various charts we created in Excel with certain parts circled. We asked them to tell us what they thought the name of the circled part should be. Logically, you would expect us to find some commonality and discover the "name" that most people already associate with a particular element. We could then use that name in our documentation, programming models, onscreen user interface, and so on. much to our dismay, we discovered absolutely no standard names for elements within a chart. You might expect that people would know which is the X axis and which is the Y axis, but many people do not remember much from their ma TH Classes and commonly Mix Them Up.

Note

For those whose minds are now racing to remember which is which, the X axis is horizontal and the Y axis is vertical. Of course, most charts have what's called a category axis and a value axis, and their orientation depends on the particular chart type . Scatter and Bubble charts have X and Y axes since they compare two (or three) values ​​against each other. In chart types such as Radar or Polar, the axes actually extend from the center of the chart, so X and Y are meaningless.

Since no common language seems to exist for describing elements of a chart, it is quite hard to talk about creating and manipulating charts. To gain any understanding of the Chart component's features and programming model, we must first define a number of key terms used in the component and look at what elements they represent. Many of the terms have specific connotations in different chart types, so if you see a chart type in the following discussion that you are not familiar with, refer to the "Supported Chart types" for a Screen Shot and A Description.series

A series is one of the most important constructs of the Chart component. In fact, most of the internal structures in this component are oriented around the series. Figure 31 points out the series in a Column chart. Notice that each series correlates to an entry In the chart's legend.

Figure 3-1. A Column Chart Containing Two Series.

A series represents a sequence of data points that you want to display in a certain manner. People commonly think that a chart has a particular type (such as a Line chart, Bar chart, or Pie chart). But in the Chart control, it's the series that has a particular type-which means you can create a combination chart by setting one series as a Line type and another as a Column type. All the data points in a series commonly have the same color (though you can override this, AS We will see later. Plus, Elements Such as Trendline and Error Bars Are Attached to Particular Series.

By Default, An entry in the legend exists for each series, but you can you want. (I will expend. "

Categories

Categories Are A Little Harden. Figure 3-2 Points Out The Category Labels Contained I Column Chart.figure 3-2. Categories in a column chart.

All charts have a notion of categories, but not all charts have a category axis. In Figure 3-2, the sales representatives' names are the categories, and each series contains a single data point in each category. In most charts, the intersection of a category and a series creates a data point. Note, however, that a particular series might not have a data point for a given category although the other series do. When this is the case, the Chart control merges all categories from all series And Simply Does Not Plot A Data Point At That Series-Category Interse.

Category Axes Differ from Value Axes in Three Important Ways:

There is no inherent ordering of categories.

There is no minimum and no maximum category.

Data Points Are Neatly Assigned to a Specific Category.

If Salesperson is your category axis, specific sale amounts are naturally attributed to specific salespeople, and no data points sit between salespeople. A value axis has a defined minimum and maximum, and the space along the axis is evenly divided into units that increase as you .

A Scatter or Bubble chart does not have a category axis because its data points are defined by X and Y coordinates as well as a bubble size for Bubble charts. Although these chart types do not have category axes, the data points can still belong to specific categories and you can retrieve the category name for a given data point. This mechanism is useful for encoding extra information into the data points of a Scatter or Bubble chart, allowing you to display that information when the user's mouse hovers over a data point.NOTE

Of course, in the real world, sales often can be attributed to more than one sales representative. However, most sales information systems perform an allocation and store each representative's contribution to the sale as a specific value that is then plotted on the chart. The point about data fitting neatly into a category is made to contrast discrete categories from continuous values. For example, a value of 1.4567454 can be plotted along a value axis between 0 and 2, but it does not fit into a discrete "bucket" on the Axis The Way Data in Categories Do.

Values, Values, VALUES

In most of the simpler chart types, you have only one set of values ​​to worry about. Figure 3-3 shows the sales values ​​plotted by year by salesperson. This chart contains only one value per data point-which holds true for most of the Simple chart Types.

Figure 3-3. VALUES in a column chart.

Scatter and Bubble charts, on the other hand, introduce the necessity for having two or three values ​​for every data point. In a Scatter chart, each data point has an X value and a Y value, the combination of which defines an (X, . Y) point in two-dimensional, Cartesian space A Bubble chart adds a third value:. a bubble size value that determines the radius of the bubble centered at the (X, Y) point Optionally, the bubble size value can be set to represent the area of ​​the bubble instead of the radius.Things get a little more complicated when using a High-Low-Close (HLC) chart because again three values ​​make up each data point, except that they are now called the high value, low value, and close value. An Open-High-Low-Close (OHLC) chart has four values ​​associated with each data point, and the extra value is called, not surprisingly, the open value. (These types of charts are often called Stock Charts Because The is isy dist of it is.)

When dealing with a Polar chart, you need to provide another set of values:. R values ​​and Theta values ​​The R value defines the distance of the data point from the center of the chart, and the Theta value represents the angle away from a horizontal Line Passing Through Origin.

Axes

The term "axes" is probably more familiar to you. In the Chart component, axes have essentially the same meaning that they do in the world of geometry. However, the Chart control adds another layer of meaning to an axis by referring to it either As a category axis or a value axis. in Figure 3-4, The category and value axes are labeled.

Figure 3-4. Category and value axes in a column chart.

A category axis is subdivided into equal segments-one for each distinct category, and data points are plotted in the middle of each category. No notion of a minimum or maximum exists for a category axis. A value axis, on the other hand, is a continuous axis that has a minimum and a maximum. Along a value axis, data points are plotted where they would fall between the minimum and maximum points.Since the placement of the category and value axes depends on the chart type, "category" and "value" are logical names that do not directly map to X and Y. For example, a Column chart has the category axis extending horizontally along the bottom (X) and the value axis rising vertically on the left (Y). But in a Bar Chart, The Placements Are Reverse, with the category Axis on The Left and the value axis along the bottom. For more on the various chart type, see "supported types."

Scaling

Although you have certainly heard the term "axis," you might not have heard the term "scaling" before. Every axis has a scaling, though you commonly use a scaling with a value axis. A scaling defines a measurement scale for its axis, determining the minimum and maximum values ​​for the axis. The scaling also determines whether the intervals along the axis are linear or logarithmic. A linear scale subdivides the axis into even segments that increase linearly from the minimum value to the maximum value (for instance, 20 , 40, 60, 80, 100). A Logarithmic Scale Also Divides The Axis Into Even Segments; However, The Increment from One Segment To The Next, 1, 10, 100).

WE WILL DISCUSS AXIS Scaling in More Detail Later In The Chapter WHEN We Talk About Split Axes, As Well As In Chapter 6, Where We Will See How To "Zoom in" to show a portion of your data in more detail.trendlines

The Chart component supports the creation of one trendline for each series in your chart. As in Excel, a trendline is used to show the trend of data in a series. Trendlines are commonly used in trend analysis and forecasting when you want to predict what a certain value will be in the future if it keeps increasing or decreasing at the historical rate. Like Excel, the Chart control offers a few different trendline calculations, including linear, logarithmic, polynomial, exponential, and power. However, the Chart control does not Offer The Moving Average Trendline Type Found in Excel. Figure 3-5 shows an esample of a trendline.

Error Bars

Error bars, shown in Figure 3-6, are short line segments extending from the data points that indicate some uncertainty about your data, known as the error amount. Each data point can display an error bar, which indicates that the data point's true value Can Be Anywhere within the error Range.

Why a Separate Scaling Object?

You might be wondering why the concept of scaling is not just part of an axis. After all, it seems that the scaling determines the minimum and maximum values ​​of an axis. However, the scaling's minimum and maximum values ​​determine the dimensions of the viewable region called the plot area. An axis displays tick marks and labels, but it is the scaling that determines the exact pixel / value ratio for that dimension of the plot area. By separating the scaling from the axis, the Chart control can support charts that have NO Visible axes.

Figures 3-5. A Trendline in a scatter chart.figure 3-6. Error Bars in a column chart.

Like trendlines, error bars are attached to a series. An error bar is displayed for each data point in the series, and the collection of error bars for that series can be set to show a positive error amount, a negative error amount, or both The Error Amount Can Be Expressed As a Percentage (Such as 10%, -10%, OR /- 10%), A Relative Value (Such as 2, -2, OR /- 2), or A Custom Amount (for Example, An Upper Bound of 12 And A Lower Bound of 8 for a Data Point of 10). Error Bars Can Also Be Data-Bound, In Which Case The Chart Control Treats The VALUES IN The Result Column As Custom Error values ​​for each data point. Although Excel charting also provides Standard error and Standard Deviation options for the error amounts, the Chart control does not yet natively support these. Of course, you could calculate these values ​​yourself and use custom error amounts to display them in .

Data labels

A data label is a small piece of text placed next to a data point that you can set to display the data point's value, percentage in the series, category name, series name, or bubble size. (See Figure 3-7 for an example .) you can display any combinations of these pieces of information in a data label. Plus, you can control the font, color, and border formatting attributes-even which separator character string to use between each piece of information.

Figure 3-7. Data Labels in a column chart.

Data labels are obviously useful when you want to show numbers next to your data points, especially for comparing data points that might be very close to each other. The percentage contribution is of course useful any time you want to show the percent a data point contributes to the overall series, such as in a Pie chart. Showing the category name is a nice way to display extra categorical information in chart types that do not have category axes, such as Scatter and Bubble charts.Like trendlines and error bars, data labels Are Attached to a Series. You Cannot Format, Hide, or Show A Data Label for An Individual Data Point. All Manipulation to Data Labels Affect All Data Points in The Series.

Supported Chart Types

The first question I usually hear from a developer's mouth when I speak about the Chart component is, "What chart types are supported?" Chart types are the bread and butter of charting, so the more types the merrier. I have a reference book on my shelf that contains almost 450 pages of different chart types, chart elements, and information graphics techniques (This book, Information Graphics:! A Comprehensive Illustrated Reference [Management Graphics, 1997], is an excellent resource for anyone involved in information graphics, as Are Any Ofward Tufte's Books.)

The first version of the Chart component includes the full set of two-dimensional chart types found in Excel 2000 (except for the Contour type), with the addition of Polar, Stacked Pie, and Filled Scatter chart types. The Chart control does not have .

Let's Look at severage examples of the supported chart type and discuss what kind of data the isy useful for displaying.column and bar charts

The Most Typical Chart Types Used in Business, Column and Bar Charts, Show A Filled Bar For Each Data Point, Extending from The Zero Point on The Value Axis To The Data Point.

Most people do not make much of a distinction between Column and Bar charts-after all, they are essentially the same, they just extend in different directions. The Chart component uses the term "Column" to refer to a vertical column that extends up And Down The Screen and The Term "Bar" for a Horizontal Bar That Extends Across The Screen. Figure 3-8 Shows An Example of a Column Chart and a bar chart.

Fighe 3-8. A Column Chart (TOP) and a bar chart.

That Do Not NEED To APEAR In Any Particular Order. Unlike Line Charts, Column and Bar Charts Don't Portray a Sense of Order or Progression.

As with many of the chart types, there are a few Column and Bar chart subtypes. The default subtype, called Clustered Column or Bar, plots bars from different series adjacent to each other within each category. (Figure 3-8 shows a Clustered Column chart and a Clustered Bar chart.) The Clustered subtype is the most useful subtype when the different series are fairly unrelated or when they should not be aggregated visually. For example, if you plot a budget in one series and the actual amount spent in the Other, you do not want to aggregate those values. instead, you................

Stacked Column and Bar charts display the different series as stacked upon one another. In such charts, the length of the column or the bar represents the sum of the data points for the category. Figure 3-9 shows an example of a Stacked Column chart .Figure 3-9. A stacked column chart.

Stacked Column and Bar charts are useful for displaying data in which the series' values ​​can and should be aggregated to depict a visual total for each category. For example, if you plot sales information by country and by product, you might want to use a Stacked Column chart to show the total sales for each country still segmented by the exact value each product contributes-meaning top-selling products will have longer segments, while products that do not sell well will (the category) across all products. The bar is Have Shorter segments. stacked Charts Are Useful When It Is Not As Necessary To Assess The Relative Contribution As It Is To Assess The Total for Each Category.

Finally, the 100% Stacked subtype is a bit like a Pie chart: it draws a bar or column all the way across the plot area and then subdivides the bar or column into segments representing the percent contribution of each series' data point The key. difference between this subtype and the Stacked subtype is that the length of each segment is the percentage of the data point's contribution to the total of the data points in that category, not the literal value. Since all the bars are the same length (100% ), such a chart is not useful for comparing one category's total to another. However, this type of chart is useful for viewing the same type of information a pie chart shows, but for many categories and series at once.

Most of the other chart types described here have the same set of subtypes-Clustered, Stacked, and 100% Stacked. I will not redefine each of these three subtypes in the descriptions that follow, but I will indicate when they are available. Refer back THIS Section for A Description of the Subtypes and Which Types of Data Are Appropriate to Display Using Them.pie, Stacked Pie, And Doughnut Charts

Pie charts are also common in business charting, which is almost a shame since they provide the least dense (and the least efficient) display of information available. However, their simplicity also makes them very understandable, and often, very persuasive. For example, When Showing a Breakdown of Market Share Information, The Effect of An Extremely Large or Small Slice INDEED POWERFUL. Figure 3-10 shows a type.

Figures 3-10. A Pie Chart.

The important quirk of Pie charts is that the legend shows the category values ​​instead of the series values. Most charts show the various series in the legend, but since a Pie chart shows only one series, the legend is used to show the category labels that Correspond to The Colored Pie "SLICES."

A Pie chart is obviously useful for showing the percentage contribution or breakdown of a total. A Pie chart shows only one dimension of data because, as stated a moment ago, it can display only one series of data points.

The Stacked Pie and Doughnut chart types, however, can show multiple series at once, much like the 100% Stacked Column chart can display data for many series and categories at once. The only real difference between the Stacked Pie chart and the Doughnut chart is that the Doughnut chart has a hole in the middle (the "doughnut hole" if you will). Figure 3-11 depicts the same information in first a Stacked Pie chart and then a Doughnut chart.Figure 3-11. A Stacked Pie chart And a doughnut chart.

I admit that these are somewhat bizarre chart types; in fact, I recommend using them only in those unique circumstances under which no other chart type will suffice (for example, displaying the percentage chemical makeup of soil in concentric rings around a bomb explosion site) .................

Line, Smooth Line, And Area Charts

.

Line and Area charts are useful for displaying data in which the categories actually have a meaningful order, such as a series of dates or times. For example, plotting sales over a series of dates or plotting stock prices over a series of hours is more effectively Displayed in a line Chart Than the Because It Is Easier To Tell WHENER THENER'S A TREND UP INETHERED IN A CHART.

The only real difference between a Line chart and an Area chart is that in the Area chart, the section between the category axis and the line is filled with the series color. The occlusion that occurs when one series' values ​​are higher than another's can make Area charts somewhat difficult to work with-unless you are using the Stacked subtype we discussed earlier. Since the series are drawn over each other in order, the last series drawn will cover any series previously drawn. Use nonstacked Area charts only when you know that A Series Has Consistently Higher Values ​​Than All The Series That Follow It.figure 3-12. A line Chart and an area chart.

As in the Column and Bar chart cases, Line charts and Area charts have the Clustered, Stacked, and 100% Stacked subtypes. However, the term "Clustered" is not commonly used to describe the default subtypes, and these defaults are simply called Line Chart and area chart without..

Line charts have one other subtype that Column and Bar charts do not. Lines in a chart can be drawn either "straight" or "smoothed." It should come as no surprise that charts drawn with smoothed lines are called Smooth Line charts. Instead of Drawing the line straight from One Data Point To Another, The Chart Component Draws The Line on a Curve So That There Are No Jagged Peaks Or Valleys.

Scatter and Bubble Charts

Scatter charts are used less often in business presentations, which is unfortunate considering that they can be a more powerful analysis tool than the simpler chart types described earlier. Although a Scatter chart has series and categories, it also has two values ​​(rather than one) that determine the location of a data point. Each data point in a Scatter chart has an X value and a Y value, and the combination of the two determines its placement on the plot area.The key difference between a Scatter chart and a Bubble chart is that the data points in a Bubble chart are circles that have dynamic size. A data point in a Bubble chart contains a third value called bubble size, which determines either the radius or the area of ​​the bubble. Figure 3-13 shows typical Scatter And bubble charts.

Figure 3-13. A Scatter Chart and a bubble chart.

Scatter charts and Bubble charts are useful for comparing two different values ​​to discover a correlation or distribution pattern. For example, using a Scatter chart to plot a department's morale budget allocation against its revenue might reveal a strong correlation, showing that a high morale budget commonly Increases Revenue. (at Least, Most Employees Would Like to Think this is true!)

Scatter charts have a few unique subtypes. The default subtype is simply called Scatter Markers and uses markers (small geometric shapes such as diamonds or squares) to indicate the data points. Different shapes are used to indicate the different series. You can choose to connect the markers of each series with a smoothed or straight line. Furthermore, you can choose to have lines without any markers at all. The Chart component includes a final subtype that is not included in Excel. It allows you to fill in the polygon made from The Data Points and Connecting Lines, Creating A Filled Scatter Chart.Fun with Filled Scatter Charts

You can try a rather creative Filled Scatter chart demo on the companion CD. Open the DrawWithChart.htm file in the Chap03 folder, and click the chart surface to create points of a filled polygon. Double-click the mouse to end the shape. This Demo Was Written by Jeff Couckuyt, One of The Extreme Talented Chart Component Developers, and Was Created Using Only The Chart Control and A Filled Scatter Chart Type.

Keep in mind that Bubble charts have the same problem of occlusion as Area charts A large bubble will hide any data points underneath it, so only use Bubble charts when you know the chance of occlusion is low;. Otherwise, consider setting the bubble fill to TRANSPARENT.

Radar charts

Radar Charts Do Not Seem to Be Typically Used In The

United State

, But I understand that they are much more common in Asian countries for portraying data such as nutritional information about food products. Figure 3-14 shows what this interesting and useful chart type looks like.

Figures 3-14. A Radar Chart.

A Radar chart has categories, series, and values ​​like the other simple chart types; however, Radar charts plot the category labels in a circle surrounding the chart and contain spokes extending from the center of the chart out to each category label Each spoke is. a value axis. The data points for each category are plotted on the corresponding spoke's scale at the appropriate point and in the appropriate series color. The chart then joins the data points of each series with a line and optionally fills the series color from the line toward the origin. Filled Radar charts have the same old problem of occlusion that Area and Bubble charts have, so beware of using the Filled subtype unless you know that your data will not cause occlusion (or unless you are not concerned about it) .Radar Charts Also Support The Smooth Line Subtype We Discussed Earlier. Plus, You Have The Option of Plotting Data Point Markers in Both The Smooth Line and Straight Line Subtypes.

High-low-close and open-high-low-close charts

Anyone displaying information about stocks or financial securities will be interested in these two chart types. The High-Low-Close chart type (or HLC chart) displays a line segment for each category. Each line segment extends from the low to the high value and FEATURES A Small Tick Mark That Denotes The Close Value. Figure 3-15 shows an esample of an hlc chart.

Figures 3-15. A high-low-close chart.

You should consider using this chart type any time you have data containing a range of values ​​for a given period and a special value that needs to be marked within the range. For example, you could use an HLC chart to display temperature readings over an extended Period of time.

An Open-High-Low-Close chart (or OHLC chart) adds one extra piece of information to the data of an HLC chart:. The open value The chart indicates the open value by displaying a filled rectangle between the open value and the close value, as Figure 3-16 shows.The filled rectangle either will be the series color or it will be black, depending on whether the difference between the close value and the open value is positive or negative. positive differences get the normal series color, while negative differences are shown as black. This shows the viewer whether the values ​​increased or decreased during the specified period so that he or she can ascertain whether the value improved or worsened and by how much.

Figures 3-16. An open-high-low-close chart.

Both the HLC and the OHLC chart types still maintain the notion of series. However, in an HLC chart type, the Chart component places different series in the same horizontal position. In other words, the control will draw multiple series over one another. Generally ................ ..

Polar Charts

The Polar chart type is the one new chart type that appears in the Chart component but not in Excel charting. Polar charts, which Microsoft Office users have been requesting for some time, are useful for displaying relationships between angles and distances. Polar charts are commonly Used in The Audio and Radio Fields, for Example, To Show The Power and Direction of A Microphone's Pickup. Figure 3-17 Depicts a typepical poilar chart.

Figures 3-17. A Polar Chart.

The Polar Chart Includes The Smooth Line Subtype, and You Can Choose WHether To Display Data Point Markers with the lines.combination charts

As mentioned at the beginning of the chapter, one of the great secrets of charting is that a chart does not really have a chart type. Instead, each individual series has a type, and if all series in a chart happen to have the same type The Chart Object's Type Property Returns That Type. However, you can use this distinction to create more complex Combination Charts, in which you Plot Some Series as columns or baking.

Not all chart types can be combined, and in this version of Office the Chart component allows you to combine only the Column, Line, and Area chart types. The most common combination chart used for business data is a mixture of the Column and Line chart Types.

Loading Data

Now that you know what the various chart elements are called and what chart types the Chart control can display, you need to learn how to load a chart with data. Like most of the Office Web Components, the Chart control can load data from a variety of sources, and the loading can be performed by using the Chart Wizard in a design environment or by writing code. The Chart component binds to all the other Office Web Components-the Spreadsheet, PivotTable, and Data Source components-as well as to all other controls that implement the IDataSource interface (the standard interface for a data source control in Microsoft Internet Explorer or Microsoft Visual Basic, documented in the Microsoft Developer Network Libraries and the OLE DB SDK), ADO Recordset objects, and even literal arrays or delimited strings Of data.

The general approach to loading data into the Chart control is to tell the chart where it should retrieve data from and what "parts" of the data source should be used for the series, categories, and values ​​the current chart type requires. In the programming model, the Chart control refers to these chart elements as dimensions that you can bind to some part of the data source When binding to a spreadsheet, the "part" of the data source you specify is a range reference, such as A1:. C1 . For an OLE DB data source, you specify what column name or ordinal index of the resultset to use. For the PivotTable control, you specify which pivot axis to use. (We will discuss this further in Chapter 4.) in literal data, only one "part" exists:. the array or delimited string itself.The Chart Wizard performs much of the binding for you, presenting you with a simple user interface for specifying this information However, the Chart Wizard merely calls the public programming model of the Chart Control, SO by writing your own code you can do anything the Chart Wizard does-and more. The Chart Wizard is fairly self-explanatory, and its online help covers much of its use. Since this book focuses on developing custom solutions with the Office Web Components, I WILL NOT DETAIL Using The Chart Wizard Here. Instead, I'll Dive Into The Code You Need To Write When Programmatically Filling The Chart with data.

Loading the Chart with Literal Data

The Following Subroutine, Taken from The LoadFromlitral.htm File In The Chap03 Folder On your Companion CD, Shows How To Load The Chart Control with Litral Data:

'------------------------------------- -----------------------

'Loadchartwithliteral ()

'Purpose: Loads The Chart with Literal Data' in: Cspace Reference to the Chartspace Object

'VSeries Variant Array OR

'Tab-Delimited String of Series Names

'Vcategories Variant Array OR

'Tab-Delimited String of Category Names

'Avvalues ​​Array of Variant Array OR

'Tab-Delimited String of Values

'One entry in the outer array per series

'

Sub LoadChartwithliteral (Cspace, Vseries, Vcategories, avairs)

'Local Variables

Dim Cht 'Chart Object We'll Create In The Chart Space

DIM Ser 'Temporary Series

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'Create a chart in the chart space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

'Now call setdata to bind the various dimensions

'Second Parameter Is C.chdataliteral, Meaning The Last Parameter

'Is a variant array or a tab-delimited string

CHT.SetData C.chdimseriesNames, C.chdataliteral, vSeries

CHT.SetData C.chdimcategories, C.chdataliteral, Vcategories

'When Loading the chart with literal data, you must

'load Each Series with Values ​​Individally

For Each Ser IN Cht.SeriesCollection

SER.SetData C.chdimvalues, C.chdataLitral, avairs (ser .index)

Next 'Server

End sub 'loadchartwithliteral ()

When loading the chart with literal data, the data can be contained either in an array of variants or in a tab-delimited string, each element or token representing a different value. In the file on your companion CD, I pass the literal data as an array using the Array function that is supported in Microsoft VBScript as well as in Microsoft VBA.The SetData method is used to pass the literal data, but note that the second argument (normally the data source index) is the constant chDataLiteral. This constant Which is equal to -1, tells the chart tria next argument is literal data and not part of a data source.

Also note that you must use the SetData method of the WCSeries object (the object representing a series) when passing literal values ​​to the chart. Since the Chart control itself can accept only a one-dimensional array of values, if it allowed you to pass literal values ​​to the SetData method of the WCChart object (the object representing a chart), it would have no way of knowing which values ​​belong to which series. The previous procedure handles this by simply looping through the series collection and passing the appropriate array of Values ​​to the current series' setdata method.

Binding to the Spreadsheet Component

The Following Subroutine, Taken from The LoadFromSpreadsheet.htm File in Chap03 Folder On your Companion CD, Shows How To Bind A Chart Component To Ranges In The Spreadsheet Component:

'------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------

'Bindcharttospreadsheet ()

'

'Purpose: Binds a Chart To Specified Ranges in The Source Spreadsheet

'IN: cspace reference to the chartspace object

'Sheet Reference To The Spreadsheet Object' Srngseries String-Based Range Reference To Where The

'Series Names Come from

'Srngcategories string-based ranging reason to where the

'Category Names Come from

'Srngvalues ​​string-based range reference to where the

'Values ​​Are

'

Sub Bindcharttospreadsheet (Cspace, Sheet, SrngSeries, Srngcategories, _

SRNGVALUES, FSERIESINCILS)

'Local Variables

Dim Cht 'Chart Object That We'll Create In The Chart Space

DIM Ser 'Temporary Series

DIM RNGVALUES 'RANGE Object of Values

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'First Tell The Chart That ITS Data IS Coming from The Spreadsheet

Set cspace.datasource = Sheet

'Create a chart in the chart space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

'Now call setdata to bind the various dimensions

'Second Parameter Is Zero, Meaning The First Data Source Sould BE

'Used if There multiple data sources

CHT.SetData C.chdimseriesNames, 0, SrngSeries

CHT.SetData C.chdimcategories, 0, Srngcategories

'The spreadsheet can bind to one-dimensional Ranges ONLY,

'So loop through the series collection and set the value

'for Each Series Individually

SET RNGVALUES = Sheet.Range (SrngValues)

For Each Ser IN Cht.SeriesCollection

IF fseriesincols thenser.setdata c.chdimvalues, 0, _

RNGVALUES.COLUMNS (SER.INDEX 1) .address

Else

Ser.SetData C.chdimvalues, 0, _

RNGVALUES.ROWS (SER.INDEX 1) .address

END IF

Next 'Server

End sub 'bindcharttospreadsheet ()

I would like to point out a few things about this example. First, to bind the Chart and Spreadsheet controls, I set the Chart control's DataSource property to the instance of the Spreadsheet control. By receiving the pointer to the Spreadsheet control instance, the Chart Control Can Now Ask The Spreadsheet Control for Cell Values ​​in The Specified Ranges.

Second, the SetData method is used to bind first the Series Names dimension and then the Categories dimension You must bind the chart dimensions in this order:. Series names first, then categories, then values ​​In the rare case in which you have only one. series of information, you can skip the Series Names dimension and just bind categories and values. Doing so will create one series for you with the default name Series, which you can change by setting the name or Caption property of the WCSeries object.

My last point is that when binding to the Spreadsheet component, the Chart component needs to receive explicit range references for the values ​​in each series. Unfortunately, you can not just hand the chart a two-dimensional range of values ​​and let it automatically figure out which series and categories the values ​​belong to. Instead, you must pass a one-dimensional range reference to the last parameter in the SetData method for each WCSeries object. The previous example does this in a generic fashion by using the Spreadsheet component's Range object to yield a range reference for each column or row in the two-dimensional range, which in turn gets passed to the series' SetData method. The fSeriesInCols flag indicates whether the values ​​for a given series are arranged down a column or across a row in the spreadsheet IF false, the rows collection is buy.Also Note That Example Adds 1 To the Series' Index Value. This is Because The C olumns and Rows collections are 1-based for compatibility with Excel's programming model, while the Chart component's series index is 0-based. Adding 1 to the series index yields the corresponding column or row in the range.

Binding to the data source component

The following method, taken from the LoadFromDSC.htm file in the Chap03 folder on the companion CD, shows how to bind a Chart component to a Recordset returned from the Data Source component (DSC). (We'll discuss the DSC more thoroughly in Chapter 5.)

'------------------------------------- -----------------------

'Bindcharttodsc ()

'

'Purpose: binds a chart to a recordset in the data source component.

'(This Example Creates a Pie Chart.)' In: Cspace Reference To The Chartspace Object

'DSC Reference to the Data Source Control

'Srsname name of recordset to bind to in the

'Data Source Control

'Scategories Name of the Result Column Containing Categories

'Svalues ​​name of the result column containing value

'

Sub Bindcharttodsc (Cspace, DSC, Srsname, Scategories, Svalues)

'Local Variables

Dim Cht 'Chart Object That We'll Create In The Chart Space

DIM Ser 'Temporary Series

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'First Tell The Chart That ITS Data IS Coming from

'the data source control

Set cspace.datasource = DSC

'Next Tell It What Recordset Within The Data Source Control

'IT Will Bind To

CSPACE.DATAMEMBER = Srsname

'Create a Pie Chart in the Chart Space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

cht.type = c.chcharttypepie

'Now call setdata to bind the various dimensions

'Second Parameter Is Zero, Meaning The First Data Source Sould BE

'Used if There multiple data sources

'In this Example of a Pie Chart, WE WILL Add ONE

'Series Manually and Use the setData Method There

Set ser = cht.seriescollection.add ()

SER.SETDATA C.CHDIMCATEGORIES, 0, Scategories

SER.SETDATA C.CHDIMVALUES, 0, SVALUES

'Finally, for this Example, Add Some' Data Labels Since It's A Pie Chart

Set dls = ser.datalabelscollection.add ()

DLS.HASPERCENTAGE = TRUE

DLS.haasvalue = false

End sub 'bindcharttodsc ()

The DSC can retrieve data from and provide data to both the Chart component and the PivotTable component. It also implements the same data source COM interface (IDataSource) that Visual Basic and Internet Explorer data source controls implement, so this code can be used for any Other Valid Data Source Control Used In Those Environments.

The DataSource and DataMember properties of the ChartSpace object are fundamental to this example. Since they are part of the data-binding standards established by Visual Basic and Internet Explorer, you will commonly see them on other data-bound controls in those environments. The DataSource property is set to point at the control providing the data (in this case the DSC), and the DataMember property is set to a string value naming the specific data set desired. Because a DSC can expose many data sets at once, the DataMember property IS Used to Tell The Chart Control Which Data Set To Request. If You Leave The DataMember Property Blank, The Chart Control Will Ask for The Default Data Set, The Identity of Which is determined by the dsc.

The SetData method is used in this example much the same way it was used in the BindChartToSpreadsheet method, except that the "data part" (the last parameter to SetData) is now the name of a column in the Recordset returned from the DSC. Alternatively , THIS DATA Part Can Be The Ordinal Index of The Column (0, 1, 2, And So ON). The Chart Control Will Pass THIS THE ADO FIELDS Collection Object's Item Method, So Any Value That Is Valid for That Method Can Be . used as the last parameter to the SetData method Typically, you use column names if you do not expect them to change over time but do expect the ordinal positions to change; you use ordinal indexes if you do not expect them to change but do expect the column names to change.As stated earlier, an interesting twist of Pie charts is that the entries in the legend are categories, not series. Therefore, when binding a Pie chart, you should bind the column you want to appear in the Legend to the categories Dimension Rather Than the Serie S Dimension. This Also Applies To Stacked Pie Charts and Doughnut Charts.

The last code block in this example creates some data labels (which we just discussed) to show the percentage each data point contributes to the whole. The Chart control can show a number of values ​​for each data point, and by default the actual number value I set the HasperceTage property.

Although this particular example creates a Pie chart, you can use any of the supported chart types when binding to the DSC. I chose to create a Pie chart in this example only to show how binding is performed using the Pie chart type.

Binding to a recordsetthe folfromrecordset.htm file in the chap03 folder on The Companion CD, Shows How To Bind A Chart Control to an ADO RecordSet Object:

'------------------------------------- -----------------------

'Bindcharttorecordset ()

'

'Purpose: Binds a chart to a recordset. (This Example Creates A

'Scatter chart.)

'IN: cspace reference to the chartspace object

'Rst Reference to RecordSet Object to Bind To

'Sfldseries Name of the Series Field

'Sfldxvalues ​​name of the field containing the x value

'Sfldyvalues ​​name of the field containing the y

'

Sub Bindcharttorecordset (Cspace, RST, SfldSeries, SfldxValues, _

sfldyvalues)

'Local Variables

Dim Cht 'Chart Object That We'll Create In The Chart Space

Dim Serd 'Temporary Series Pointer

Dim Ax 'Temporary Axis Pointer

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'First Tell The Chart That ITS Data IS Coming from The Recordset

Set cspace.datasource = RST

'Create a Scatter Chart in The Chart Space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

cht.type = C.chcharttypeScatterMarkers

'Now call setdata to bind the various dimensions

'Second Parameter Is Zero, Meaning The First Data Source Sould BE

'Used if There multiple data sources

'In this Example of a Scatter Chart, We Will Bind' Two Value Dimensions: x and y

CHT.SetData C.chdimseriesNames, 0, SfldSeries

CHT.SetData C.chdimxValues, 0, SFLDXVALUES

CHT.SetData C.chdimyValues, 0, SfldyValues

'Finally, Let's Add Some Axis Labels Using

'the column names as the axis capen

Set ax = cht.axes (c.chaxispositionbottom)

Ax.hastitle = TRUE

Ax.title.caption = sfldxvalues

Ax.title.font.name = "tahoma"

Ax.title.font.size = 8

Ax.title.Font.Bold = true

Ax.numberformat = "#, ## 0"

Set ax = cht.axes (c.chaxispositionLeft)

Ax.hastitle = TRUE

Ax.title.caption = sfldyvalues

Ax.title.font.name = "tahoma"

Ax.title.font.size = 8

Ax.title.Font.Bold = true

Ax.Numberformat = "$ #, ## 0"

'Let's also set the marker size a bit smaller Than Normal

For Each Ser IN Cht.SeriesCollection

SER.Marker.size = 5

Next 'Server

End sub 'bindcharttorecordset ()

You will no doubt quickly notice that this example is similar to the previous example involving the DSC, except that this example uses a Scatter chart. This is because the ADO Recordset object is itself a valid data source in Visual Basic and Internet Explorer, and it implements the same data source interface as the DSC. This makes it possible to set the Chart control's DataSource property to point to the Recordset object just as you would set it when using the DSC. However, the Recordset object by definition has only one data set To Expose, So The DataMember Property Does Not Need To Be set by.

Because the chart type used in this example is a Scatter chart, the code sets two value dimensions:. X Values ​​and Y Values ​​As described earlier in the section on supported chart types, a Scatter chart uses two values ​​for each data point, so we need to bind the X Values ​​dimension to one column in the Recordset and the Y Values ​​dimension to another column. (You could bind them to the same column, but that would make for a highly correlated Scatter chart!) An Accident of Good Architecture

When I sent this chapter to the Chart component developers for review, one of them commented that the component does not actually "support" loading from a Recordset and that the OWC team had not officially tested this scenario. However, almost all the demos and real ....................... ..

The reason that loading the Chart component from a Recordset works is an accident of good architecture. When the Visual Basic and Internet Explorer development teams selected the standard data source interface (IDataSource), the

ADO

team decided that it made sense for the Recordset object to implement this interface since it could easily return the underlying IRowset interface from the GetDataMember method. Because the Chart control uses IDataSource when loading data from a DSC, it all just worked. To the Chart control , The RecordSet Object Looks Like Any Other Data Source Control.

When Binding to a RecordSet Object, You Must Ensure That The Recordset Is Using The Microsoft Windows Cursor Engine (WCE) Or Is Capable of Being Sorted and Scrolled. The WCE IS AN

ADO

component that provides scrolling, sorting, filtering, and more on any OLE DB Rowset regardless of the Rowset's source or native capabilities. To use this engine, set the CursorLocation property of your ADO Connection or Recordset object to adUseClient, which has a value of 3 if you are in an environment that does not recognize constants. To ensure that the Chart control can scroll around the Recordset, you can use the adOpenStatic cursor type, which also has a value of 3. use adOpenStatic or 3 for the CursorType parameter of the Recordset's Open method or for the CursorType property of the Recordset object. (Chapter 4 will discuss the WCE in more detail.) for an example of setting the necessary Recordset properties, see the full source listing in the LoadFromRecordset.htm file on the companion CD WHEN Viewing this file, Names for the axis capenn name for the axis captions. Scatter Charts Have Two Value Axes (x and y) SO you Should Give Those Axes Titles and Explain What Values ​​You Are Showing on Them. Using The Column Names in The RecordSet Can Be An Easy Way To Label There Axes; Of Course, You Can Set your OWN CAPTIONSET ARE NAMES IN The RecordSet Are Not Intelligible.

Binding to the pivottable component

The last possible source of data for the Chart component is the PivotTable component. (We will talk more about this component in the next chapter.) As you might expect, this component also implements the same data source interface that all valid data sources expose in Visual Basic and Internet Explorer, so the following example, taken from the LoadFromPivot.htm file in the chap03 folder on the companion CD, looks similar to the DSC example we discussed earlier but has a few important differences:

'------------------------------------- -----------------------

'Bindcharttopivot ()

'

'Purpose: Binds a chart to a pivottable company

'IN: cspace reference to the chartspace object

'PTable Reference to the Pivottable Object

'Fseriesincols boolean flag indicating WHether the Series

'Of the chart sale come from the column

'Axis or The Row Axis of the Pivottable Control

'

Sub Bindcharttopivot (Cspace, PTABLE, FSERIESINCOLS)

'Local Variables

Dim Cht 'Chart Object That We'll Create In The Chart Space

Dim Ax 'Temporary Axis Reference

DIM FNT 'TEMPORARY FONT REFERENCE

'Grab The Constants Object So That We Can Use Constant Names in

'The script. Note: this is needed only in Vbscript - do not include

'this in vba code.

Set c = cspace.constants

'Clear Out Anything That In The Chart Space

Cspace.clear

'First Tell The Chart That ITS Data IS Coming from The

'Pivottable Component

Set cspace.datasource = PTABLE

'Create a chart in the chart space

Set cht = cspace.Charts.Add ()

cht.haslegegend = true

cht.type = c.chcharttypebarclustered

'Now call setdata to bind the various dimensions

'Second Parameter Is Zero, Meaning The First Data Source Sould BE

'Used if There multiple data sources

IF fseriesincols.

CHT.SetData C.chdimseriesNames, 0, C.chpivotcolumns

CHT.SetData C.chdimcategories, 0, C.chpivotrows

Else

CHT.SetData C.chdimseriesNames, 0, C.chpivotrows

CHT.SetData C.chdimcategories, 0, C.chpivotcolumns

END IF 'FSERIESINCOLS

'Set the value dimension. The value' you pass for the data reason (The Last Parameter)

'is the index of the total you want to use.

'Since There IS Only One Total in this Example,

'We Pass Zero, Indicating The First One.

CHT.SetData C.chdimvalues, 0, 0

'Finally, Let's Add An Axis Title To The Value

'Axis, Using The Label On The Pivot Total

'as the caption, and set the number format

Set ax = cht.axes (c.chaxispositionbottom)

Ax.hastitle = TRUE

Ax.title.caption = ptable.activeview.dataaxis.totals (0) .caption

Set fnt = ax.title.font

FNT.NAME = "Tahoma"

FNT.SIZE = 8

FNT.BOLD = TRUE

Ax.numberformat = ptable.activeview.dataaxis.totals (0) .Numberformat

End sub 'bindcharttopivot ()

As in the earlier Recordset and DSC examples, to bind the Chart control to the PivotTable control, you start by setting the Chart control's DataSource property to point to an instance of the PivotTable control. As in the Recordset example, the PivotTable control has only one Data Set to Expose, So you do not need to change the datetribr.

The critical difference between this example and the DSC example is the use of special constant values ​​for the last parameter to the SetData method. As you will remember, this last parameter specifies which part of the data you want to bind to the specified chart dimension. in a PivotTable control, the logical parts available are the row and column pivot axes and all the totals in the view. in a PivotTable control, the row axis refers to all the labels displayed down the left side of the table, and the column axis refers to all the labels displayed across the top of the table (more on these axes in the next chapter). All the Chart control needs to know is which axis you want to bind to the Series Names dimension and which axis you want to bind to the Categories dimension.Binding the various values ​​dimensions of the Chart control is slightly different. Since a PivotTable report can display many totals at once, the Chart control needs to know which total you want to use for the specified values ​​dimension. You indicate this by passing the ordinal index of the total as the last parameter to the SetData method. In the BindChartToPivot example, we use a Clustered Bar chart so that each data point has only one value. We tell the Chart control to use the total at index zero (the first one, since this is 0-based) for the data point values. Note that this is the ordinal index of the available totals shown in the PivotTable control's current view-not all the possible totals in the Data Source.

While the PivotTable control does implement the standard COM interface for a data source control, it does not know how to return ADO Recordsets or OLE DB Rowsets. The Chart control has special code for knowing how to read the PivotTable control's crosstab data display and properly ignore subtotals and grand totals, which if used, would skew the chart's scale. Therefore, even though the Chart control can consume data from the PivotTable control, not all data-bound controls will be able to use the PivotTable control as their data source.Chart And Axis Titles

Charts can be effective mechanisms for displaying large quantities of information in a quick-to-assimilate visual manner However, the data plotted in charts is rarely self-explanatory;. Often you will want to add a descriptive title to your chart or to the axes Displayed within it.

USING MULTIPLE TOTALS for MultiValued Charts

The Scatter, Bubble, Polar, and OHLC chart types all have something in common:. They need more than one value to determine a data point on the chart A Scatter chart requires both an X value and a Y value, a Bubble chart needs both those values ​​as well as a bubble size value, a Polar chart needs Theta and R values, and an OHLC chart needs the four values ​​its name suggests. Since PivotTable reports can show more than one total at a time, it's often desirable to map those Totals to the Different Chart Values ​​to make A Single Data Point.

You can do this by specifying the index of the total in the PivotTable view as the last parameter to the SetData method. For example, to bind the first total to X and the second total to Y in a Scatter chart, you would write this code :

CHT.SetData C.chdimxValues, 0, 0 'First Total

cht.SetData c.chDimYValues, 0, 1 'Second totalSometimes you want to use those multiple totals with a chart type that uses only one value per data point, such as a Stacked Column chart. In this case, you might want the caption of The Total To Appear As a Nested Category or a Nested Series Label. To do this, you use a special constant:

CHT.SetData C.chdimcategories, 0, C.chpivotrowaggrates

This setting would use any total captions appearing on the row axis as nested category names on a hierarchical category axis. To get the results you want, you also should set the TotalsOrientation property of the PivotView object to the plTotalOrientationRow constant so that the total captions are Displayed on each rot.

Perhaps you want to display multiple totals as different series in the chart To do this, leave the column axis on the PivotTable report empty, add the totals you want to appear as different series, and then write the following code.:

CHT.SetData C.chdimseriesNames, 0, C.chpivotcolaggRegates

............................... ..

If you add more than one chart to the Chart control (detailed in the section "Multiple Charts in 'Chart Space'"), you can give each chart its own title. In fact, you can give the Chart control itself a global title that will be displayed above all the individual charts. Chart titles can be formatted with all the basic font attributes (name, size, bold, italic, underline, and color). You can also set their backgrounds to a specific color or leave them transparent. The Same Is True for Axis Titles.

By default, newly created charts will have neither a chart title nor axis titles. You can add chart and axis titles either at design time using the Property Toolbox or at runtime using code. The following method, taken from the AddTitles.htm file in the CHAP03 Folder on the Companion CD, Shows How To Add A Chart Title: '-------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

'Setcharttitle ()

'

'Purpose: Sets The Chart's Title

'In: Cht Reference to a chart

'Stitle New Title Caption

'

Sub SetChartTitle (CHT, Stitle)

DIM FNT 'TEMPORARY FONT REFERENCE

'If the title is nonblank

If Len (Stitle)> 0 THEN

'Add a title if neseary

cht.haastitle = true

'Set the caption and its font formatting

cht.title.caption = stitle

Set fnt = cht.title.font

FNT.NAME = "Tahoma"

FNT.SIZE = 10

FNT.BOLD = TRUE

Else

'Title Is Blank. Remove IT.

cht.haastitle = false

END IF

End sub 'setcharttitle ()

You Add Axis Title The Same Way You Add a Chart Title, Except That The First Parameter of The Method Accepts An Axis Object Reference Instead of a Chart Object Reference.

Also note that you can set the Color property for the title's font or background to either an RGB color value or to one of the Internet Explorer color names-for instance, "FireBrick" or "PapayaWhip". This also applies to any use of color In The Chart Control, Such As The Chart's Background Color, Plot Area Color, Series Color, And So ON.

Axis Labels

By default, the Chart control will include labels on all your axes to show where a data point lies on the scale (for value axes) or which category a data point belongs to (for category axes). You might want to adjust a few aspects of these labels using either code at runtime or the Property Toolbox at design time.For value axes, the labels show numeric points on the overall value scale of the axis. These numbers initially have no formatting unless the source is a spreadsheet with cells containing explicit numeric formatting. to change the default number formatting, set the axis's NumberFormat property to a new number format name or string. The list of named formats you can use appears in the Spreadsheet control's help file (opened by clicking the Help button on the spreadsheet) under the topic, "Number formats in a spreadsheet." you can also build a custom format string just like you can in Excel, and the symbols used in custom number formats are documented in the Excel 2000 help files Starting with the overview Topic Titled, "CREATE A CUSTOM NUMBER FORMAT."

For both value and category axes, you can choose to drop some of the labels-for example, showing only every fifth label. This is useful only for axes that have too many labels to show without overlapping and for which the dropped labels can be inferred from visible labels such as a series of dates. category axes will not drop labels by default. But suppose you have a large set of dates on a category axis. you can choose to drop some of them by setting the TickLabelSpacing property of the appropriate WCAxis object, either by selecting the axis and using the Property Toolbox at design time or in code at runtime. The setting for this property determines how many labels to skip between the labels that appear. Note that this property affects only labels, meaning the axis will still show tick marks where each label would have appeared. However, you can drop some of these tick marks as well by adjusting the TickMarkSpacing property to the same value as TickLabelSpacing.The Chart Legend

By default, newly created charts do not have a legend. If you plan on showing more than one series of data points, you might want to add a legend to your chart to explain which color maps to which series. To add a legend, either ............... ..

Initially, the legend will contain one entry per series by default, but you can adjust that. To hide a legend entry, use the LegendEntries collection of the WCLegend object to retrieve the legend entry you want to hide, and then set the returned object's Visible Property to false. at Design Time, You CAN SIMPLY SELECT The Legend Entry Itself and press the delete key.

If you have more than one chart in the Chart control, you can create a legend for each individual chart or you can create one for the control as a whole. If you are showing multiple Pie charts, for example, it probably makes the most sense to show only one legend for all the pies since the color / category mapping will be same for each chart. Other chart types that show the series in the legend can benefit from individual legends if the set of series displayed differs among charts.One rather annoying aspect of using a single legend for multiple charts that show series in the legend (charts other than Pie, Stacked Pie, and Doughnut) is that the Chart control will initially add an entry to the legend for each occurrence of each series in each chart. If you are showing two series on five charts, the chart space legend will contain ten legend entries, the same two entries repeated five times. To eliminate the extra legend entries, select and delete them at design time or use the WCLegendEntr Y Object's Visible Property in Code As Described Earlier.

转载请注明原文地址:https://www.9cbs.com/read-117889.html

New Post(0)