@univerjs-pro/sheets-chart-ui v0.5.4


Class: FChartBuilderBase

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:177

FBase is a base class for all facade classes. It provides a way to extend classes with static and instance methods. The _initialize as a special method that will be called after the constructor. You should never call it directly.

Extends

  • FBase.IPieChartBuilderMixin.IRadarChartBuilderMixin.ILineChartBuilderMixin

Extended by

Constructors

new FChartBuilderBase()

new FChartBuilderBase(
   unitId, 
   subUnitId, 
   workbook, 
   injector, 
   chartId?): FChartBuilderBase

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:196

Parameters

ParameterType
unitIdstring
subUnitIdstring
workbookWorkbook
injectorInjector
chartId?string

Returns

FChartBuilderBase

Overrides

FBase.constructor

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_disposedprotectedbooleanfalseFBase._disposedsubmodules/univer/packages/core/src/shared/lifecycle.ts:96
_injectorreadonlyInjectorundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:179
_workbookreadonlyWorkbookundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:178
chartIdpublicstringundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:183
chartTypepublicChartTypeBitsundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:192
heightpublicnumberundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:191
optionspublicIChartBuildOptionsundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:193
rangepublicundefined | IRangeundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:185
sourceSheetNamepublicundefined | stringundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:186
subUnitIdpublicstringundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:182
transposeRowsAndColumnspublicbooleanundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:194
unitIdpublicstringundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:181
widthpublicnumberundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:190
xpublicnumberundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:188
ypublicnumberundefined-packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:189

Methods

addRange()

addRange(range): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:246

Adds a range to the chart this builder modifies

Parameters

ParameterTypeDescription
rangestring | IRangeThe range string or object to add for chart source data.The should be not a single cell.

Returns

this

-this builder, for chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder
// set the source data range of the chart
.addRange('A1:D6')
.setChartType(ChartTypeBits.Column)
.setPosition(1, 1, 0, 0)
.build();
fSheet.insertChart(chartInfo);

asLineChart()

asLineChart(): LineChartBuilder

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/types.ts:14

Returns

LineChartBuilder


asPieChart()

asPieChart(): PieChartBuilder

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/types.ts:6

Returns

PieChartBuilder


asRadarChart()

asRadarChart(): RadarChartBuilder

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/types.ts:10

Returns

RadarChartBuilder


build()

build(): IChartBuilderInfo

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:785

Builds the chart to reflect all changes made to it.

Returns

IChartBuilderInfo

-The chart builder info.

Description

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).

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
   .setChartType(ChartTypeBits.Column)
   .setPosition(1, 1, 0, 0)
   .setWidth(600)
   .setHeight(400)
   .build();
fSheet.insertChart(chartInfo);

clearRange()

clearRange(): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:263

Clears the range from the chart this builder modifies

Returns

this

-this builder, for chaining


dispose()

dispose(): void

Defined in: submodules/univer/packages/core/src/shared/lifecycle.ts:109

Returns

void

Inherited from

FBase.dispose


disposeWithMe()

disposeWithMe(disposable): IDisposable

Defined in: submodules/univer/packages/core/src/shared/lifecycle.ts:99

Parameters

ParameterType
disposableDisposableLike

Returns

IDisposable

Inherited from

FBase.disposeWithMe


ensureNotDisposed()

protected ensureNotDisposed(): void

Defined in: submodules/univer/packages/core/src/shared/lifecycle.ts:103

Returns

void

Inherited from

FBase.ensureNotDisposed


getChartType()

getChartType(): ChartTypeBits

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:224

Gets the chart type of the chart this builder modifies.

Returns

ChartTypeBits

ChartType - The chart type of the chart this builder modifies.

Description

The chart type of the chart this builder modifies. The chart type (ChartTypeBits) can be found from package @univerjs-pro/sheets-chart. Please pay attention to the type of the chart you are creating, a Pie chart have a property of Doughnut is donut chart, and a Pie chart have a property of Rose is rose pie chart.But the chart builder will not change the chart type to the corresponding chart type.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const charts = fSheet.getCharts();
if(charts.length > 0) {
 const chart = charts[0];
 const chartBuilder = chart.getChartBuilder();
 const chartType = chartBuilder.getChartType();
 console.log(chartType); // The chart type of first chart.
}
 
***
 
### setAbsolutePosition()
 
```ts
setAbsolutePosition(x, y): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:331

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

Parameters

ParameterTypeDescription
xnumberThe x-coordinate of the chart’s top left-hand corner.
ynumberThe y-coordinate of the chart’s top left-hand corner.

Returns

this

-this builder, for chaining.

Description

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

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
.setChartType(ChartTypeBits.Column)
// set the chart's top left-hand corner is at (100, 200) pixels.
.setAbsolutePosition(100, 200)
.build();
fSheet.insertChart(chartInfo);

setAllSeriesStyle()

setAllSeriesStyle(allSeriesStyle): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:727

Sets styles for all series.

Parameters

ParameterTypeDescription
allSeriesStylePartial<IAllSeriesStyle>The style for all series.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
   .setChartType(ChartTypeBits.Line)
   .setPosition(1, 1, 0, 0)
   .setALLSeriesStyle({
     chartType: ChartTypeBits.Line,
     rightYAxis: false,
     color: '#ff0000',
     fillOpacity: 0.5,
     border: {
         color: '#00ff00',
         opacity: 0.5,
         width: 1,
         dashType: ChartBorderDashType.Solid,
      })
   .build();
fSheet.insertChart(chartInfo);

setAxisPointerStyle()

setAxisPointerStyle(style): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:682

Sets the axis pointer style

Parameters

ParameterTypeDescription
style| undefined | { indicatorLabelColor: string; indicatorLabelTextColor: string; indicatorLineColor: ChartBorderDashType; indicatorLineType: string; }The style for the axis pointer.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
 .setChartType(ChartTypeBits.Line)
 .setPosition(1, 1, 0, 0)
 .setAxisPointerStyle({
     indicatorLabelColor: '#ff0000',
     indicatorLineType: ChartBorderDashType.Solid,
     indicatorLineColor: '#00ff00',
     indicatorLabelTextColor: '#0000ff',
 })
 .build();
fSheet.insertChart(chartInfo);
 
// a AxisPointerStyle can be defined like following:
 const chartInfo = chartBuilder.setOptions('axisPointer.indicatorLineColor', '#ff0000')
.setOptions('axisPointer.indicatorLineType', ChartBorderDashType.Solid)
.setOptions('axisPointer.indicatorLineColor', '#00ff00')
.setOptions('axisPointer.indicatorLabelTextColor', '#0000ff')
.build();

setChartType()

setChartType(chartType): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:358

The type of chart to create.

Parameters

ParameterTypeDescription
chartTypeChartTypeBitsThe type of chart to create.Which can be found from package @univerjs-pro/sheets-chart.

Returns

this

-this builder, for chaining.

Description

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

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
  .setChartType(ChartTypeBits.Column)
  .setPosition(1, 1, 0, 0)
  .build();
fSheet.insertChart(chartInfo);
// update chart type to line
const updateBuilder = fSheet.newChart();
const updateChartInfo = updateBuilder.setChartType(ChartTypeBits.Line).build();
fSheet.updateChart(updateChartInfo);

setHeight()

setHeight(height): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:378

Sets the height of the chart in pixels.

Parameters

ParameterTypeDescription
heightnumberThe height of the chart in pixels.

Returns

this

-this builder, for chaining.


setInvalidValueStrategy()

setInvalidValueStrategy(invalidValueType): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:643

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

Parameters

ParameterTypeDescription
invalidValueTypeInvalidValueTypeThe type of invalid value to use.

Returns

this

-this builder, for chaining.

Description

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.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
.setChartType(ChartTypeBits.Line)
.setPosition(1, 1, 0, 0)
.setInvalidValueAs(InvalidValueType.Zero)
.build();
fSheet.insertChart(chartInfo);

setOptions()

setOptions(optionPath, optionVal): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:425

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

Parameters

ParameterTypeDescription
optionPathstringThe path of the option to set. A ” path means the root of the options object.
optionValunknownThe value to set. Undefined value will be ignore , and null means delete the property.If a path is ”, the value must be the whole options object.

Returns

this

The builder, for chaining.

Example

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();
fWorkSheet.insertChart(chartBuilderInfo1);
// or they are same effect
// fWorkSheet.insertChart(chartBuilderInfo2);

setPosition()

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

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:290

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.

Parameters

ParameterTypeDescription
anchorRowPosnumberThe chart’s top side is anchored in this row.
anchorColPosnumberThe chart’s left side is anchored in this column.
rowOffsetnumberThe chart’s top left-hand corner is offset by this many pixels.
columnOffsetnumberThe chart’s lower left-hand corner is offset by this many pixels.

Returns

this

-this builder, for chaining

Description

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.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
 .setChartType(ChartTypeBits.Column)
 // set the chart's top side is anchored in row 2, left side is anchored in column 5, and the chart's top left-hand corner is offset by 20 pixels.
 .setPosition(2, 5, 20, 20)
 .build();
fSheet.insertChart(chartInfo);

setRightYAxisTextStyle()

setRightYAxisTextStyle(textStyle): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:619

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

Parameters

ParameterTypeDescription
textStyleIChartTextStyleThe text style for the chart right y-axis.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
.setChartType(ChartTypeBits.Line)
.setPosition(1, 1, 0, 0)
.setRightYAxisTextStyle({ content: 'rightYAxis Title text', fontSize: 12, fontColor: '#ff0000' })
.build();
fSheet.insertChart(chartInfo);

setRightYAxisTitle()

setRightYAxisTitle(title): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:549

Sets the title of the chart right y-axis.

Parameters

ParameterTypeDescription
titlestringThe title of the chart right y-axis.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
.setChartType(ChartTypeBits.Line)
.setPosition(1, 1, 0, 0)
.setRightYAxisTitle('rightYAxis Title text')
.build();
fSheet.insertChart(chartInfo);

setSeriesStyle()

setSeriesStyle(index, seriesStyle): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:760

Sets the series style by series index.

Parameters

ParameterTypeDescription
indexstring | numberThe index of the series to set the style for.
seriesStyleISeriesStyleThe style for the series.

Returns

this

-this builder, for chaining.

Description

Like setALLSeriesStyle, this difference is the style only set for the provide sty

Example

 const fWorkbook = univerAPI.getActiveWorkbook();
 const fSheet = fWorkbook.getActiveSheet();
 const chartBuilder = fSheet.newChart();
 const chartInfo = chartBuilder.addRange('A1:D6').setChartType(2).setPosition(1, 1, 0, 0).build();
 const fChart = await fSheet.insertChart(chartInfo);
 // should wait the chart rendered
 setTimeout( () => {
     if (fChart) {
         const chartBuilder = fSheet.newChart(fChart);
         // get the series data
         const first = fChart.getSeriesData()[0];
         chartBuilder.setSeriesStyle(first.index, {
             color: '#ff0000',
         }).build();
         fSheet.updateChart(chartBuilder);
     }
 }
 , 1000);

setTheme()

setTheme(theme): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:479

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

Parameters

ParameterTypeDescription
themestringThe theme name of the chart.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
 .setChartType(ChartTypeBits.Column)
 .setPosition(1, 1, 0, 0)
 .setTheme('univer1')
 .build();
fSheet.insertChart(chartInfo);

setTransposeRowsAndColumns()

setTransposeRowsAndColumns(transposeRowsAndColumns): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:457

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

Parameters

ParameterTypeDescription
transposeRowsAndColumnsbooleanWhether to transpose the rows and columns of the chart.The default value is false.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
.setChartType(ChartTypeBits.Column)
.setPosition(1, 1, 0, 0)
// the chart will transpose the rows and columns
.setTransposeRowsAndColumns(true)
.build();
fSheet.insertChart(chartInfo);

setWidth()

setWidth(width): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:368

Sets the width of the chart in pixels.

Parameters

ParameterTypeDescription
widthnumberThe width of the chart in pixels.

Returns

this

-this builder, for chaining.


setXAxisTextStyle()

setXAxisTextStyle(textStyle): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:573

Sets the text style for the chart x-axis.

Parameters

ParameterTypeDescription
textStyleIChartTextStyleThe text style for the chart x-axis.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
 .setChartType(ChartTypeBits.Column)
.setPosition(1, 1, 0, 0)
.setXAxisTextStyle({ content: 'xAxis Title text', fontSize: 12, fontColor: '#ff0000' })
.build();
fSheet.insertChart(chartInfo);

setXAxisTitle()

setXAxisTitle(title): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:501

Sets the title of the chart x-axis.

Parameters

ParameterTypeDescription
titlestringThe title of the chart x-axis.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
  .setChartType(ChartTypeBits.Column)
  .setPosition(1, 1, 0, 0)
  .setXAxisTitle('xAxis Title text')
  .build();
fSheet.insertChart(chartInfo);

setYAxisTextStyle()

setYAxisTextStyle(textStyle): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:596

Sets the text style for the chart y-axis.

Parameters

ParameterTypeDescription
textStyleIChartTextStyleThe text style for the chart y-axis.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
.setChartType(ChartTypeBits.Line)
.setPosition(1, 1, 0, 0)
.setYAxisTextStyle({ content: 'yAxis Title text', fontSize: 12, fontColor: '#ff0000' })
.build();
fSheet.insertChart(chartInfo);

setYAxisTitle()

setYAxisTitle(title): this

Defined in: packages/sheets-chart-ui/src/facade/chart-builder/chart-builder-base.ts:525

Sets the title of the chart y-axis.

Parameters

ParameterTypeDescription
titlestringThe title of the chart y-axis.

Returns

this

-this builder, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fSheet = fWorkbook.getActiveSheet();
const chartBuilder = fSheet.newChart();
const chartInfo = chartBuilder.addRange('A1:D6')
 .setChartType(ChartTypeBits.Line)
 .setPosition(1, 1, 0, 0)
 .setYAxisTitle('yAxis Title text')
 .build();
fSheet.insertChart(chartInfo);

extend()

static extend(source): void

Defined in: submodules/univer/packages/core/src/facade/f-base.ts:26

Parameters

ParameterType
sourceany

Returns

void

Inherited from

FBase.extend