Create Charts With Multiple Chart Types

You can create charts that apply different chart types to each data series. For example, you may want to create a column chart to display one series of data and then add another series that plots the data as a continuous line on the chart. These types of chart features enable you to create more complex-looking charts. By using multiple chart types, you create a chart that appears as a combination of various types of charts.

To set the chart type for a data series, you need to specify the SeriesCollection object that represents the data series that you want to modify. The SeriesCollection collection object contains each of the data series in the range of data on the chart as an individual SeriesCollection object. You reference an individual object using the corresponding index value, which Excel numbers from 1 to the number of data series in the range of data for the chart. For example, to reference the second data series, you can specify SeriesCollection(2).

To set the chart type for a data series, you need to modify the ChartType property for the specific SeriesCollection object. When you initially create your chart, you can either use this method to set the chart type for each individual data series or you can set the chart type for the entire chart, and then modify the ChartType property for the individual data series that you want to change.

When you utilize the ChartType property, you need to assign it one of the xlChartType constant values that represent the chart type you want to use for the data series. See Appendix A for a list of the xlChartType constant values that you can assign to the ChartType property.

CREATE CHARTS WITH MULTIPLE CHART TYPES

CREATE CHARTS WITH MULTIPLE CHART TYPES

Vba Chart Mutile

_D Create a new subroutine.

L0 Type Set NewChart = ThisWorkbooks.Charts.Add().

-Q Type NewChart.SetSourceData Source:=Workbooks("Sheet1") .Range("A1:D9"), replacing Workbooks("Sheet1") .Range("A1:D9") with the range of data for the chart.

Type NewChart.ChartType = xlColumnClustered, replacing xlColumnClustered with the chart type constant.

_D Create a new subroutine.

L0 Type Dim NewChart As Chart, replacing NewChart with the chart variable.

L0 Type Set NewChart = ThisWorkbooks.Charts.Add().

-Q Type NewChart.SetSourceData Source:=Workbooks("Sheet1") .Range("A1:D9"), replacing Workbooks("Sheet1") .Range("A1:D9") with the range of data for the chart.

Type NewChart.ChartType = xlColumnClustered, replacing xlColumnClustered with the chart type constant.

L-0 Type NewChart.PlotBy = xlColumns.

WORKING WITH CHARTS

Ex m

You can use a different chart type for each data series. Excel keeps track of the different series chart types and groups the common types together as ChartGroup objects. Each ChartGroup object contains one or more data series with the same chart type. Excel stores all ChartGroup objects within the ChartGroups collection object, which you can access via the ChartGroup property.

Because of these series groupings, the ChartGroups object provides methods for returning the collection of the ChartGroup objects that correspond to the particular type. For example, if you want to access the line chart type ChartGroup objects, you use the LineGroups method. The example illustrates how to count the number of column chart types in a chart. You can use the methods in the table with the ChartGroup objects.

Example:

DataSeriesCount =

ThisWorkbook.Charts(1).ColumnGroups.Count

METHOD

DESCRIPTION

AreaGroups

Determines the number of series with an area data type.

BarGroups

Determines the number of series with a bar chart data type.

ColumnGroups

Determines the number of series with a column chart data type.

DoughnutGroups

Determines the number of series with a doughnut chart data type.

LineGroups

Determines the number of series with a line chart data type.

PieGroups

Determines the number of series with a pie chart data type.

—Q Type NewChart.Series Collection (2) .ChartType = xlLine, replacing 2 with the series reference and xlLine with the desired chart type.

0 Switch to Excel and run the macro.

Excel creates a new chart using the first chart type value for the entire chart and modifying the chart type for the referenced data series.

—Q Type NewChart.Series Collection (2) .ChartType = xlLine, replacing 2 with the series reference and xlLine with the desired chart type.

0 Switch to Excel and run the macro.

■ Excel creates a new chart using the first chart type value for the entire chart and modifying the chart type for the referenced data series.

0 -2

Responses

Post a comment