def add_chart(params = {})
      # Type must be specified so we can create the required chart instance.
      type     = params[:type]
      embedded = params[:embedded]
      name     = params[:name]
      raise "Must define chart type in add_chart()" unless type

      chart = Chart.factory(type, params[:subtype])
      chart.palette = @palette

      # If the chart isn't embedded let the workbook control it.
      if ptrue?(embedded)
        chart.name = name if name

        # Set index to 0 so that the activate() and set_first_sheet() methods
        # point back to the first worksheet if used for embedded charts.
        chart.index = 0
        chart.set_embedded_config_data
      else
        # Check the worksheet name for non-embedded charts.
        sheetname  = check_chart_sheetname(name)
        chartsheet = Chartsheet.new(self, @worksheets.size, sheetname)
        chartsheet.chart   = chart
        @worksheets << chartsheet
      end
      @charts << chart
      ptrue?(embedded) ? chart : chartsheet
    end
def add_chart(params = {})
      # Type must be specified so we can create the required chart instance.
      type     = params[:type]
      embedded = params[:embedded]
      name     = params[:name]
      raise "Must define chart type in add_chart()" unless type

      chart = Chart.factory(type, params[:subtype])
      chart.palette = @palette

      # If the chart isn't embedded let the workbook control it.
      if ptrue?(embedded)
        chart.name = name if name

        # Set index to 0 so that the activate() and set_first_sheet() methods
        # point back to the first worksheet if used for embedded charts.
        chart.index = 0
        chart.set_embedded_config_data
      else
        # Check the worksheet name for non-embedded charts.
        sheetname  = check_chart_sheetname(name)
        chartsheet = Chartsheet.new(self, @worksheets.size, sheetname)
        chartsheet.chart   = chart
        @worksheets << chartsheet
      end
      @charts << chart
      ptrue?(embedded) ? chart : chartsheet
    end
This method is use to create a new chart either as a standalone worksheet
 (the default) or as an embeddable object that can be inserted into
 a worksheet via the
 {Worksheet#insert_chart}[Worksheet.html#method-i-insert_chart] method.

     chart = workbook.add_chart(:type => 'column')

 The properties that can be set are:

     :type     (required)
     :subtype  (optional)
     :name     (optional)
     :embedded (optional)

 === :type

 This is a required parameter.
 It defines the type of chart that will be created.

     chart = workbook.add_chart(:type => 'line')

 The available types are:

     area
     bar
     column
     line
     pie
     scatter
     stock

 === :subtype

 Used to define a chart subtype where available.

     chart = workbook.add_chart(:type => 'bar', :subtype => 'stacked')

 Currently only Bar and Column charts support subtypes
 (stacked and percent_stacked). See the documentation for those chart
 types.

 === :name

 Set the name for the chart sheet. The name property is optional and
 if it isn't supplied will default to Chart1 .. n. The name must be
 a valid Excel worksheet name. See add_worksheet
 for more details on valid sheet names. The name property can be
 omitted for embedded charts.

     chart = workbook.add_chart(:type => 'line', :name => 'Results Chart')

 === :embedded

 Specifies that the Chart object will be inserted in a worksheet
 via the {Worksheet#insert_chart}[Worksheet.html#insert_chart] method.
 It is an error to try insert a Chart that doesn't have this flag set.

     chart = workbook.add_chart(:type => 'line', :embedded => 1)

     # Configure the chart.
     ...

     # Insert the chart into the a worksheet.
     worksheet.insert_chart('E2', chart)

 See Chart[Chart.html] for details on how to configure the chart object
 once it is created. See also the chart_*.rb programs in the examples
 directory of the distro.