Skip to Content
ClassesPieChartBuilder

Class: PieChartBuilder

The builder for creating a pie chart.

Extends

  • FChartBuilderBase

Properties

PropertyType

borderColor

string

doughnutHole

number

hasPaddingAngle

boolean

isHalfPie

boolean

rosePie

boolean

showLabelLine

boolean

Methods

build()

build(): IChartBuilderInfo

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

Overrides

FChartBuilderBase.build

setBorderColor()

setBorderColor(borderColor): this

Sets the color of the border around the pie chart.

Parameters

ParameterTypeDescription
borderColorstringThe color of the border around the pie chart.

Returns

this

this builder, for chaining.

Example

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

setDoughnutHole()

setDoughnutHole(doughnutHole): this

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.

Parameters

ParameterTypeDescription
doughnutHolenumberThe size of the hole in the center of the pie chart as a percentage of the chart size.

Returns

this

this builder, for chaining.

Example

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

setHasPaddingAngle()

setHasPaddingAngle(hasPaddingAngle): this

Sets whether the pie chart has a padding angle.

Parameters

ParameterTypeDescription
hasPaddingAnglebooleanTrue if the pie chart has a padding angle; false otherwise.

Returns

this

this builder, for chaining.

Example

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

setIsHalfPie()

setIsHalfPie(isHalfPie): this

Sets whether the pie chart is a half pie chart.

Parameters

ParameterTypeDescription
isHalfPiebooleanTrue if the pie chart is a half pie chart; false otherwise.

Returns

this

this builder, for chaining.

Example

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

setRosePie()

setRosePie(rosePie): this

Sets whether the pie chart is a rose pie chart.

Parameters

ParameterTypeDescription
rosePiebooleanTrue if the pie chart is a rose pie chart; false otherwise.

Returns

this

this builder, for chaining.

Example

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

setShowLabelLine()

setShowLabelLine(showLabelLine): this

Sets whether the pie chart shows label lines.

Parameters

ParameterTypeDescription
showLabelLinebooleanTrue if the pie chart shows label lines; false otherwise.

Returns

this

this builder, for chaining.

Example

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