Microsoft KB Archive/287666

= 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.   Use any text editor or HTML editor to save the following code as Chartdemo.htm :





Dim c      Set c = ChartSpace1.constants 'Create arrays for the x-values and the y-values. Dim xValues, yValues1, yValues2 xValues = Array(&quot;Beverages&quot;, &quot;Condiments&quot;, &quot;Confections&quot;, _                      &quot;Dairy Products&quot;, &quot;Grains & Cereals&quot;, _                       &quot;Meat & Poultry&quot;, &quot;Produce&quot;, &quot;Seafood&quot;) 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 = &quot;Sales Per Category&quot; '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 = &quot;Full Year 2000&quot; 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 = &quot;2001 YTD&quot; 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 = &quot;$#,##0&quot; axRightAxis.NumberFormat = &quot;0&quot; 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

 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).

