I have a Chart
containing two ChartGroup
s. I never did this intentionally, so I cannot guess what caused this. Can anyone give all options (either VBA or else)?
If I know which are the possible actions that may have led to this, I can be aware of and control/avoid them.
PS: The downside of this is that I have quite a bit of code that uses the PlotOrder
for identifying Series
. When there is more than one ChartGroup
, PlotOrder
is not a unique identifier of a Series
in a Chart
(it is unique within a ChartGroup
). In the long run, I Will have to adapt my code, anyway. But for the time being, I could take care of adapting my charts to having a single ChartGroup
, as much as possible. Is there an easy way to reassign the ChartGroup
of a Series
? (this would make a single post with two questions...)
This question stemmed from
Excel: Duplicated PlotOrder for two Series in a Chart
EDIT: I list here some interesting findings (which revolve around this topic, but do not answer the specific question).
I found this in the official site
ChartGroups Collection: "A collection of all the ChartGroup objects in the specified chart. Each ChartGroup object represents one or more series plotted in a chart with the same format." Even if I did not find it explicitly stated, it appears that each
XlChartType
(theEnumeration
type of.ChartType
for aSeries
) would be obviously associated with a given format, e.g.,xlXYScatter
with scatter.ChartGroup Object: "Represents one or more series plotted in a chart with the same format."
All
Series
in aChartGroup
should have the same "format". But the converse is not true: it is possible to haveSeries
with the same format in differentChartGroup
s. See point 3 and example below.From ChartGroup Object: "Because the index number for a particular chart group can change if the chart format used for that group is changed, it may be easier to use one of the named chart group shortcut methods to return a particular chart group. The PieGroups method returns the collection of pie chart groups in a chart, the LineGroups method returns the collection of line chart groups, and so on." E.g., LineGroups Method.
This allows for point 2: The
PieGroups
would return a collection ofChartGroup
s. There may be more than one suchChartGroup
, and all of the series would have a Pie format.The available named chart group shortcut methods to return a particular chart group are not comprehensive. E.g., there is no
XYScatterGroups
method.
As an example of point 2, I have a chart with all series with format XYScatter. The 5 available XlChartType
s (with their numeric values and description, according to XlChartType Enumeration) are
xlXYScatter -4169 Scatter.
xlXYScatterSmooth 72 Scatter with Smoothed Lines.
xlXYScatterSmoothNoMarkers 73 Scatter with Smoothed Lines and No Data Markers.
xlXYScatterLines 74 Scatter with Lines.
xlXYScatterLinesNoMarkers 75 Scatter with Lines and No Data Markers.
In the chart, there are 2 ChartGroups, as shown in the dump (from a custom Sub)
ChartObject 'Chart 36', no. series: 6
* ChartGroup, .Index: 1, no. series: 2
** plot order: 1, type: -4169, chart: 'Chart 36', chart type: 73, no. points: 17
** plot order: 2, type: -4169, chart: 'Chart 36', chart type: -4169, no. points: 17
* ChartGroup, .Index: 2, no. series: 4
** plot order: 1, type: -4169, chart: 'Chart 36', chart type: 75, no. points: 2
** plot order: 2, type: -4169, chart: 'Chart 36', chart type: -4169, no. points: 24
** plot order: 3, type: -4169, chart: 'Chart 36', chart type: 75, no. points: 33
** plot order: 4, type: -4169, chart: 'Chart 36', chart type: -4169, no. points: 5
Note that there are series of type xlXYScatter
(-4169) in both ChartGroup
s. I could change the format of Series
2 of ChartGroup
1 to any of the 5 types, and it would not change its ChartGroup
.