title: Delphi 6 - Create Excel chart from delphi application - data and chart on the same pagen
body: <p>I need to create a chart in excel in a delphi application based on some data from a table.</p>
  
  <p>I created the excel worksheet and filled n rows of data from the table. Now I need to make the chart based on the data.</p>
  
  <p>We have to add two Legent entries(categories) - D5:D15 and E5:E15
  and one Horizontal(Category) Axis labels -F5:F15</p>
  
  <p>I tried the following to get this.
  When executed I got the error message </p>
  
  <blockquote>
    <p>Method 'setsourcedata' not supported by automation object.</p>
  </blockquote>
  
  <p>I tried the <code>SeriesCollection.item.value</code> method then also the system gave the same message.</p>
  
  <pre><code>procedure TForm1.Make_a_Chart;
  var
    Sheets,Ch1 : Variant;
  begin
    ch1 := XLApp.ActiveWorkBook.Sheets[1].ChartObjects.Add ( 500,100,400,200 ); // creates a new chart in the specified 
    Sheets := XLApp.Sheets;
    ch1.Chart.ChartWizard (
                           Sheets.Item['Delphi Data'].Range['D5:D15'],   // 1  Source
                           xlBarStacked, //  2  The chart type.
                           8,            //  3  Format - The option number for the built-in autoformats. Can be a number from 1 through 10, depending on the gallery type.
                           2,            //  4  PlotBy - Specifies whether the data for each series is in rows or columns. Can be one of the following XlRowCol constants.
                           1,            //  5  CategoryLabels - An integer specifying the number of rows or columns within the source range that contain category labels.
                           1,            //  6  SeriesLabels - An integer specifying the number of rows or columns within the source range that contain series labels.
                           False,        //  7  HasLegend - 'true' to include a legend.
                           'My Report',  // 8  Title - The Chart control title text.
                           'Y Axis',      // 9  CategoryTitle - The category axis title text.
                           'X Axis',      // 10  ValueTitle - The value axis title text
                           2                //  11  ExtraTitle - The series axis title for 3-D charts or the second value axis title for 2-D charts.
                         );
    ch1.setsourcedata(Sheets.Item['Delphi Data'].Range['E5:E15'],xlColumns,2);
    ch1.Chart.ChartType := xlBarStacked;
  // ch1.SeriesCollection.Item[1].Values := Sheets.Item['Delphi Data'].Range['E5:E15'];
  end;
  </code></pre>