Chart

Updated at:

This topic describes the API operations related to Chart objects of tables.

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart

Returns a Chart object.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart

    expression: an Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects in the active worksheet.
      const shapes = await activeSheet.Shapes;
    
      // Obtain a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    }

Methods

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.SetSourceData()

Sets the source data range for the specified chart.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.SetSourceData({ Source, PlotBy })

    expression: an Application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Source

    Range

    Yes

    Specifies the range that contains the source data.

    PlotBy

    Enum

    No

    Specifies whether the source data is in rows or columns. For more information, see XlRowCol.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects in the active worksheet.
      const shapes = await activeSheet.Shapes;
    
      // Obtain a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    
      // Obtain the range of source data.
      const source = await activeSheet.Range('A1:D4');
    
      // Set the source data range for the chart.
      await chart.SetSourceData(source, 1);
    }

Properties

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.HasLegend

Specifies whether the chart has a legend.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.HasLegend = Boolean

    expression: an Application object.

    If you set the property to true, the chart has a legend. If you set the property to false, the chart does not have a legend.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects in the active worksheet.
      const shapes = await activeSheet.Shapes;
    
      // Obtain a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    
      // Obtain the range of source data.
      const source = await activeSheet.Range('A1:D4');
    
      // Set the source data range for the chart.
      await chart.SetSourceData(source, 1);
    
      // Specify that the chart does not have a legend.
      chart.HasLegend = false;
    }

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.HasTitle

Specifies whether the chart has a title.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.HasTitle = Boolean

    expression: an Application object.

    If you set the property to true, the chart has a title. If you set the property to false, the chart does not have a title.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects in the active worksheet.
      const shapes = await activeSheet.Shapes;
    
      // Obtain a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    
      // Obtain the range of source data.
      const source = await activeSheet.Range('A1:D4');
    
      // Set the source data range for the chart.
      await chart.SetSourceData(source, 1);
    
      // Specify that the chart does not have a title.
      chart.HasTitle = false;
    }

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.ChartTitle

Specifies the title of the chart by using the ChartTitle property.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.ChartTitle

    expression: an Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects.
      const shapes = await activeSheet.Shapes;
    
      // Return a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    
      // Obtain the range of the data source.
      const source = await activeSheet.Range('A1:D4');
    
      // Bind the chart to the data source.
      await chart.SetSourceData(source, 1);
    
      // Specify the title of the chart.
      chart.ChartTitle.Text ='This is the new title';
    }

ChartTitle

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.ChartTitle

Specifies a title.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.ChartTitle

expression: an Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects.
      const shapes = await activeSheet.Shapes;
    
      // Return a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    
      // Obtain the range of the data source.
      const source = await activeSheet.Range('A1:D4');
    
      // Bind the chart to the data source.
      await chart.SetSourceData(source, 1);
    
      // Specify a new title
      chart.ChartTitle.Text = 'this is the new title';
    }

Property

ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.ChartTitle.Text

Specifies the title for a chart by using the text property.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart.ChartTitle.Text

    expression: an Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Obtain the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Obtain all Shape objects.
      const shapes = await activeSheet.Shapes;
    
      // Return a single Shape object.
      const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300);
    
      // Obtain a single Chart object.
      const chart = await shape.Chart;
    
      // Obtain the range of the data source.
      const source = await activeSheet.Range('A1:D4');
    
      // Bind the chart to the data source.
      await chart.SetSourceData(source, 1);
    
      // Specify the new title.
      chart.ChartTitle.Text = 'this is the new title';
    }