FChart
| packages | @univerjs-pro/sheets-chart-ui |
|---|
The facade class for the chart.
APIs
getCategoryData
Get the category data of the chart.
Signature
getCategoryData(): IChartDataCategory | undefinedReturns
- (
IChartDataCategory | undefined) — The category data of the chart.
Tags
@type@property— {string} name The name of the category.@property— {number} index The index of the category.@property— {CategoryType} type The type of the category.@property— {string[]} keys The keys of the category.@property— {IChartDataItem[]} items The data of the category.@property— {number} items.value The value of the category.@property— {string} items.label The label of the category.
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)
}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())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())getSeriesData
Get the series data list of the chart.
Signature
getSeriesData(): IChartDataSeries[] | undefinedReturns
- (
IChartDataSeries[] | undefined) — The series data list of the chart.
Tags
@typedef
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)
}modify
Returns a new FChartBuilderBase instance that modifies this chart.
Signature
modify(): FChartBuilderBaseReturns
- (
FChartBuilderBase) — The new FChartBuilderBase instance.
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(ISheetChartSourceSingleRange) — The new range of the chart.rangeInfo.range.range— The new range of the chart.rangeInfo.range.subUnitId— The new sheet id of the chart.rangeInfo.range.unitId— The new workbook id of the chart.rangeInfo.isRowDirection— Is treat row as category.
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)
}