FScatterChartBuilder
Fluent, type-specific Builder for Scatter Charts.
Scatter uses the ordinary Cartesian category/value mapping. Select the optional X-axis
field with setCategoryField() and every Y/value series with setValueFields().
Inheritance
Extends FCartesianChartBuilder. Its inherited members are available on this object.
Example
Independent X fields in Sheets
TypeScript
const fWorksheet = univerAPI.getActiveWorkbook().getActiveSheet()fWorksheet.getRange('A1:D4').setValues([ ['Shared X', 'First Y', 'Other X', 'Second Y'], [1, 10, 5, 30], [2, 20, 9, 40], [3, 25, 12, 50],])const info = fWorksheet .newChart(univerAPI.Enum.ChartTypeString.Scatter) .setSource({ range: 'A1:D4', orientation: univerAPI.Enum.ChartSourceOrientation.Columns }) .setCategoryField(0) .setValueFields([1, 3]) .setSeriesToCategory({ 3: [2] }) .build()await fWorksheet.insertChart(info)// First Y inherits Shared X: (1,10), (2,20), (3,25).// Second Y uses Other X: (5,30), (9,40), (12,50).// Calling setSeriesToCategory({}) restores Shared X for both Y series.Sheet
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const chartInfo = fWorksheet .newChart(univerAPI.Enum.ChartTypeString.Scatter) .setSource({ range: 'A1:C8', orientation: univerAPI.Enum.ChartSourceOrientation.Columns, }) .setCategoryField(0) .setValueFields([1, 2]) .build()await fWorksheet.insertChart(chartInfo)Doc
TypeScript
const fDocument = univerAPI.getActiveDocument()const chartInfo = fDocument .newChart(univerAPI.Enum.ChartTypeString.Scatter) .setSource([ ['X', 'Y'], [10, 20], [18, 32], [24, 28], ]) .setCategoryField(0) .setValueFields([1]) .build()await fDocument.insertChart(chartInfo)Slide
TypeScript
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const chartInfo = fSlide .newChart(univerAPI.Enum.ChartTypeString.Scatter) .setSource([ ['X', 'Y'], [10, 20], [18, 32], [24, 28], ]) .setCategoryField(0) .setValueFields([1]) .build()await fSlide.insertChart(chartInfo)Board
TypeScript
const fBoard = univerAPI.getActiveBoard()const chartInfo = fBoard .newChart(univerAPI.Enum.ChartTypeString.Scatter) .setSource([ ['X', 'Y'], [10, 20], [18, 32], [24, 28], ]) .setCategoryField(0) .setValueFields([1]) .build()await fBoard.insertChart(chartInfo)Setup
Register @univerjs-pro/engine-chart or a preset that includes it. In plugin mode, import @univerjs-pro/engine-chart/facade. Additional methods below require their listed plugin packages. See Facade setup.
How is this guide?