workbook.createChart(options)

Method Description

Creates a chart , A chart is a workbook component that enables you to visualize your dataset query results using predefined chart and graph types, such as line graphs and bar charts. A chart is built from an underlying dataset and can also include a category, a legend, series, a type, expressions, filters, stacking behavior indicators, along with an ID, a name, a title, and a subtitle.

For more information about charts in SuiteAnalytics, see Workbook Charts.

Returns

workbook.Chart

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/workbook Module

Sibling Module Members

N/workbook Module Members

Since

2020.2

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.aggregationFilters

Array<workbook.ConditionalFilter |workbook.LimitingFilter>

optional

The set of conditional filters or limiting filters that are applied to the chart. When multiple filters are defined, they are aggregated together to form a single compounded filter.

options.category

workbook.Category

required

The category of the chart.

options.dataset

dataset.Dataset

required

The underlying dataset that the chart is based on. A chart can include only the data (fields) that are included in the dataset.

options.datasetLink

datasetLink.DatasetLink

required

The datasetLink on which the chart is based

options.filterExpressions

workbook.Expression[]

optional

The simple, non-aggregated value-based filters for the chart.

options.id

string

required

The ID of the chart.

options.legend

workbook.Legend

required

The legend for the chart.

options.name

string

required

The name of the chart.

options.portletName

string | workbook.Expression

required

The name of the portlet for the chart.

options.series

workbook.Series[]

required

The set of series for the chart. Each series includes information about how each data point is calculated. For example, a series can represent the sum of transaction amounts for a customer in a particular month.

options.stacking

workbook.Stacking

optional

The stacking type that describes how the chart data is stacked.

options.subTitle

string | workbook.Expression

optional

The subtitle of the chart.

options.title

string | workbook.Expression

optional

The title of the chart.

options.type

workbook.ChartType

required

The type of the chart.

Errors

Error Code

Thrown If

INVALID_CHART_TYPE

The value specified for the options.type parameter is invalid. Set this value using workbook.ChartType

INVALID_STACKING_TYPE

The value specified for the options.stacking parameter is invalid. Set this value using workbook.Stacking.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/workbook Module Script Samples. Also see Full scripts in the Tutorial: Creating a Workbook Using the Workbook API topic.

            // Add additional code
...
// Create a basic Chart
var myChart = workbook.createChart({
    name: 'myChart',
    id: '_myChart',
    type: workbook.ChartType.BAR,
    category: myCategory,
    legend: myLegend,
    series: [mySeries],
    dataset: myDataset
});

// Create a comprehensive Chart
var myChart = workbook.createChart({
    name: 'myChart',
    title: 'My Chart Title',
    subTitle: 'My Chart Subtitle',
    id: '_myChart',
    type: workbook.ChartType.BAR,
    stacking: workbook.Stacking.PERCENT,
    category: myCategory,
    legend: myLegend,
    series: [mySeries],
    filterExpressions: [myExpression],
    aggregationFilters: [myLimitingFilter],
    dataset: myDataset,
    datasetLink: myDatasetLink,
    portletName: myPortlet
});
...
// Add additional code 

          

Related Topics

General Notices