Programming MS Office 2000 Web Components Chapter 3 Section III

xiaoxiao2021-03-06  61

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 3, Section 3 Programming Model Key Elements

Like the previous chapter, I will focus on the key elements of the chart component programming model in this chapter. The properties, methods, and events listed in this section will probably be used frequently, and classify and organize these methods and events in accordance with common tasks.

I no longer repeat the contents of all controls that have been mentioned in the OFFIC Web component library in the previous chapter - You can return to Chapter 2 to browse those lists and interpretations of those properties.

Create a chart in the chart space

When you create a new ChartSpace object, it does not contain any charts. Use the WCCHARTS collection Add method to add a chart to the ChartSpace object. Table 3-1 lists the properties and methods used when the chart is added to the chart or remove the chart from the space.

Table 3-1. The properties and methods used when the chart is added to the chart space or remove the chart from the space.

Attribute or method

description

Chartspace.Charts

This property returns a WCCHARTS collection that contains all WCCHART objects in the chart control.

WCCHARTS.ADD

Use this method to add a new chart to the chart space.

Chartspace.clear

This method clears all the content from the chart control. Using this method quickly removes all charts, data sources, and any other elements created in the chart space.

Change the type of chart or series

You should remember that we discussed various chart types very early in this chapter. Convert a chart type into another chart type and set a property as simple. As shown in Table 3-2.

Table 3-2. Change the properties and constants of the chart or series of series.

Attribute or enumeration value

description

WCCHART.TYPE

This property settings or extracts all the types of all series in a chart.

WCSERIES.TYPE

This property settings or extracts a single series in the chart. Each series in multiple series can have their own type, but not all types can be combined into a chart (just like we mentioned in the "Combined Chart" section in front).

Chartcharttypeenum

This enumeration contains all constants that can be used in the Type property described above.

Load the data into the chart

Table 3-3 lists the methods used when loading data into chart components. If you need more detailed description and example code, you can refer to the "Load" section in front of this chapter.

Table 3-3. Methods of loading data into the chart.

method

description

Wcchart.setdata

This method can be used to load all data (including the series) into the entire chart at a time.

WCSERIES.SETDATA

This method loads the data into a specified series.

Output GIF graphics

You can always output the current content of the chart control in the form of a GIF graphic to the disk in the form of GIF graphics. This requires the ExportPicture method described in Table 3-4.

Table 3-4. Create a method of GIF graphics for chart controls.

method

description

Chartspace.exportPicture

This method outputs the current content of the chart control into a GIF graphics file. You can specify the file name, the width, and the height. If you specify an optional FilterName parameter, it must be "gif" because GIF is the format that is only supported by the current version control.

Operating axis

You often need to adjust the appearance of various axes in your chart. Please use the properties listed in Table 3-5 to complete these tasks.

Table 3-5. Format the properties of the axes in the chart.

Attributes

description

WCCHART.AXES

This property returns a WCAXES collection that you can get a specific axis. If you want to find the axis with the position of the shaft, you can use the appropriate constant in the ChartaxisPositionenum enumeration. If you want to look up in the order of the axis, you can use them to locate the debt value in the collection. Wcaxis.numberformat

This property settings or extracts the digital format for the value axis tag. You can use any digital format supported by any spreadsheet, including the pre-name format and customized format.

Wcaxis.font

This property returns the OWCFont object of the axis. You can use the individual properties of this object to adjust the name, size, and other properties of the axis tag.

Wcaxis.hastitle

This property settings or gets the shaft has a title. If this property is false, there is no title; the space that should take up will be reclaimed by the chart. If this property is set to true, the axis will have a title; you can use the wcaxis.title property to get the WCTITLE object, and set its text. Note that if you access the title property when wcaxis.hastitle property is False, it will cause runtime errors.

Wcaxis.title

This attribute returns the WCTIL object of the shaft, using it you can set the text, font, and color properties of the title.

Wcaxis.ticklabelspacing

This property sets or extracts the space for the scale tag for the axis. The scale label space determines how many labels between the labels displayed are discarded. This trick is useful when you have too much label you want to display. The discarded label can be calculated according to the surrounding label.

Wcaxis.tickmarkspacing

This property is set or the space between the scale marks on the axis. Like the TickLabelsPacing property, this property determines how many markers between those displayed are discarded.

Operational legend

You may need to hide or display a graphical illustration, or hide a map item. Please use the properties described in Table 3-6 to complete these tasks.

Table 3-6. Operation The properties of the display of the legend.

Attributes

description

Chartspace.haschartspaceLegend, Wcchart.haslegegend

Like the attributes introduced in Table 3-5, the HaschartSpaceLegend and Haslegend properties define the chart space and a separate chart showing the legend, and whether it is a legend reserved space. In order to use the ChartSpaceLegend or Legend property below, you need to set the HaschartSpaceLegend or HASLEGEND attribute to True first.

Chartspace.ChartSpaceLegend, WCCHART.LEGEND

The ChartSpaceLegend and Legend properties returned to the legend representing the entire chart space, and the WCLGEND object representative of a single chart.

WCLEGEND.LGENTENTRIES

This property returns a WCLEGENDENTRIES collection, which contains all items in the legend. This collection has a count property, you can tell how many items in the legend, there is an Item property, let us take each item.

WCLEGENDENTRY.Visible

This attribute defines whether an image is displayed in the legend. This image item will be hidden if you set it to false.

WCLEGEND.PSITION

This attribute defines which location is placed in the chart. It can be placed on top, bottom, left, or right (default location).

Useful event

The chart control exposes some interesting events you might need to capture. All events are triggered from top ChartSpace objects. Table 3-7 lists these most interesting events.

Table 3-7. Useful chart event.

event

description

Click, DBLClick is triggered when the user clicks or doubles anywhere in the chart control. The system passes a WCChartEventInfo object to these events, so that the mouse can be judged in the X and Y coordinates in the chart control, and if they pass them to the RangeFromPoint method, the chart object at the (x, y) point can be obtained.

Mousemove

Trigrated when the user moves the mouse over the chart control. The WCChartEventInfo object is also passed to this event.

DataSetChange

Triggered when a binding data source is notified when chart data changes. The chart control is automatically updated to display new data; however, you should use this event to reset the chart because it is possible to add a new series. Be careful not to put too much code in this event: Because any changes in source data will trigger this event, it may be triggered very frequently.

Small knot

Although the chart component may look very simple, it is actually quite complicated. In this chapter, we have learned the functions of many chart controls. However, in the second part of this book I will discuss some solutions created using the chart components, and you will find more information to use chart components. Also, spend some time to read the example files in this chapter in the CD, which will help you start writing using chart controls.

Appendix: English

Key Elements of The Programming Model

As in the previous chapter, I want to finish by highlighting the key elements of the Chart component's programming model. The properties, methods, and events listed in this section are the subset that you will likely want to use often and are organized according to the Tasks You Will Typically Want To Perform.

I will not repeat the parts of the Spreadsheet component's programming model that I noted in the previous chapter as applying to all the controls in the Office Web Components library-you can refer back to Chapter 2 for a list and explanation of those properties.

Creating Charts in the Chart Space

When you create a new ChartSpace object, it initially does not contain any charts. To add a chart to the ChartSpace object, use the Add method of the WCCharts collection. Table 3-1 lists the properties and methods you will use to add and remove Charts from the chart space.

Table 3-1. Properties and Methods for Adding and Removing Charts from the Chart Space.

Property Or Method

Description

Chartspace.Charts

This Property Returns The Wccharts Collection of All The Wcchart Objects in The Chart Control.WCCHARTS.ADD

Use this method to add a new chart to the chart space.

Chartspace.clear

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

Changing Chart Or Series Types

As you will recall, we discussed The Various Chart Types Much Earlier in The Chapter Types Much Earlier In The Chapter Types Much Earlier In The Chapter Types Much Earlier In The Chapter Types Much Earlier In The Chapter Type.

Table 3-2. Properties and constants for Changing Chart Or Series Types.

Property or enum

Description

WCCHART.TYPE

This Property Sets Or Returns The Type for All Series in A Chart.

WCSERIES.TYPE

This property sets or returns the type for a single series in a chart. Multiple series can each have their own type, but not all types can be combined in one chart (as discussed earlier in the chapter in the "Combination Charts" section).

Chartcharttypeenum

This Enumeration Contains All The Constants You CAN Use with The Two Type Properties Just Described.

Loading the chart with data

THE APLANATION AND EXAMPLE COMPONENT WITH TO LOAD THE MORE WIL1 TO LOAD THE METORT INTATIONS AND EXAMPLE COMPONEN THE TO LOAD The Method Company.

Table 3-3. Methods for Loading Data Into a chart.

Method

Description

Wcchart.setdata

This Method Can Be Used to Load Data INTO The Entire Chart Atce, Including The Series Names.

WCSERIES.SETDATA

This Method Loads Data Into A Given Series.

Exporting a GIF Image

You can export the Chart control's current contents to a GIF image on disk at any time. Use the ExportPicture method, which is described in Table 3-4.Table 3-4. Method for creating a GIF image of the chart space.

Method

Description

Chartspace.exportPicture

This method exports the Chart control's current contents to a GIF image file. You can specify the filename, width, and height. If you specify the optional FilterName parameter, it must be "GIF" since the only format implemented in this version of the control IS GIF.

Working with axes

Often You Want To Adjust The Look of The Various Axes in Your Chart. Use the property Outlined in Table 3-5 To Accomplish this.

Table 3-5. Properties for Formatting The Chart Axes.

Property

Description

WCCHART.AXES

This property returns the WCAxes collection, from which you can obtain a specific axis. To ask for an axis by its location, use the appropriate constant from ChartAxisPositionEnum. To retrieve the axes in order, use their index values.

Wcaxis.numberformat

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

Wcaxis.font

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

Wcaxis.hastitle

This property sets or returns whether the axis has a title If this property is False, no title exists;. The space it would have used is reclaimed for the chart If this property is set to True, the axis will have a title;. You CAN use the wcaxis.title property to get at the wctitle Object and set it title Property While Wcaxis.hastitle IS False Results in a runtime error.wcaxis.title

This Property Returns The Wctitle Object for the Axis, with Which You Can Set The Title's Caption, Font, And Color Settings.

Wcaxis.ticklabelspacing

This property sets or returns the tick label spacing used for the axis. The tick label spacing determines how many labels are dropped from the axis between those that are displayed. This technique is useful for dropping date values ​​when you have too many to show. The Dropped Labels Can Be Assumed Based on The Surrounding Labels.

Wcaxis.tickmarkspacing

This Property Sets Or Returns The Spacing Between Tick Marks on An Axis. Like The Ticklabelspacing Property, this property determines How Many Tick Marks Should Be Dropped Between Those That Are Shown.

Manipulating the legend

You might want to hide or show the legend of a chart or hide individual legend entries. To do so, use the profmenties discussed in Table 3-6.

Table 3-6. Properties for manipulating legend display.

Property

Description

Chartspace.haschartspaceLegend, Wcchart.haslegegend

Like the WCAxis.HasTitle property described in Table 3-5, the HasChartSpaceLegend and HasLegend properties determine whether the chart space and individual chart will show and reserve space for a legend. To use the ChartSpaceLegend or Legend property described below, first set the HasChartSpaceLegend or Haslegend Property to True.ChartSpace.ChartSpaceLegend, Wcchart.Legend

........................... ...CRIPLIED BOOSURCEMY.

WCLEGEND.LGENTENTRIES

This property returns the WCLegendEntries collection of all entries in the legend. The collection has a Count property that tells you how many entries appear in the legend and an Item property that lets you retrieve each one.

WCLEGENDENTRY.Visible

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

WCLEGEND.PSITION

This property determines where the legend is placed in the chart. It can be placed on the top, bottom, left side, or right side (the default) of the char.

USEful Events

The Chart Control Exposed A FEW Interesting Events That You Might Want To Catch. All Events Are Raised from The Top-Level Chartspace Object. Table 3-7 Lists the MOSTING Events.

Table 3-7. Useful Chartspace Events.

Event

Description

Click, DBLClick

Raised whenever the user clicks or double-clicks anywhere on the Chart control. Use the WCChartEventInfo object passed to these events to determine the current X and Y coordinates of the mouse within the Chart control, and pass those to the RangeFromPoint method to retrieve the chart Object at what (x, y) Point.

Mousemove

Raised WHENEVER THE User Moves The Mouse over The Chart Control. The wccharteventinfo object is also passed to this event.datasetchange

. Raised whenever a bound data source notifies the chart that the data has changed The Chart control will automatically update to show the new data; however, you should use this event to reformat the chart in case new series were added Beware of putting too much. Code in this event: Since Any Change To The Source Data Will Raise The Event, IT CAN Fire Quite Offen.

Summary

Although the Chart component might look rather simple on the surface, there is quite a bit of complexity hiding in it. We've covered much of the functionality of the Chart control in this chapter. However, you'll find more information on using the Chart component in Part II of this book where I discuss several solutions you can build using it. Also, spend some time looking at this chapter's example files on the companion CD as they will help you get started writing code against the Chart control.

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

New Post(0)