API

S2DataConfig

Tabular data configuration

const s2DataConfig = { 
  data: [], 
  meta: [], 
  sortParams: [], 
  fields: { 
    rows: [], 
    columns: [], 
    values: [] 
  } 
} 
parameterillustratetypeDefaultsrequired
dataRaw dataData[]✓
fieldsdimension indexFields✓
totalDataTotal/Subtotal DataData[]
metaField metadata, configurable field aliases and value formattingMeta[]
sortParamsSorting parameter configurationSortParam[]

RawData

SimpleData | MiniChartData | MultiData required , default: null

Function description: tabular data source

type RawData = Record<string, DataItem>; 
type DataItem =  SimpleData | MultiData; 

SimpleData

Function description: basic data type

type SimpleData = string | number; 
const data = [ 
  { 
    area: '东北', 
    province: '吉林', 
    city: '白山', 
    type: '办公用品', 
    subType: '纸张', 
    cost: '2', 
  }, 
  { 
    area: '东北', 
    province: '吉林', 
    city: '白山', 
    type: '办公用品', 
    subType: '笔', 
    cost: '3', 
  } 
]; 

MultiData

Function description: used to support custom data cell rendering of multiple indicator types. Example: Trend Analysis Table

Configuration item nameillustratetypeDefaultsrequired
valuesThe formatted data is directly displayed in dataCfgSimpleData [][]✓
originalValuesraw data, for raw data exportSimpleData [][]
labelUsed as a subtitle of a cell, displayed on a separate linestring
[key: string]Other transparent fields for customized display of custom cellsunknown``
const data = [ 
  { 
    number: { 
      originalValues: [1, 2, 3], 
      values: ['1', '2', '3'] 
    } 
  } 
]; 

Fields

object is required , default: null

Function description: Configure the dimension field of the table, that is, the corresponding row and column dimensions

Configuration item nameillustratetypeDefaultsrequired
rowsRow dimension (customizable row header, see example )string[] | CustomTreeNode[][]
columnsColumn dimension (column header can be customized, see example )string[] | CustomTreeNode[][]
valuesIndicator Dimensionsstring[][]
valueInColsWhether the indicator dimension is at the column headerboolean
customValueOrderThe hierarchical order of custom indicator dimensions in the row and column headers (that is, the order of values , starting from 0 ) View examplenumber-

Meta

Function description: field metadata, configurable field alias and value formatting.

Function description: Field metadata, configurable field alias and value formatting.

parameterillustratetypeDefaultsrequired
fieldfield idstring
nameField Namestring
descriptionField description, which will be displayed in the tooltip corresponding to the row header, column header, and cellstring
formatterFormatting cells, row headers and column headers support formatting, but corner headers do not support formatting. The second parameter exists only for cells.
Numerical fields: generally used to format numeric units Text fields: generally used as aliases for field enumeration values The second parameter will be passed in in the following situations: data cell formatting, copy/export, tooltip display ( and only when selected When there are multiple cells, the data type is an array )
(value: unknown, data?: Data | Data[], meta?: Node | ViewMeta) => string
renderercell render type(image or video)Renderer

Renderer

parameterillustratetypeDefaultsrequired
typeRender TypeIMAGE | VIDEO✓
clickToPreviewThis parameter is valid when type is image or videobooleantrue
prepareTextPerform asynchronous processing on the text before rendering(value: SimpleData) => Promise
fallbackFallback display for image loading failurestring
timeoutnumber10000
configPartial<ImageStyleProps> | Partial<HTMLVideoElement>| HTMLStyleProps

MiniChartData

renderMiniChart

Draw mini charts in cells (support line charts, bullet charts, histograms). View examples

 renderMiniChart = (cell: S2CellType, data?: BaseChartData | BulletValue) => void; 

BaseChartData

Line chart, histogram data configuration items, data format refer to g2

parameterillustratetyperequiredDefaults
typemini-chart typeline | bar✓
encodeEncoding method, declare the corresponding column data bound to the x position channel or y position channel{x: string; y: string}✓
dataRaw dataData[]✓
[key: string]Other transparent fields for customized display of custom cellsunknown

BulletValue

Bullet chart data configuration items

parameterillustratetyperequiredDefaults
typemini-chart typebullet✓bullet
measurecurrent indicatornumber | string✓
targettarget valuenumber | string✓
[key: string]Other transparent fields for customized display of custom cellsunknown

MultiData

object is required , default: null

Function description: used to support custom data cell rendering of multiple indicator types. Example: Trend Analysis Table

Configuration item nameillustratetypeDefaultsrequired
valuesThe formatted data is directly displayed in dataCfg(string | number)[][]✓
originalValuesraw data, for raw data export(string | number)[][]
labelUsed as a cell subtitle, displayed on a separate linestring
[key: string]Other transparent fields for customized display of custom cellsunknown``

SortParam

Function description: sorting configuration

parameterillustratetypeDefaultsrequired
sortFieldIdMeasure Id, the Id to be sortedstring-✓
sortMethodsort byASC | DESC | asc | desc-
sortBycustom sorted liststring[]-
sortByMeasureSort by metric value (numeric value) (for pivot tables)string-
queryFilter criteria, narrow the sort range such as: {city:'白山'}Record<string, string>-
typeSorting within the group is used to display the icon (for pivot tables)string-
sortFuncFunction for custom sorting(params: SortFuncParam ) => string[]-

SortFuncParam

Function description: Custom sorting function parameters

parameterillustratetypeDefaultsrequired
sortFieldIdMeasure Id, the Id to be sortedstring-✓
sortMethodsort byASC | DESC | asc | desc-
sortBycustom sorted liststring[]-
sortByMeasureSort by metric value (numeric value) (for pivot tables)string-
queryFilter criteria, narrow the sort range such as: {city:'白山'}Record<string, string>-
typeSorting within the group is used to display icons (applicable to pivot tables)string-
dataList of currently sorted dataArray<string | Record<string, any>>-

CustomTreeNode

Function description: Customize the configuration of the tree structure. View detailed instructions or examples

parameterillustratetypeDefaultsrequired
keyThe unique identifier of the current nodestring✓
titlecurrent node display namestring✓
collapsedWhether the node is collapsed (in tree mode, non-leaf nodes at the head of the line are valid)booleanfalse
descriptionThe additional description information of the node is displayed in the tooltip of the corresponding line headerstring
childrenchild nodeCustomTreeNode[]

Columns

Array<ColumnNode | string>

Column configuration array, supports the use of ColumnNode structure to describe the column grouping relationship in the detailed table mode

ColumnNodes

attribute nameillustratetypeDefaultsrequired
keycolumn field id or group idstring✓
childrensubclass below the groupArray<ColumnNode | string>
S2Options