FWorksheetSparklineMixin

GitHubEdit on GitHub
packages@univerjs-pro/sheets-sparkline

APIs

addSparkline

Signature

addSparkline(sourceRanges: IRange[], targetRanges: IRange[], type: SparklineTypeEnum.LINE_CHART): FSparkline | undefined

Parameters

  • sourceRanges (IRange[]) — Source data location for sparklines
  • targetRanges (IRange[]) — Where to place sparklines
  • type (SparklineTypeEnum.LINE_CHART) — The type of Sparklines

Returns

  • (FSparkline | undefined) — Returns the sparkline instance for the next call

Tags

  • @description — Add sparkline to the worksheet.

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()

// Create a sparkline in the range A10, with the data source in the range A1:A7.
const sourceRanges = [fWorksheet.getRange('A1:A7').getRange()]
const targetRanges = [fWorksheet.getRange('A10').getRange()]
const sparkline = fWorksheet.addSparkline(sourceRanges, targetRanges, univerAPI.Enum.SparklineTypeEnum.LINE_CHART)
console.log('sparkline instance', sparkline)

composeSparkline

Signature

composeSparkline(ranges: IRange[]): void

Parameters

  • ranges (IRange[]) — - The selection range to be grouped

Returns

Tags

  • @description — Group the sparklines in the selection into a new sparkline group

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()

// Create a sparkline in the range A10, with the data source in the range A1:A7.
const firstSparkline = fWorksheet.addSparkline(
  [fWorksheet.getRange('A1:A7').getRange()],
  [fWorksheet.getRange('A10').getRange()],
)
// Create a sparkline in the range B10, with the data source in the range B1:B7.
const secondSparkline = fWorksheet.addSparkline(
  [fWorksheet.getRange('B1:B7').getRange()],
  [fWorksheet.getRange('B10').getRange()],
)
console.log('debugger', fWorksheet.getAllSubSparkline().size) // 2

// Compose the two sparklines into one group after 3 seconds
setTimeout(() => {
  fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()])
  console.log('debugger', fWorksheet.getAllSubSparkline().size) // 1
}, 3000)

getAllSubSparkline

Signature

getAllSubSparkline(): Map<string, ISparklineGroup> | undefined

Returns

  • (Map<string, ISparklineGroup> | undefined) — - The key is sparkline group id.

Tags

  • @description — Get all sparklines in the worksheet.

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()

// Get all sparklines in the current worksheet
const allSparkline = fWorksheet.getAllSubSparkline()
console.log('allSparkline', allSparkline)

getSparklineByCell

Signature

getSparklineByCell(row: number, col: number): FSparkline | undefined

Parameters

  • row (number) — - The row index of the cell, start at 0.
  • col (number) — - The column index of the cell, start at 0.

Returns

  • (FSparkline | undefined) — Returns the sparkline instance for the next call

Tags

  • @description — Get the sparkline instance of the current cell

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()

// Create a sparkline in the range A10, with the data source in the range A1:A7.
const sourceRanges = [fWorksheet.getRange('A1:A7').getRange()]
const targetRanges = [fWorksheet.getRange('A10').getRange()]
const sparkline = fWorksheet.addSparkline(sourceRanges, targetRanges)

console.log('Cell A10: ', fWorksheet.getSparklineByCell(9, 0))
console.log('Cell A11: ', fWorksheet.getSparklineByCell(10, 0))

getSparklineGroupByCell

Signature

getSparklineGroupByCell(row: number, col: number): FSparklineGroup | undefined

Parameters

  • row (number) — - The row index of the cell, start at 0.
  • col (number) — - The column index of the cell, start at 0.

Returns

  • (FSparklineGroup | undefined) — Returns the sparkline group instance for the next call

Tags

  • @description — Get the sparkline groups instance of the current cell

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()

// Create a sparkline in the range A10, with the data source in the range A1:A7.
const firstSparkline = fWorksheet.addSparkline(
  [fWorksheet.getRange('A1:A7').getRange()],
  [fWorksheet.getRange('A10').getRange()],
)
// Create a sparkline in the range B10, with the data source in the range B1:B7.
const secondSparkline = fWorksheet.addSparkline(
  [fWorksheet.getRange('B1:B7').getRange()],
  [fWorksheet.getRange('B10').getRange()],
)
console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0))

// Compose the two sparklines into one group after 3 seconds
setTimeout(() => {
  fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()])
  console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0))
}, 3000)

unComposeSparkline

Signature

unComposeSparkline(ranges: IRange[]): void

Parameters

  • ranges (IRange[]) — - The selection range to be ungrouped

Tags

  • @description — Split the sparkline group within the current selection

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()

// Create a sparkline in the range A10, with the data source in the range A1:A7.
const firstSparkline = fWorksheet.addSparkline(
  [fWorksheet.getRange('A1:A7').getRange()],
  [fWorksheet.getRange('A10').getRange()],
)
// Create a sparkline in the range B10, with the data source in the range B1:B7.
const secondSparkline = fWorksheet.addSparkline(
  [fWorksheet.getRange('B1:B7').getRange()],
  [fWorksheet.getRange('B10').getRange()],
)

// Compose the two sparklines into one group
fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()])
console.log('debugger', fWorksheet.getAllSubSparkline().size) // 1

// Uncompose the sparkline group after 3 seconds
setTimeout(() => {
  fWorksheet.unComposeSparkline([fWorksheet.getRange('A10:B10').getRange()])
  console.log('debugger', fWorksheet.getAllSubSparkline().size) // 2
}, 3000)