Programming MS Office 2000 Web Components Chapter 3 2

xiaoxiao2021-03-06  37

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.

My email: tangtaike@163.com

For reprint, please notify us in advance.

Chapter III Second Section Infographic Components Advanced Features

We have learned all the basic knowledge about the chart, and now let us study some more advanced features of the chart component, especially those that are not generated in traditional Excel chart. Many of these features are used in solutions described in the second part of this book. When we discuss these solutions, if you can't remember the basics of a particular function, you can look back in this section to get a more general explanation.

Multiple chart in "Chart Space"

As mentioned earlier, the chart control can display multiple charts at a place named chart space. In fact, the top programming interface of the chart control is called ChartSpace. When you insert a new chart control in the container, the default name of the control is usually called ChartSpace1.

When you need to display a plurality of associated maps, and when you can easily compare each diagram, you will be useful to display multiple charts in one control. It is often known as "small multiple designs", which can become a powerful analysis tool. For example, if you need to display sales data, salesperson, as well as geographic locations at the same time, you can create a chart for each country, showing the sales staff as a series in each chart, and the time is displayed as category. Figure 3-18 shows the possible looks of the last chart.

The chart control can display up to 16 charts in the same chart space, but all charts must share the same set of categories. If the two graphs each contain different sets of categories, the set of categories for all charts will be the collection of each chart. This is because small multi-design relies on the consistency of the scale in each chart, the tissue of the series, so that you can easily discover significant differences and trends between the charts.

Figure 3-18. Multiple chart in a chart space.

The chart control does not automatically set the scale of the value axis in each chart, but you can use a small piece of code from the multiplecharts.htm file under the CHAP03 folder in the book CD.

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

'NormalizeCharts ()

'

'Purpose: Set the value shaft of all charts in the chart space to you so you can accurately compare each value.

'Incoming parameters: cspace = Reference to ChartSpace object

'Naxis = value axis index in WCAXES collection

'

Sub NormalizeCharts (CSPACE, NAXIS)

'Local variable

DIM CHT 'points to the temporary reference to the Chart object

DIM ax 'points to the temporary reference to the Axis object

DIM NMAX 'maximum value on each axis

Nmax = 0

'Traverse all charts once, get the maximum value of all chart median axes

For Each Cht in Cspace.Charts

Set ax = cht.axes (naxis)

If Ax.scaling.maximum> Nmax Then

nmax = ax.scaling.maximum

END IF

Next 'CHT

'Traverse each graph again, set the maximum value

For Each Cht in Cspace.Charts

Set ax = cht.axes (naxis)

Ax.scaling.maximum = nmaxnext 'CHT

End sub 'NormalizeCharts ()

This code performs two traverses twice on all Chart objects in the chart space. The maximum value on all value shafts is traveled for the first time, and the second time the scaling.maximum property on each icon is set to the maximum value, so all charts have the same maximum on their value shaft. Note that this method is only necessary when your chart has a value axis - it does not apply to multiple cakes, multiple stacked cakes, or multiple circles.

You can also control the layout of the control space in the control space by adjusting the ChartLayout and ChartWrapCount properties of the top-level ChartSpace object. You can lay horizontally or vertically tiled horizontally or vertically by setting a ChartLayout property. The ChartWrapCount property controls how many charts are displayed in a row (or each column) in a row (or a column). You can also expand or reduce the size of the specific chart by adjusting the HeightRatio and WidthRatio properties of each WCChart object.

Service application

In addition to hosting on the form in the form of a COM control, each Office Web component can be used in a manner that is not visible and in memory. But when running in a Web Server environment, the chart component may be the most concerned part of the Office WEB component. When the OWC team started to issue a beta version in Microsoft, we immediately received many other groups from the company, they would like to know how to use the Chart control on the server to generate dynamic data charts (most cases, yes In order to provide a BUG statistical report). Many business activities include a set of metrics for evaluating product or operation processes; business executives have been dreaming that as long as you open his (or her) web browser, you can see a chart that reflects the real-time update data. Because the chart control can be used on the server side, and can generate graphic copies of the GIF format of the chart itself, many developers have found that the server can use the chart control to generate both to the Internet environment and can be used to include various kinds. Charts for real-time data in a business environment of different types of client computers is a great way.

When you use a chart control when the server uses a chart control, you can use all of its standard features. Also, the code we have discussed to load different types of data into the chart is also available in the server environment. Typically, an ADO Recordset object generated by another script on a server or another script is used to load chart controls. You can reference all elements in the chart, as if they are displayed on the screen, after you complete the chart, you can use the CHARTSPACE object's ExportPicture method to write the GIF graphics into a file. In the current version, the Chart control only supports the output of GIF graphics format, but you can specify any width and height of the output graphic (in pixels).

About server applications, the last point I need to explain is: You should check your Office2000 license protocol and ask the Microsoft Application Developer Customer Association (ADCU) representative to develop resolution on using Office Web components on the web server. More information of the program. During the writing of this book, the Office Marketing Group is incorporated with a special Office Web component server using licenses and Office use protocols together. Although many details have not been finalized, this license is expected to limit the number of clients so you can use these components on an Internet site.

Split axis

Another universally required chart generation function is the ability to divide the value axis in a certain point, which allows you to draw a small value and a large value on the same value axis, and can still display local changes, Figure 3- 19 describes a common split axis chart.

Figure 3-19. A split axis chart. The chart can have a split point on each value shaft, you can specify the exact value of the split and end on the value axis. This action can be done in the design phase in the Properties Toolbox: first select the value axis, then use the split axis segment in the Properties Toolbox to set the split value of the start and end. You can also complete the code at runtime: Set the HASSPLIT property of the axis's Scaling object to True, then set the splitminimum and splitmaximum properties.

Adjust the scale of the axis

By default, the chart control automatically selects a minimum and maximum value for the value axis, making all the data points to be seen, and some gaps are left around the plot area. However, if you need to overwrite these default settings, you can manually adjust the scaling property of an axis to accurately set the minimum and maximum values ​​you need.

Each WCAXIS object has a scaling property that returns a WCSCaling object. The WCSCaling object has an attribute called minimum and maximum, which can be accurately set by these attributes, or read the current value from these properties. You can also force the axis to return to the status of the time by setting the Hasautominimum and Hasautomaximum properties to TRUE.

You can also use WCSCaling objects to tell the axis to use the logarithmic scale instead of linear scale. Setting the wcscaling type attribute to ChscaleTypelogarithMic constants, you can turn the scale to a log scale, reset the Type property back to ChscaleTypeLinear constant, which can turn the scale into linear scale. You can also set the base of the log scale by adjusting the logbase property.

Another interesting setting you can adjust is the orientation property, which can make the scale to display in the opposite order from the minimum value to the maximum value. It may be useful for a value axis, or it may not be used, but this is the easiest way to display all kinds of categories on the category axis.

The most interesting part of the use of Scaling objects may be analog scaling and displacement on an axis. If the data points in your chart are high, it can be used to allow the analyst to enlarge a particular segment on the shaft and then move on the shaft to observe each segment. You can achieve this purpose by simply operating the minimum and maximum properties of the Scaling object, which causes the results of chart scaling and displacement, because the two properties will make the chart show less visual distance on the screen. Numerical distance.

Homemade chart tag

The chart component does not have the chart tag function you have seen in Excel. The chart tag is a larger screen tag that will be displayed when you stay on a data point or chart element. The chart tag displays the value, category, series, and other useful information. Bad news is that these chart tags are not the properties of the chart control itself; good news is you can add these tags from some events triggered by capturing chart controls. In the second part of this book, I will explain how you can create these homemade chart tags. Now, I just tell the principles of their work.

The chart control will trigger the MouseMove event when moving over the control above the control. In this incident, you can find the X and Y coordinates of the mouse current relative to the upper left corner of the control. This x and y coordinates not only help you prevent other elements in the location where the mouse is located, you can also pass them to the RangeFromPoint method of the ChartSpace object to get the CHART object that is currently located below the mouse. For example, if your mouse is above a data point, this method returns a WCPoint object, using this object, you can judge the parent series, category, and use of the data point to get the specific value of this data point. You can also use this WCPoint object to adjust this data point format, which means you can:, for example, change the color of the border to highlight this value, or change the internal color into a darker color or the current fill color A shallow shadow. If the mouse is above a chart element, such as the legend, you can get a WCLEGEND object from the return of this method. Use the Typename method in VBScript and VBA to determine what type of object you get from the RangeFromPoint method. You can also use the SelectionType property of the ChartSpace object to determine the type of object returned from the Selection property. Please refer to the reactingtomouse.htm file under the CD-CD CHAP03 folder, there is an example of using the chart component event and respond to the mouse in the file.

Why is it called RangeFromPoint?

When I first pay attention to the detail hidden in the chart component programming model, I asked the project manager of the chart component: Jason Cahill, why the name of this method is called RangeFromPoint, it is clear that it is independent of the RANGE, and returns a Chart object. I asked: "Why not call ObjectFromPoint?".

Jason explained that when Microsoft's auxiliary function group determines when the blind is created a screen reader, they need to return a method in Excel to return the current area below the mouse so that they can use the computer's sound system to read the value in the cell. . (If you confuse this, there is a corresponding explanation information: The purpose of the auxiliary function group is to make the computer to help those disabled, the screen reader uses the audio to read the text on the screen.) Excel will correctly Named RangeFromPoint because it returns a zone according to a (x, y) point. However, the auxiliary function group writes the name of this method into their application's code, and now anyone who wants to provide assistance for the screen reader must implement the RangeFromPoint method, even his or her app and spreadsheet. There is no relationship between the area.

Appendix: English

Advanced FunctionAlicity of the Chart Component

Now that we've covered all the basics of charting, let's explore a few of the more advanced features of the Chart component, especially those not found in traditional Excel charting. You will see many of these features put to use in the solutions presented in Part II of this book. When we get to those solutions, if you need to refresh your memory on the basics of any particular feature, simply refer back to this section for a more general explanation.Multiple Charts in "Chart Space"

As noted earlier, the Chart control can display more than one chart at a time in what is known as a chart space. The top-level programming interface for the Chart control is actually called ChartSpace, and when you insert a new Chart control into a Container, The Default Name Given The Control Is Usually Chartspace1.

Showing multiple charts at once in a control is useful for displaying related plots that you want to compare in one glance. This design, often called small multiples, can be a powerful analysis tool. For example, if you need to show sales data across time , salespeople, and geography simultaneously, you might create one chart for each country, each displaying the salespeople as series and the time as categories. Figure 3-18 shows what the resulting charts might look like.

The Chart control can show up to 16 charts in the same chart space, but all the charts must share the same set of categories. If two charts have a different set of categories, the set of categories used for both charts will be the union of the categories from each chart. This is because small-multiple designs rely on the consistency of the categories, series, and axis scalings among the various charts so that you notice large differences and trends easily.Figure 3-18. Multiple charts in one chart Space.

That said, the Chart control will not automatically normalize the value axis scales among all the various charts for you, but you can do this quite easily with a little bit of code from the MultipleCharts.htm file in the Chap03 folder on the companion CD:

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

'NormalizeCharts ()

'

'Purpose: Makes All Value Axes of Charts in a Chart Space The Same

'SO That You CAN Accurately Compare Values

'In: cspace = reference to the chartspace object

'Naxis = index of the value axis in the wcaxes collection

'

Sub NormalizeCharts (CSPACE, NAXIS)

'Local Variables

Dim Cht 'Temporary Chart Object Reference

Dim Ax 'Temporary Axis Object Reference

DIM NMAX 'Maximum Value Across The Axes

Nmax = 0

'Loop through all the charts overce to determine the Overall Maximum

For Each Cht in Cspace.Charts

Set ax = cht.axes (naxis)

If Ax.scaling.maximum> Nmax Then

nmax = ax.scaling.maximum

END IF

Next 'CHT

'Loop again to set the maximum

For Each Cht in Cspace.Charts

Set ax = cht.axes (naxis)

Ax.scaling.maximum = nmax

Next 'chtend sub' normalizecharts ()

The code here performs two loops over all the Chart objects in the chart space. The first determines the maximum value across all the value axes, and the second sets the Scaling.Maximum property to the maximum value so that all charts have the same maximum on ............. ..

You can also control the layout of multiple charts within the chart space by adjusting the ChartLayout and ChartWrapCount properties of the top-level ChartSpace object. You can set the ChartLayout property to make the charts lay out horizontally or vertically. ChartWrapCount controls how many charts appear .................. ..

Server-Side USE

Each of the Office Web Components can be used as a nonvisible, in-memory object in addition to a COM control hosted on a form. But when it comes to running on a web server, the Chart component is probably the most desirable of the Office Web Components. When the OWC team first started releasing beta builds internally at Microsoft, we immediately began to receive e-mail from other groups in the company that wanted to know how to use the Chart control on the server to generate charts of live data ( . in most cases, to report bug statistics) Many businesses have a set of metrics they use to measure a production or operational process; it's a manager's dream to simply open his or her web browser and see a chart with up-to-the- minute data. Since the Chart control can be used on the server and can emit a GIF image of itself, many developers find utilizing the Chart control on the server a compelling way to generate charts of live data that can be used across the Internet or in Enterprises Wher e the client desktop is heterogeneous.You will find this type of solution implemented in Chapter 6, where we will examine it in much greater detail. For now, I will familiarize you with what the Chart control can do when running on the server and show You the Basics of Saving The Chart Control's Contents as a gif Image.

You can employ all the normal features of the Chart control when using it on the server. Also, all the code we discussed earlier that is used to load the chart with different data is applicable in that environment. Typically, you load the Chart control from an ADO Recordset object obtained from either a server-side object or another script on the server. you can refer to all the elements of the chart as if they were on the screen, and when you are finished creating the chart, you can use the ChartSpace object's ExportPicture method to write the GIF image to a file. The Chart control supports exporting to only the GIF image format in this release, but you can specify any width and height you want in pixels.The last point I want to make about server -side usage is that you should check the license agreement that comes with your copy of Office 2000 and ask a Microsoft Application Developer Customer Unit (ADCU) representative for more information on distributing a solution that uses the Off ice Web Components on a web server. At the time of this writing, the Office marketing group was putting together a special server-side usage license for the Office Web Components. Although the details had not been finalized, this fee was intended to cover an Unlimited Number of Clients So That You Could Use these Components on an internet site.

Split

Axes

Another commonly requested charting feature is the ability to split a value axis at a certain point so that you can portray small and large numbers on the same value axis and still show the local variation. Figure 3-19 depicts a common Split-Axis chart.

Figures 3-19. A split-axis chart.

Charts can have one split per value axis, and you can specify the exact values ​​where the value axis's split starts and ends. You can do this in the Property Toolbox at design time by selecting the value axis and using the Split Axis section of the Property Toolbox to set the start and end split values. You can also do this with code at runtime by setting the HasSplit property of the axis's Scaling object to True and then setting the SplitMinimum and SplitMaximum properties.Adjusting an Axis's Scaling

The Chart control by default will choose an automatic minimum and maximum for a value axis that will make all the data points visible and leave a little bit of margin around the plot area. However, sometimes you will want to override these defaults and manually adjust an Axis's Scaling Attributes To Get Precisely The Minimum and Maximum You Want.

Every WCAxis object has a Scaling property that returns a WCScaling object. The WCScaling object has properties called Minimum and Maximum for setting an explicit minimum and an explicit maximum or for reading the current values. You can also set the HasAutoMinimum and HasAutoMaximum properties to True to Force the axis to return to automatic scaling behavior.

The WCScaling object also lets you tell the axis to use a logarithmic scale instead of a linear one. Set the Type property of WCScaling to the chScaleTypeLogarithmic constant to make the scale logarithmic, or restore it to the chScaleTypeLinear constant to make it linear again. You Can Also Adjust The Logbase Property to set the base of the logarithmic scale.

Another interesting setting you can adjust is the Orientation property, which makes a scale display backwards, from minimum to maximum, rather than vice versa. This might or might not be useful for a value axis, but it is the easiest way to make a category axis show the categories in reverse order.Probably the most interesting use of the Scaling object is to simulate zooming and panning on an axis. If your chart is densely packed with data points, it is useful to allow an analyst to zoom into a specific section of the axis and then pan across the axis to see various sections. You can do this by simply manipulating the Minimum and Maximum properties of the Scaling object, which has the effect of zooming and panning in the chart because the chart shows less numerical distance in The Same Visual Distance on The Screen.

Homemade Chart Tips

The Chart component does not yet have the chart tips feature that you have no doubt seen in Excel. Chart tips are the larger ScreenTips that show up when you hover the mouse over a data point or chart element. Chart tips show the data point's value, . category, series, and other useful information The bad news is that these chart tips are not a native feature of the Chart control; the good news is that you can add them yourself by catching a few events raised by the Chart control In Part. Ii of The Book, I Will Explain How you can create these homemade chart tips. For now, i will just give you the basics of how they work.

The Chart control raises the MouseMove event whenever the mouse is moved over the control. During this event, you can ask for the mouse's current X and Y coordinates with respect to the control's top-left pixel. These X and Y coordinates not only help you position other elements where the mouse is, but you can also feed them to the ChartSpace object's RangeFromPoint method to get the chart object that is currently under the mouse. For example, if your mouse is positioned over a data point, this method will return a WCPoint object, with which you can determine the parent series, the category, and the exact value of the point using the GetValue method. you can also adjust the formatting for that specific data point using the WCPoint object, which means you can, for instance , change the border color to highlight the value or change the interior color to a slightly darker or lighter shade of the current fill color. If the mouse is positioned over a chart element such as the legend, you wil l get a WCLegend object back from this method. Use the TypeName method in VBScript and VBA to determine what kind of object you get back from the RangeFromPoint method. You can also use the ChartSpace object's SelectionType property to determine the type of object returned from the SEE The File ReactingTomouse.htm in The Chap03 Folder on The Companion CD.

Why is it caled rangefrompoint?

When I first started looking into the nooks and crannies of the Chart component's programming model, I asked Jason Cahill, the Chart component's program manager, why this method was called RangeFromPoint when it clearly had nothing to do with ranges and instead returned chart objects. " Should not this be called ObjectFromPoint? "I asked.Jason explained that when Microsoft's accessibility group first decided to build screen readers for the blind, they wanted a method in Excel that would return the current range underneath the mouse so that they could read the values ​​in the cells over the computer's audio system. (in case you were wondering, the accessibility group makes computers accessible to people with disabilities. Screen readers use audio to "read" onscreen text aloud for blind users.) Excel correctly named the method RangeFromPoint Since It Returned A Range from A (X, Y) Point. However, The Accessibility Group Coded That Method Name Into Their Application, and Now Anyone Who Wants Accessibility to the Screen Reader Must Implement The RangeFromPoint Method Even Though His Or Her Application Might Not Have Anything to do with spreadsheet Ranges.

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

New Post(0)