Link to home
Start Free TrialLog in
Avatar of svvada
svvada

asked on

msGraph DataLabel Count

I'm using the 'Microsoft Graph 11.0 Object Library' (Type Lib) to add a chart to a PowerPoint presentation. I've loaded the data into the graph so now I'm looking at formatting the presentation. I would like to change the font on the datalabels and I've figured out how to do this:

    ThisSeries := (IDispatch(ThisChart.SeriesCollection(1)) as Graph_TLB.Series);
    ThisDataLable := (IDispatch(ThisSeries.DataLabels(1)) As DataLabel);
    ThisDataLable.Font.Size := 8;

but I've not found a way to get the count from the SeriesCollection or the DataLables so I don't know how many series or how many datalables per series there is. So if there's a way to get this information it would be of great help. Boot the SeriesCollection interface and the DataLables interface has a count property. But I can't seem to get a hold of any of them?
Avatar of atul_parmar
atul_parmar
Flag of India image

To loop through collection in Delphi, you will need to use IEnumVariant.
See http://www.swissdelphicenter.ch/torry/showcode.php?id=2135 on how to use IEnumVariant.
The code will look like the following. (Not tested)

var
  SeriesCol : IEnumVariant ;
  Series : Olevariant;
begin
  SeriesCol := IUnknown(ThisChart.SeriesCollection._NewEnum) as IEnumVariant;
  while SeriesCol .Next(1, Series, value) = 0 do
  begin
     // here you will get the series object e.g.
  end;
end
Avatar of svvada
svvada

ASKER

The thing is that I can't get hold of the collection? The Chart interface has a function SeriesCollection that takes an index as parameter.

    function SeriesCollection(Index: OleVariant): IDispatch; dispid 68;

ASKER CERTIFIED SOLUTION
Avatar of atul_parmar
atul_parmar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of svvada

ASKER

Looks good for the series!
But then I need to get to the datalabels. I tried the same thing as for the series, but got a message telling me that it could not access _NewEnum?
Avatar of svvada

ASKER

Never mind. Got that from a series where no datalabels were assigned.
Avatar of svvada

ASKER

atul_parmar, thanks for the help earlier, a quick followup question.
When I have this part in the code:

  while SeriesCol.Next(1, Series, value) = 0 do
  begin
    // Series (ISeries)
  end;

the Graph.exe process is not stopped when I free the PowerPoint objects? If I remove the while loop it works fine. Got any ideas as to why?
It might be because of the olevariant variables (MyChart, Series, ...etc) are still refering to the objects of chart. free them all. e.g.
MyChart := unassigned; // plz. do it for all the used variables
Avatar of svvada

ASKER

That did the trick! Thanks again.