Loading...
In order to meet more analysis scenarios, S2 provides an out-of-the-box scenario table component - trend analysis table. With it, you can easily implement a scene table that displays multiple indicators in a cell.
As shown in the figure, the table form of this type of table is characterized by the ability to display multiple indicator data in the same data cell and column header cell , which is used for data indicators that need to pay attention to time trends , and to view year-on- year comparisons and other scenarios. Line headers can customize the hierarchical structure . Therefore, this component can be used directly when there is such an analysis requirement.
The trend analysis table component uses various capabilities provided by S2 for integration, so it is recommended that you have read the following chapters before reading this chapter:
const s2Options = {
width: 600,
height: 480,
// 角头文本
cornerText: '指标层级',
// 条件格式
conditions: {
// 同环比数值映射规则
text: [
{
field: 'number',
mapping: (value, cellInfo) => {
const { meta, colIndex } = cellInfo;
if (
colIndex === 0 ||
!value ||
!meta?.fieldValue
) {
return {
fill: '#000',
};
}
return {
fill: value > 0 ? '#FF4D4F' : '#29A294',
};
},
},
],
},
style: {
dataCell: {
valuesCfg: {
// 原始数据字段,用于原始数据导出和 tooltip 展示
originalValueField: 'originalValues',
},
},
},
};
import React from "react";import ReactDOM from "react-dom";import { SheetComponent } from "@antv/s2-react";import '@antv/s2-react/dist/s2-react.min.css';ReactDOM.render(<SheetComponentsheetType="strategy"dataCfg={s2DataConfig}options={s2Options}/>,document.getElementById('container'),);
const data = {"measure-a": {values: ["1", "2"],originalValues: [1, 2]}}
const fields = {rows: [{key: 'a-1',title: '节点 1',children: []}]}
import { EXTRA_COLUMN_FIELD } from '@antv/s2'const fields = {columns: ['date', EXTRA_COLUMN_FIELD]}
Virtual examples are the same as ordinary fields, you can customize the formatting
const s2DataConfig = {meta: [// 日期列头 格式化{field: 'date',name: '时间',formatter: (value) => `${value}年`,},// 同环比名称(虚拟列头) 格式化{field: EXTRA_COLUMN_FIELD,formatter: (value, data, meta) => {console.log(data, meta);return meta?.colIndex === 0 ? '自定义标题' : value;},},],};
⚠️ Notes:
originalValues
can not be declaredEXTRA_COLUMN_FIELD
) may not be configuredhierarchyType: 'tree'
options.cornerText
options.conditions
, no need to specify the field
parameter, the usage reference field tag currently only supports the text color channelFunction description: Customize the configuration of the tree structure. View detailed instructions or examples
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
key | The unique identifier of the current node | string | ✓ | |
title | current node display name | string | ✓ | |
collapsed | Whether the node is collapsed (in tree mode, non-leaf nodes at the head of the line are valid) | boolean | false | |
description | The additional description information of the node is displayed in the tooltip of the corresponding line header | string | ||
children | child node | CustomTreeNode[] |
The Tooltip
of the trend analysis table uses the customization capabilities provided by S2
to customize the行头 (row)
,列头 (col)
and数值 (data)
, and can be imported separately in the @antv/s2-react
package
Configuration item name | illustrate | type | Defaults | required |
---|---|---|---|---|
cell | current cell | S2CellType | ✓ | |
defaultTooltipShowOptions | Default tooltip display configuration | TooltipShowOptions<ReactNode> | ||
label | title | `ReactNode | (cell: S2CellType, defaultLabel: ReactNode) => ReactNode` | |
showOriginalValue | Whether to display raw values (if any) | boolean | false |
import { StrategySheetRowTooltip, StrategySheetColTooltip, StrategySheetDataTooltip } from '@antv/s2-react'const s2Options = {tooltip: {content: (cell) => <StrategySheetDataTooltip cell={cell} label={label}/>}}
By default, the name of the row header node is used as the title of the Tooltip, and the content can be customized through the label
// 字符串<StrategySheetDataTooltip cell={cell} label={"自定义标题"}/>// 自定义组件<StrategySheetDataTooltip cell={cell} label={(cell, defaultLabel) => `${defaultLabel}(自定义标题`} />
After showOriginalValue
is turned on, it will read the originalValues
data corresponding to the current Tooltip (if any), and display the original data together, that is,展示值(原始值)
<StrategySheetDataTooltip cell={cell} showOriginalValue />
You can use renderDerivedValue
to customize the value of the same ring ratio, such as replacing it with the original value
currentValue
: current valueoriginalValue
: the original valuecell
: the cell information corresponding to the current Tooltip<StrategySheetDataTooltipcell={cell}renderDerivedValue={(currentValue, originalValue, cell) => <span>({originalValue})</span> }/>
In the indicator trend analysis scenario, usually we want to see the global trend of the data. Trend analysis not only needs to include specific ups and downs, but it is also better to show the trend chart within a fixed period of time, or the completion status (progress) of indicators, so we provide the drawing of mini charts in the table. In order to reduce the dependence on external component libraries, we built a very lightweight mini library based on @antv/g
drawing, which can draw bullet charts, line charts and histograms in cells with minimal performance overhead.
The configuration is as follows:
Draw mini charts in cells (support line charts, bullet charts, histograms). View examples
renderMiniChart = (cell: S2CellType, data?: BaseChartData | BulletValue) => void;
Line chart, histogram data configuration items, data format refer to g2
parameter | illustrate | type | required | Defaults |
---|---|---|---|---|
type | mini-chart type | line | bar | ✓ | |
encode | Encoding method, declare the corresponding column data bound to the x position channel or y position channel | {x: string; y: string} | ✓ | |
data | Raw data | Data[] | ✓ | |
[key: string] | Other transparent fields for customized display of custom cells | unknown |
Bullet chart data configuration items
parameter | illustrate | type | required | Defaults |
---|---|---|---|---|
type | mini-chart type | bullet | ✓ | bullet |
measure | current indicator | number | string | ✓ | |
target | target value | number | string | ✓ | |
[key: string] | Other transparent fields for customized display of custom cells | unknown |
If you want to change the Mini graph style configuration, you can refer to the theme configuration