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

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

APIs

Data

getCategoryData

Get the category data of the chart.

Signature

getCategoryData(): IChartDataCategory | undefined

Returns

  • IChartDataCategory — 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

  • any — 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[] — 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