Microsoft KB Archive/287666

From BetaArchive Wiki
Knowledge Base


How To Change Label Orientation with the Office XP Chart Component

Article ID: 287666

Article Last Modified on 2/22/2007



APPLIES TO

  • Microsoft Office Web Components
  • Microsoft Office Web Components



This article was previously published under Q287666

SUMMARY

When you use either the Microsoft Office 2003 Chart component or the Microsoft Office XP Chart component to create a chart, you may find that the tick labels on an axis are crowded and are difficult to read. This problem occurs if the quantity of the labels or if the length of the labels exceeds the amount that can be clearly rendered on the axis. To correct this problem, you can change the orientation for tick labels on an axis by setting the Orientation property for the axis. Tick labels may be oriented horizontally, upward (+90 degrees vertically), or downward (-90 degrees vertically). This article provides sample script that changes tick label orientation for a Chart component that is hosted on a Web page.

Note The ability to change tick label orientation is a new feature of the Office 2003 Chart component and of the Office XP Chart component. Tick label orientation cannot be changed with the Microsoft Office 2000 Chart component.

MORE INFORMATION

Note The following code uses the Office XP version of the Chart object. For the Office 2003 version of the Chart object, you must replace clsid:0002E556-0000-0000-C000-000000000046 in the code with clsid:0002E55D-0000-0000-C000-000000000046.

  1. Use any text editor or HTML editor to save the following code as Chartdemo.htm:

    <html>
    
    <body>
    <object classid="clsid:0002E556-0000-0000-C000-000000000046" id="ChartSpace1">
    </object>
    </body>
    
    <script language="VBScript">
    
           Dim c
           Set c = ChartSpace1.constants
           
           'Create arrays for the x-values and the y-values.
           Dim xValues, yValues1, yValues2
           xValues = Array("Beverages", "Condiments", "Confections", _
                           "Dairy Products", "Grains & Cereals", _
                           "Meat & Poultry", "Produce", "Seafood")
           yValues1 = Array(104737, 50952, 78128, 117797, 52902, 80160, _
                            47491, 62435)
           yValues2 = Array(20000, 15000, 36000, 56000, 40000, 18000, 20000, _
                            33000)
           
           'Create a new chart.
           Dim oChart
           ChartSpace1.Clear
           Set oChart = ChartSpace1.Charts.Add
           
           'Add a title to the chart.
           oChart.HasTitle = True
           oChart.Title.Caption = "Sales Per Category"
           
           'Add a series to the chart with the x-values and y-values
           'from the arrays and then set the series type to a column chart.
           Dim oSeries
           Set oSeries = oChart.SeriesCollection.Add
           oSeries.Caption = "Full Year 2000"
           oSeries.SetData c.chDimCategories, c.chDataLiteral, xValues
           oSeries.SetData c.chDimValues, c.chDataLiteral, yValues1
           oSeries.Type = c.chChartTypeColumnClustered
           
           oChart.Axes(0).Orientation = c.chLabelOrientationDownward 'Category axis
           
           'Add another series to the chart with the x-values and the y-values
           'from the arrays and then set the series type to a line chart.
           Set oSeries = oChart.SeriesCollection.Add
           oSeries.Caption = "2001 YTD"
           oSeries.SetData c.chDimCategories, c.chDataLiteral, xValues
           oSeries.SetData c.chDimValues, c.chDataLiteral, yValues2
           oSeries.Type = c.chChartTypeLineMarkers
           
            'Add a value axis to the right of the chart for the second series.
            Dim axisScale
            Dim axRightAxis
            Set axisScale = oChart.Axes(c.chAxisPositionLeft).Scaling
            Set axRightAxis = oChart.Axes.Add(axisScale)
            axRightAxis.Position = c.chAxisPositionRight
    
           'Format the value axes.
           oChart.Axes(c.chAxisPositionLeft).NumberFormat = "$#,##0"
           axRightAxis.NumberFormat = "0"
           oChart.Axes(c.chAxisPositionLeft).MajorUnit = 20000
           axRightAxis.MajorUnit = 20000
           
           'Show the legend at the bottom of the chart.
           oChart.HasLegend = True
           oChart.Legend.Position = c.chLegendPositionBottom
    
    </script>
    </html>
                        
  2. Start Microsoft Internet Explorer and then move to Chartdemo.htm.

    Notice that the chart rendered on the Web page and that the orientation of the category labels is set to -90 degrees (or downward).


REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

288907 IINFO: Binding the Office XP Chart Component to a Data Source


289288 INFO: Using Timescale Axes with the Office XP Chart Component


286211 How To Create a Combination Chart Using the Office XP Chart Component



Additional query words: owc chart space charting graph label labels legend graphing

Keywords: kbhowto kbofficewebchart KB287666