Skip to Content
ClassesPieChartBuilder

类: PieChartBuilder

The builder for creating a pie chart.

继承

  • FChartBuilderBase

属性

属性类型

borderColor

string

doughnutHole

number

hasPaddingAngle

boolean

isHalfPie

boolean

rosePie

boolean

showLabelLine

boolean

方法

build()

build(): IChartBuilderInfo;

Builds the chart to reflect all changes made to it.

返回

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

示例

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

重写了

FChartBuilderBase.build

setBorderColor()

setBorderColor(borderColor): this;

Sets the color of the border around the pie chart.

参数

参数类型描述
borderColorstringThe color of the border around the pie chart.

返回

this

this builder, for chaining.

示例

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.

参数

参数类型描述
doughnutHolenumberThe size of the hole in the center of the pie chart as a percentage of the chart size.

返回

this

this builder, for chaining.

示例

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.

参数

参数类型描述
hasPaddingAnglebooleanTrue if the pie chart has a padding angle; false otherwise.

返回

this

this builder, for chaining.

示例

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.

参数

参数类型描述
isHalfPiebooleanTrue if the pie chart is a half pie chart; false otherwise.

返回

this

this builder, for chaining.

示例

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.

参数

参数类型描述
rosePiebooleanTrue if the pie chart is a rose pie chart; false otherwise.

返回

this

this builder, for chaining.

示例

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.

参数

参数类型描述
showLabelLinebooleanTrue if the pie chart shows label lines; false otherwise.

返回

this

this builder, for chaining.

示例

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