Chart
| Packages | @univerjs-pro/sheets-chart |
|---|
The facade class for the chart.
This class should not be instantiated directly. Use factory methods on
univerAPIinstead.
Overview
@univerjs-pro/sheets-chart (FChart)
| Method | Description |
|---|---|
chartId | - |
getCategoryData | Get the category data of the chart |
getChartId | Get the chart id |
getRange | Get the range of the chart |
getSeriesData | Get the series data list of the chart |
modify | Returns a new FChartBuilderBase instance that modifies this chart |
subUnitId | - |
unitId | - |
updateRange | Update the range info of the chart |
@univerjs-pro/sheets-chart (FChartBuilderBase)
| Method | Description |
|---|---|
addRange | Adds a range to the chart this builder modifies |
asLineChart | Returns a LineChartBuilder instance |
asPieChart | Returns a PieChartBuilder instance |
asRadarChart | Returns a RadarChartBuilder instance |
build | Builds the chart to reflect all changes made to it |
clearRange | Clears the range from the chart this builder modifies |
getChartType | Gets the chart type of the chart this builder modifies |
setAbsolutePosition | Sets the position by pixel |
setAllSeriesStyle | Sets styles for all series |
setAxisPointerStyle | Sets the axis pointer style |
setChartType | The type of chart to create |
setHeight | Sets the height of the chart in pixels |
setInvalidValueStrategy | Sets how to handle invalid data in the chart |
setOptions | The options for the chart |
setPosition | Sets the position |
setRightYAxisTextStyle | Sets the text style for the chart right y-axis |
setRightYAxisTitle | Sets the title of the chart right y-axis |
setSeriesStyle | Sets the series style by series index |
setTheme | Sets the theme of the chart |
setTransposeRowsAndColumns | Sets whether to transpose the rows and columns |
setWidth | Sets the width of the chart in pixels |
setXAxisTextStyle | Sets the text style for the chart x-axis |
setXAxisTitle | Sets the title of the chart x-axis |
setYAxisTextStyle | Sets the text style for the chart y-axis |
setYAxisTitle | Sets the title of the chart y-axis |
@univerjs-pro/sheets-chart (LineChartBuilder)
| Method | Description |
|---|---|
setDataPointColor | The color of the data point in the line chart |
setDataPointShape | The shape of the data point in the line chart |
setDataPointSize | The size of the data point in the line chart |
setLineStyle | The line style of the line chart |
build | Builds the chart to reflect all changes made to it |
@univerjs-pro/sheets-chart (PieChartBuilder)
| Method | Description |
|---|---|
setBorderColor | Sets the color of the border around the pie chart |
setDoughnutHole | Sets the size of the hole in the center of the pie chart |
setHasPaddingAngle | Sets whether the pie chart has a padding angle |
setIsHalfPie | Sets whether the pie chart is a half pie chart |
setRosePie | Sets whether the pie chart is a rose pie chart |
setShowLabelLine | Sets whether the pie chart shows label lines |
build | Builds the chart to reflect all changes made to it |
@univerjs-pro/sheets-chart (RadarChartBuilder)
| Method | Description |
|---|---|
setFill | Sets whether the radar chart is filled |
setShape | Sets the shape of the radar chart |
build | Builds the chart to reflect all changes made to it |
APIs
Data
getCategoryData
Get the category data of the chart.
Signature
getCategoryData(): IChartDataCategory | undefinedReturns
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);
}@univerjs-pro/sheets-chart
getRange
Get the range of the chart.
Signature
getRange(): ISheetChartSourceSingleRange | undefinedReturns
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());@univerjs-pro/sheets-chart
getSeriesData
Get the series data list of the chart.
Signature
getSeriesData(): IChartDataSeries[] | undefinedReturns
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);
}@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
rangeInfoISheetChartSourceSingleRange— No 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);
}@univerjs-pro/sheets-chart
Modification
modify
Returns a new FChartBuilderBase instance that modifies this chart.
Signature
modify(): FChartBuilderBaseReturns
FChartBuilderBase— The new FChartBuilderBase instance.
@univerjs-pro/sheets-chart
Miscellaneous
chartId
Signature
chartId: stringReturns
string— See signature above.
@univerjs-pro/sheets-chart
getChartId
Get the chart id.
Signature
getChartId(): stringReturns
string— The chart id.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const charts = fWorksheet.getCharts();
console.log(charts[0]?.getChartId());@univerjs-pro/sheets-chart
subUnitId
Signature
subUnitId: stringReturns
string— See signature above.
@univerjs-pro/sheets-chart
unitId
Signature
unitId: stringReturns
string— See signature above.
@univerjs-pro/sheets-chart
FChartBuilderBase - Range & Position
addRange
Adds a range to the chart this builder modifies.
Signature
addRange(range: IRange | string): thisParameters
rangeIRange | 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);@univerjs-pro/sheets-chart
clearRange
Clears the range from the chart this builder modifies.
Signature
clearRange(): thisReturns
this— This builder, for chaining.
@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): thisParameters
anchorRowPosnumber— The chart's top side is anchored in this row.anchorColPosnumber— The chart's left side is anchored in this column.rowOffsetnumber— The chart's top left-hand corner is offset by this many pixels.columnOffsetnumber— 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);@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): thisParameters
xnumber— The x-coordinate of the chart's top left-hand corner.ynumber— 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);@univerjs-pro/sheets-chart
FChartBuilderBase - Chart Type & Size
getChartType
Gets the chart type of the chart this builder modifies.
Signature
getChartType(): ChartTypeBitsReturns
ChartTypeBits— The chart type of the chart this builder modifies.
@univerjs-pro/sheets-chart
asLineChart
Returns a LineChartBuilder instance for creating a line chart.
Signature
asLineChart(): LineChartBuilderReturns
LineChartBuilder— The LineChartBuilder instance.
@univerjs-pro/sheets-chart
asPieChart
Returns a PieChartBuilder instance for creating a pie chart.
Signature
asPieChart(): PieChartBuilderReturns
PieChartBuilder— The PieChartBuilder instance.
@univerjs-pro/sheets-chart
asRadarChart
Returns a RadarChartBuilder instance for creating a radar chart.
Signature
asRadarChart(): RadarChartBuilderReturns
RadarChartBuilder— The RadarChartBuilder instance.
@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): thisParameters
chartTypeChartTypeBits— 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);@univerjs-pro/sheets-chart
setWidth
Sets the width of the chart in pixels.
Signature
setWidth(width: number): thisParameters
widthnumber— 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);@univerjs-pro/sheets-chart
setHeight
Sets the height of the chart in pixels.
Signature
setHeight(height: number): thisParameters
heightnumber— 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);@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): thisParameters
optionPathstring— The path of the option to set. A '' path means the root of the options object.optionValunknown— 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);@univerjs-pro/sheets-chart
setTransposeRowsAndColumns
Sets whether to transpose the rows and columns of the chart.
Signature
setTransposeRowsAndColumns(transposeRowsAndColumns: boolean): thisParameters
transposeRowsAndColumnsboolean— 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);@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): thisParameters
themestring— 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);@univerjs-pro/sheets-chart
FChartBuilderBase - Axis & Title
setXAxisTitle
Sets the title of the chart x-axis.
Signature
setXAxisTitle(title: string): thisParameters
titlestring— 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);@univerjs-pro/sheets-chart
setYAxisTitle
Sets the title of the chart y-axis.
Signature
setYAxisTitle(title: string): thisParameters
titlestring— 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);@univerjs-pro/sheets-chart
setRightYAxisTitle
Sets the title of the chart right y-axis.
Signature
setRightYAxisTitle(title: string): thisParameters
titlestring— 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);@univerjs-pro/sheets-chart
setXAxisTextStyle
Sets the text style for the chart x-axis.
Signature
setXAxisTextStyle(textStyle: IChartTextStyle): thisParameters
textStyleIChartTextStyle— 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);@univerjs-pro/sheets-chart
setYAxisTextStyle
Sets the text style for the chart y-axis.
Signature
setYAxisTextStyle(textStyle: IChartTextStyle): thisParameters
textStyleIChartTextStyle— 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);@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): thisParameters
textStyleIChartTextStyle— 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);@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): thisParameters
invalidValueTypeInvalidValueType— 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);@univerjs-pro/sheets-chart
setAxisPointerStyle
Sets the axis pointer style.
Signature
setAxisPointerStyle(style: IChartBuildOptions['axisPointer']): thisParameters
styleIChartBuildOptions['axisPointer']— The style for the axis pointer.indicatorLabelColorstring(optional) — The line color of the axis pointer.indicatorLabelTextColorstring(optional) — The font color of the axis pointer.indicatorLineTypestring(optional) — The line type of the axis pointer.indicatorLineColorChartBorderDashType(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);@univerjs-pro/sheets-chart
setAllSeriesStyle
Sets styles for all series.
Signature
setAllSeriesStyle(allSeriesStyle: Partial<IAllSeriesStyle>): thisParameters
allSeriesStylePartial<IAllSeriesStyle>— The style for all series.chartTypeChartTypeBits(optional) — The chart type of the series. It only works in combination chart, and the value must be one ofChartTypeBits.Line,ChartTypeBits.Column, orChartTypeBits.Area.rightYAxisboolean(optional) — Use the right y-axis for the series.colorstring(optional) — The color of the series.fillOpacitynumber(optional) — The opacity of the series fill.borderobject(optional) — The border style of the series.colorstring— The color of the series border.opacitynumber— The opacity of the series border.widthnumber— The width of the series border.dashTypeChartBorderDashType— The dash type of the series border.
labelISeriesLabelStyle(optional) — The label style of the series.pointIPointStyle(optional) — The point style of the series.dataPointsIDataPointStyle(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);@univerjs-pro/sheets-chart
setSeriesStyle
Sets the series style by series index.
Signature
setSeriesStyle(index: number | string, seriesStyle: ISeriesStyle): thisParameters
indexnumber | string— The index of the series to set the style for.seriesStyleISeriesStyle— 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);@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(): IChartBuilderInfoReturns
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);@univerjs-pro/sheets-chart
LineChartBuilder
setLineStyle
The line style of the line chart.
Signature
setLineStyle(lineStyle: AreaLineStyle): thisParameters
lineStyleAreaLineStyle— 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);@univerjs-pro/sheets-chart
setDataPointShape
The shape of the data point in the line chart.
Signature
setDataPointShape(dataPointShape: LinePointShape): thisParameters
dataPointShapeLinePointShape— 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);@univerjs-pro/sheets-chart
setDataPointColor
The color of the data point in the line chart.
Signature
setDataPointColor(dataPointColor: string): thisParameters
dataPointColorstring— 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);@univerjs-pro/sheets-chart
setDataPointSize
The size of the data point in the line chart.
Signature
setDataPointSize(dataPointSize: number): thisParameters
dataPointSizenumber— 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);@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(): IChartBuilderInfoReturns
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);@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): thisParameters
doughnutHolenumber— 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);@univerjs-pro/sheets-chart
setBorderColor
Sets the color of the border around the pie chart.
Signature
setBorderColor(borderColor: string): thisParameters
borderColorstring— 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);@univerjs-pro/sheets-chart
setHasPaddingAngle
Sets whether the pie chart has a padding angle.
Signature
setHasPaddingAngle(hasPaddingAngle: boolean): thisParameters
hasPaddingAngleboolean— 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);@univerjs-pro/sheets-chart
setIsHalfPie
Sets whether the pie chart is a half pie chart.
Signature
setIsHalfPie(isHalfPie: boolean): thisParameters
isHalfPieboolean— 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);@univerjs-pro/sheets-chart
setRosePie
Sets whether the pie chart is a rose pie chart.
Signature
setRosePie(rosePie: boolean): thisParameters
rosePieboolean— 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);@univerjs-pro/sheets-chart
setShowLabelLine
Sets whether the pie chart shows label lines.
Signature
setShowLabelLine(showLabelLine: boolean): thisParameters
showLabelLineboolean— 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);@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(): IChartBuilderInfoReturns
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);@univerjs-pro/sheets-chart
RadarChartBuilder
setShape
Sets the shape of the radar chart.
Signature
setShape(shape: RadarShape): thisParameters
shapeRadarShape— 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);@univerjs-pro/sheets-chart
setFill
Sets whether the radar chart is filled.
Signature
setFill(fill: boolean): thisParameters
fillboolean— 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);@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(): IChartBuilderInfoReturns
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);@univerjs-pro/sheets-chart