Chart

GitHubEdit on GitHub
Packages@univerjs-pro/sheets-chart
PRO

The facade class for the chart.

This class should not be instantiated directly. Use factory methods on univerAPI instead.

Overview

@univerjs-pro/sheets-chart (FChart)

MethodDescription
chartId-
getCategoryDataGet the category data of the chart
getChartIdGet the chart id
getRangeGet the range of the chart
getSeriesDataGet the series data list of the chart
modifyReturns a new FChartBuilderBase instance that modifies this chart
subUnitId-
unitId-
updateRangeUpdate the range info of the chart

@univerjs-pro/sheets-chart (FChartBuilderBase)

MethodDescription
addRangeAdds a range to the chart this builder modifies
asLineChartReturns a LineChartBuilder instance
asPieChartReturns a PieChartBuilder instance
asRadarChartReturns a RadarChartBuilder instance
buildBuilds the chart to reflect all changes made to it
clearRangeClears the range from the chart this builder modifies
getChartTypeGets the chart type of the chart this builder modifies
setAbsolutePositionSets the position by pixel
setAllSeriesStyleSets styles for all series
setAxisPointerStyleSets the axis pointer style
setChartTypeThe type of chart to create
setHeightSets the height of the chart in pixels
setInvalidValueStrategySets how to handle invalid data in the chart
setOptionsThe options for the chart
setPositionSets the position
setRightYAxisTextStyleSets the text style for the chart right y-axis
setRightYAxisTitleSets the title of the chart right y-axis
setSeriesStyleSets the series style by series index
setThemeSets the theme of the chart
setTransposeRowsAndColumnsSets whether to transpose the rows and columns
setWidthSets the width of the chart in pixels
setXAxisTextStyleSets the text style for the chart x-axis
setXAxisTitleSets the title of the chart x-axis
setYAxisTextStyleSets the text style for the chart y-axis
setYAxisTitleSets the title of the chart y-axis

@univerjs-pro/sheets-chart (LineChartBuilder)

MethodDescription
setDataPointColorThe color of the data point in the line chart
setDataPointShapeThe shape of the data point in the line chart
setDataPointSizeThe size of the data point in the line chart
setLineStyleThe line style of the line chart
buildBuilds the chart to reflect all changes made to it

@univerjs-pro/sheets-chart (PieChartBuilder)

MethodDescription
setBorderColorSets the color of the border around the pie chart
setDoughnutHoleSets the size of the hole in the center of the pie chart
setHasPaddingAngleSets whether the pie chart has a padding angle
setIsHalfPieSets whether the pie chart is a half pie chart
setRosePieSets whether the pie chart is a rose pie chart
setShowLabelLineSets whether the pie chart shows label lines
buildBuilds the chart to reflect all changes made to it

@univerjs-pro/sheets-chart (RadarChartBuilder)

MethodDescription
setFillSets whether the radar chart is filled
setShapeSets the shape of the radar chart
buildBuilds the chart to reflect all changes made to it

APIs

Data

getCategoryData

Get the category data of the chart.

Signature

getCategoryData(): IChartDataCategory | undefined

Returns

  • IChartDataCategory | undefined — The category data of the chart.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const charts = fWorksheet.getCharts();
if (charts.length > 0){
  const categoryData = charts[0].getCategoryData();
  console.log(categoryData);
}
Source: @univerjs-pro/sheets-chart

getRange

Get the range of the chart.

Signature

getRange(): ISheetChartSourceSingleRange | undefined

Returns

  • ISheetChartSourceSingleRange | undefined — The range of the chart.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const charts = fWorksheet.getCharts();
console.log(charts[0]?.getRange());
Source: @univerjs-pro/sheets-chart

getSeriesData

Get the series data list of the chart.

Signature

getSeriesData(): IChartDataSeries[] | undefined

Returns

  • IChartDataSeries[] | undefined — The series data list of the chart.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const charts = fWorksheet.getCharts();
if (charts.length > 0){
 const seriesData = charts[0].getSeriesData();
 console.log(seriesData);
}
Source: @univerjs-pro/sheets-chart

updateRange

Update the range info of the chart. The range info includes the range of the chart and the direction in source.

Signature

updateRange(rangeInfo: ISheetChartSourceSingleRange): Promise<boolean>

Parameters

  • rangeInfo ISheetChartSourceSingleRangeNo description

Returns

  • Promise<boolean> — Whether the update is successful.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Get all charts on the active sheet.
const charts = fWorksheet.getCharts();

// Switch chart row direction
if (charts.length > 0){
  const rangeInfo = { ...charts[0].getRange() };
  rangeInfo.isRowDirection = !rangeInfo.isRowDirection;
  charts[0].updateRange(rangeInfo);
}
Source: @univerjs-pro/sheets-chart

Modification

modify

Returns a new FChartBuilderBase instance that modifies this chart.

Signature

modify(): FChartBuilderBase

Returns

  • FChartBuilderBase — The new FChartBuilderBase instance.
Source: @univerjs-pro/sheets-chart

Miscellaneous

chartId

Signature

chartId: string

Returns

  • string — See signature above.
Source: @univerjs-pro/sheets-chart

getChartId

Get the chart id.

Signature

getChartId(): string

Returns

  • string — The chart id.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const charts = fWorksheet.getCharts();
console.log(charts[0]?.getChartId());
Source: @univerjs-pro/sheets-chart

subUnitId

Signature

subUnitId: string

Returns

  • string — See signature above.
Source: @univerjs-pro/sheets-chart

unitId

Signature

unitId: string

Returns

  • string — See signature above.
Source: @univerjs-pro/sheets-chart

FChartBuilderBase - Range & Position

addRange

Adds a range to the chart this builder modifies.

Signature

addRange(range: IRange | string): this

Parameters

  • range IRange | string — The range string or object to add for chart source data. The should be not a single cell.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

clearRange

Clears the range from the chart this builder modifies.

Signature

clearRange(): this

Returns

  • this — This builder, for chaining.
Source: @univerjs-pro/sheets-chart

setPosition

Sets the position, changing where the chart appears on the sheet. anchorRowPos and anchorColPos are 0-indexed. This api can only work in the active sheet.

The chart's start anchor position is the top left-hand corner of the chart. The rowOffset and columnOffset are the pixel offsets from the anchor position.

Signature

setPosition(anchorRowPos: number, anchorColPos: number, rowOffset: number, columnOffset: number): this

Parameters

  • anchorRowPos number — The chart's top side is anchored in this row.
  • anchorColPos number — The chart's left side is anchored in this column.
  • rowOffset number — The chart's top left-hand corner is offset by this many pixels.
  • columnOffset number — The chart's lower left-hand corner is offset by this many pixels.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell F3 and offset 20 pixels to the right and down.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(2, 5, 20, 20)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setAbsolutePosition

Sets the position, changing where the chart appears on the sheet by pixel.

The chart's start anchor position is the top left-hand corner of the chart. This api is opposite to setPosition.

Signature

setAbsolutePosition(x: number, y: number): this

Parameters

  • x number — The x-coordinate of the chart's top left-hand corner.
  • y number — The y-coordinate of the chart's top left-hand corner.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is (100, 200) pixels from the top left-hand corner of the sheet.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setAbsolutePosition(100, 200)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

FChartBuilderBase - Chart Type & Size

getChartType

Gets the chart type of the chart this builder modifies.

Signature

getChartType(): ChartTypeBits

Returns

  • ChartTypeBits — The chart type of the chart this builder modifies.
Source: @univerjs-pro/sheets-chart

asLineChart

Returns a LineChartBuilder instance for creating a line chart.

Signature

asLineChart(): LineChartBuilder

Returns

  • LineChartBuilder — The LineChartBuilder instance.
Source: @univerjs-pro/sheets-chart

asPieChart

Returns a PieChartBuilder instance for creating a pie chart.

Signature

asPieChart(): PieChartBuilder

Returns

  • PieChartBuilder — The PieChartBuilder instance.
Source: @univerjs-pro/sheets-chart

asRadarChart

Returns a RadarChartBuilder instance for creating a radar chart.

Signature

asRadarChart(): RadarChartBuilder

Returns

  • RadarChartBuilder — The RadarChartBuilder instance.
Source: @univerjs-pro/sheets-chart

setChartType

The type of chart to create. The following are the possible values: Line, Column, ColumnStacked, ColumnPercentStacked, Bar, BarStacked, BarPercentStacked, Pie, Doughnut, Area, AreaStacked, AreaPercentStacked, Radar, Scatter, Combination.

Signature

setChartType(chartType: ChartTypeBits): this

Parameters

  • chartType ChartTypeBits — The type of chart to create.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .build();
await fWorksheet.insertChart(chartInfo);

// Get all charts on the active sheet.
const charts = fWorksheet.getCharts();

// Update the first chart type to line after 3 seconds.
setTimeout(() => {
  const newChartInfo = fWorksheet.newChart(charts[0])
    .setChartType(univerAPI.Enum.ChartType.Line)
    .build();
  fWorksheet.updateChart(newChartInfo);
}, 3000);
Source: @univerjs-pro/sheets-chart

setWidth

Sets the width of the chart in pixels.

Signature

setWidth(width: number): this

Parameters

  • width number — The width of the chart in pixels.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The width of the chart is 600 and the height is 400.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setWidth(600)
  .setHeight(400)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setHeight

Sets the height of the chart in pixels.

Signature

setHeight(height: number): this

Parameters

  • height number — The height of the chart in pixels.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The width of the chart is 600 and the height is 400.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setWidth(600)
  .setHeight(400)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

FChartBuilderBase - Options

setOptions

The options for the chart. This function will overwrite existing options and merge new options property.

Signature

setOptions(optionPath: string, optionVal: unknown): this

Parameters

  • optionPath string — The path of the option to set. A '' path means the root of the options object.
  • optionVal unknown — The value to set. Undefined value will be ignored, and null means delete the property. If a path is '', the value must be the whole options object.

Returns

  • this — The builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorkSheet = fWorkbook.getActiveSheet();
const chartBuilder = fWorkSheet.newChart().asPieChart();
const chartBuilderInfo1 = chartBuilder
  .addRange('A1:D6')
  .setOptions('title.content', 'Chart Title')
  .setOptions('legend.position', 'right')
  .setDoughnutHole(0.5)
  .setHasPaddingAngle(true)
  .setRosePie(true)
  .setIsHalfPie(true)
  .build();
// setOptions can be replaced by setOptions('', { ... })
const chartBuilderInfo2 = chartBuilder
  .addRange('A1:D6')
  .setOptions('', {
    "title": {
      "content": "Chart Title"
    },
    "legend": {
      "position": "right"
    },
    "pie": {
      "doughnutHole": 0.5,
      "hasPaddingAngle": true,
      "isHalfPie": true,
      "rosePie": true
    }
  })
  .build();
await fWorkSheet.insertChart(chartBuilderInfo1);
// or they are same effect
// await fWorkSheet.insertChart(chartBuilderInfo2);
Source: @univerjs-pro/sheets-chart

setTransposeRowsAndColumns

Sets whether to transpose the rows and columns of the chart.

Signature

setTransposeRowsAndColumns(transposeRowsAndColumns: boolean): this

Parameters

  • transposeRowsAndColumns boolean — Whether to transpose the rows and columns of the chart. The default value is false.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The chart will transpose the rows and columns.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  // the chart will transpose the rows and columns
  .setTransposeRowsAndColumns(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setTheme

Sets the theme of the chart. If the theme name is not registered, a default theme will be used.

Signature

setTheme(theme: string): this

Parameters

  • theme string — The theme name of the chart.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// register your theme
const theme = { // your theme object
  'version': 1,
  'themeName': 'myTheme',
  'theme': {
    // ... Some code is omitted for brevity
    color: [
      '#893448',
      '#d95850',
      '#eb8146',
      '#ffb248',
      '#f2d643',
      '#ebdba4'
    ],
    // ... Some code is omitted for brevity
    visualMapColor: [
      '#893448',
      '#d95850',
      '#eb8146',
      '#ffb248',
      '#f2d643',
      'rgb(247,238,173)'
    ],
    // ... Some code is omitted for brevity
    'axes': [
      // ... Some code is omitted for brevity
    ]
    // ... Some code is omitted for brevity
  }
};
fWorksheet.registerChartTheme('myTheme', theme);

// use your theme for chart
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setTheme('myTheme')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

FChartBuilderBase - Axis & Title

setXAxisTitle

Sets the title of the chart x-axis.

Signature

setXAxisTitle(title: string): this

Parameters

  • title string — The title of the chart x-axis.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The x-axis title is 'xAxis Title text'.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setXAxisTitle('xAxis Title text')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setYAxisTitle

Sets the title of the chart y-axis.

Signature

setYAxisTitle(title: string): this

Parameters

  • title string — The title of the chart y-axis.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The y-axis title is 'yAxis Title text'.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setYAxisTitle('yAxis Title text')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setRightYAxisTitle

Sets the title of the chart right y-axis.

Signature

setRightYAxisTitle(title: string): this

Parameters

  • title string — The title of the chart right y-axis.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The right y-axis title is 'rightYAxis Title text'.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setRightYAxisTitle('rightYAxis Title text')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setXAxisTextStyle

Sets the text style for the chart x-axis.

Signature

setXAxisTextStyle(textStyle: IChartTextStyle): this

Parameters

  • textStyle IChartTextStyle — The text style for the chart x-axis.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The x-axis style is set.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setXAxisTextStyle({
    content: 'xAxis Title text',
    fontSize: 12,
    fontColor: '#ff0000'
  })
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setYAxisTextStyle

Sets the text style for the chart y-axis.

Signature

setYAxisTextStyle(textStyle: IChartTextStyle): this

Parameters

  • textStyle IChartTextStyle — The text style for the chart y-axis.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The y-axis style is set.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setYAxisTextStyle({
    content: 'yAxis Title text',
    fontSize: 12,
    fontColor: '#ff0000'
  })
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setRightYAxisTextStyle

Sets the text style for the chart right y-axis. Only works in charts have right y-axis.

Signature

setRightYAxisTextStyle(textStyle: IChartTextStyle): this

Parameters

  • textStyle IChartTextStyle — The text style for the chart right y-axis.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The right y-axis style is set.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setRightYAxisTextStyle({
    content: 'rightYAxis Title text',
    fontSize: 12,
    fontColor: '#ff0000'
  })
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

FChartBuilderBase - Style & Pointer

setInvalidValueStrategy

Sets how to handle invalid data in the chart. The possible values are 'zero', 'break' & 'link'.

The default value is 'zero'. It means that invalid data will be treated as zero. 'break' means that the chart will have a gap where the invalid data is. 'link' means that the chart will connect the data points on either side of the invalid data.

Signature

setInvalidValueStrategy(invalidValueType: InvalidValueType): this

Parameters

  • invalidValueType InvalidValueType — The type of invalid value to use.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The invalid value is set as zero.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setInvalidValueStrategy('zero')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setAxisPointerStyle

Sets the axis pointer style.

Signature

setAxisPointerStyle(style: IChartBuildOptions['axisPointer']): this

Parameters

  • style IChartBuildOptions['axisPointer'] — The style for the axis pointer.
    • indicatorLabelColor string (optional) — The line color of the axis pointer.
    • indicatorLabelTextColor string (optional) — The font color of the axis pointer.
    • indicatorLineType string (optional) — The line type of the axis pointer.
    • indicatorLineColor ChartBorderDashType (optional) — The line width of the axis pointer.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The axis pointer style is set.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setAxisPointerStyle({
    indicatorLabelColor: '#ff0000',
    indicatorLineType: univerAPI.Enum.ChartBorderDashType.Solid,
    indicatorLineColor: '#00ff00',
    indicatorLabelTextColor: '#0000ff',
  })
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setAllSeriesStyle

Sets styles for all series.

Signature

setAllSeriesStyle(allSeriesStyle: Partial<IAllSeriesStyle>): this

Parameters

  • allSeriesStyle Partial<IAllSeriesStyle> — The style for all series.
    • chartType ChartTypeBits (optional) — The chart type of the series. It only works in combination chart, and the value must be one of ChartTypeBits.Line, ChartTypeBits.Column, or ChartTypeBits.Area.
    • rightYAxis boolean (optional) — Use the right y-axis for the series.
    • color string (optional) — The color of the series.
    • fillOpacity number (optional) — The opacity of the series fill.
    • border object (optional) — The border style of the series.
      • color string — The color of the series border.
      • opacity number — The opacity of the series border.
      • width number — The width of the series border.
      • dashType ChartBorderDashType — The dash type of the series border.
    • label ISeriesLabelStyle (optional) — The label style of the series.
    • point IPointStyle (optional) — The point style of the series.
    • dataPoints IDataPointStyle (optional) — The data point style of the series. Radar chart does not support this property.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The all series style is set.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setAllSeriesStyle({
    rightYAxis: false,
    color: '#ff0000',
    border: {
      color: '#00ff00',
      opacity: 0.5,
      width: 1,
      dashType: univerAPI.Enum.ChartBorderDashType.Solid,
    },
  })
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setSeriesStyle

Sets the series style by series index.

Signature

setSeriesStyle(index: number | string, seriesStyle: ISeriesStyle): this

Parameters

  • index number | string — The index of the series to set the style for.
  • seriesStyle ISeriesStyle — The style for the series.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .build();
const fChart = await fWorksheet.insertChart(chartInfo);

// Update the first series style after 3 seconds.
setTimeout(() => {
  const first = fChart.getSeriesData()[0];
  const newChartInfo = fWorksheet.newChart(fChart)
    .setSeriesStyle(first.index, {
      color: '#ff0000',
    })
    .build();
  fWorksheet.updateChart(newChartInfo);
}, 3000);
Source: @univerjs-pro/sheets-chart

FChartBuilderBase - Build

build

Builds the chart to reflect all changes made to it.

This method does not automatically draw the chart on top of the spreadsheet. A new chart must be inserted via sheet.insertChart(chart), and an existing chart should be updated via sheet.updateChart(chart).

Signature

build(): IChartBuilderInfo

Returns

  • IChartBuilderInfo — The chart builder info.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a column chart with data source A1:D6
// The starting position is upper-left corner of cell B2.
// The width of the chart is 600 and the height is 400.
const chartInfo = fWorksheet.newChart()
  .setChartType(univerAPI.Enum.ChartType.Column)
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setWidth(600)
  .setHeight(400)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

LineChartBuilder

setLineStyle

The line style of the line chart.

Signature

setLineStyle(lineStyle: AreaLineStyle): this

Parameters

  • lineStyle AreaLineStyle — The line style of the line chart.

Returns

  • this — The builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart builder with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The line style is set to the step type.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setLineStyle('step')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setDataPointShape

The shape of the data point in the line chart.

Signature

setDataPointShape(dataPointShape: LinePointShape): this

Parameters

  • dataPointShape LinePointShape — The shape of the data point in the line chart.

Returns

  • this — The builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The data point shape is set to circle, color is red, and size is 10.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setDataPointShape(univerAPI.Enum.LinePointShape.CIRCLE)
  .setDataPointColor('#ff0000')
  .setDataPointSize(10)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setDataPointColor

The color of the data point in the line chart.

Signature

setDataPointColor(dataPointColor: string): this

Parameters

  • dataPointColor string — The color of the data point in the line chart.

Returns

  • this — The builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The data point shape is set to circle, color is red, and size is 10.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setDataPointShape(univerAPI.Enum.LinePointShape.CIRCLE)
  .setDataPointColor('#ff0000')
  .setDataPointSize(10)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setDataPointSize

The size of the data point in the line chart.

Signature

setDataPointSize(dataPointSize: number): this

Parameters

  • dataPointSize number — The size of the data point in the line chart.

Returns

  • this — The builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The data point shape is set to circle, color is red, and size is 10.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setDataPointShape(univerAPI.Enum.LinePointShape.CIRCLE)
  .setDataPointColor('#ff0000')
  .setDataPointSize(10)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

build (LineChartBuilder)

Builds the chart to reflect all changes made to it.

This method does not automatically draw the chart on top of the spreadsheet. A new chart must be inserted via sheet.insertChart(chart), and an existing chart should be updated via sheet.updateChart(chart).

Signature

build(): IChartBuilderInfo

Returns

  • IChartBuilderInfo — The chart builder info.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a line chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The line style is set to the step type.
// The data point shape is set to circle, color is red, and size is 10.
const chartInfo = fWorksheet.newChart()
  .asLineChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setLineStyle('step')
  .setDataPointShape(univerAPI.Enum.LinePointShape.CIRCLE)
  .setDataPointColor('#ff0000')
  .setDataPointSize(10)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

PieChartBuilder

setDoughnutHole

Sets the size of the hole in the center of the pie chart as a percentage of the chart size. The value should be in the range 0-1.

Signature

setDoughnutHole(doughnutHole: number): this

Parameters

  • doughnutHole number — The size of the hole in the center of the pie chart as a percentage of the chart size.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The doughnut hole is set to 0.5.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setDoughnutHole(0.5)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setBorderColor

Sets the color of the border around the pie chart.

Signature

setBorderColor(borderColor: string): this

Parameters

  • borderColor string — The color of the border around the pie chart.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The border color is set to red.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setBorderColor('#ff0000')
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setHasPaddingAngle

Sets whether the pie chart has a padding angle.

Signature

setHasPaddingAngle(hasPaddingAngle: boolean): this

Parameters

  • hasPaddingAngle boolean — True if the pie chart has a padding angle; false otherwise.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The pie chart has a padding angle.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setHasPaddingAngle(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setIsHalfPie

Sets whether the pie chart is a half pie chart.

Signature

setIsHalfPie(isHalfPie: boolean): this

Parameters

  • isHalfPie boolean — True if the pie chart is a half pie chart; false otherwise.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The pie chart is a half pie chart.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setIsHalfPie(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setRosePie

Sets whether the pie chart is a rose pie chart.

Signature

setRosePie(rosePie: boolean): this

Parameters

  • rosePie boolean — True if the pie chart is a rose pie chart; false otherwise.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The pie chart is a rose pie chart.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setRosePie(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setShowLabelLine

Sets whether the pie chart shows label lines.

Signature

setShowLabelLine(showLabelLine: boolean): this

Parameters

  • showLabelLine boolean — True if the pie chart shows label lines; false otherwise.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The pie chart does not show label lines.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setShowLabelLine(false)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

build (PieChartBuilder)

Builds the chart to reflect all changes made to it.

This method does not automatically draw the chart on top of the spreadsheet. A new chart must be inserted via sheet.insertChart(chart), and an existing chart should be updated via sheet.updateChart(chart).

Signature

build(): IChartBuilderInfo

Returns

  • IChartBuilderInfo — The chart builder info.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a pie chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The doughnut hole is set to 0.5.
// The border color is set to red.
// The pie chart has a padding angle.
// The pie chart is a half pie chart.
const chartInfo = fWorksheet.newChart()
  .asPieChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setDoughnutHole(0.5)
  .setBorderColor('#ff0000')
  .setHasPaddingAngle(true)
  .setIsHalfPie(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

RadarChartBuilder

setShape

Sets the shape of the radar chart.

Signature

setShape(shape: RadarShape): this

Parameters

  • shape RadarShape — The shape of the radar chart.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a radar chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The shape of the radar chart is set to polygon and filled with red color.
const chartInfo = fWorksheet.newChart()
  .asRadarChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setShape(univerAPI.Enum.RadarShape.Polygon)
  .setFill(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

setFill

Sets whether the radar chart is filled.

Signature

setFill(fill: boolean): this

Parameters

  • fill boolean — True if the radar chart is filled; false otherwise.

Returns

  • this — This builder, for chaining.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a radar chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The shape of the radar chart is set to polygon and filled with red color.
const chartInfo = fWorksheet.newChart()
  .asRadarChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setShape(univerAPI.Enum.RadarShape.Polygon)
  .setFill(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart

build (RadarChartBuilder)

Builds the chart to reflect all changes made to it.

This method does not automatically draw the chart on top of the spreadsheet. A new chart must be inserted via sheet.insertChart(chart), and an existing chart should be updated via sheet.updateChart(chart).

Signature

build(): IChartBuilderInfo

Returns

  • IChartBuilderInfo — The chart builder info.

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a radar chart with data source A1:D6.
// The starting position is upper-left corner of cell B2.
// The shape of the radar chart is set to polygon and filled with red color.
const chartInfo = fWorksheet.newChart()
  .asRadarChart()
  .addRange('A1:D6')
  .setPosition(1, 1, 0, 0)
  .setShape(univerAPI.Enum.RadarShape.Polygon)
  .setFill(true)
  .build();
await fWorksheet.insertChart(chartInfo);
Source: @univerjs-pro/sheets-chart