Loading...
The "dimension drill-down" capability provided by S2 can dig out more detailed data in different dimensions for you, making your data insights clearer.
Configure dimension drill-down, currently only supports drill-down in the perspective mode tree structure, row header dimension drill-down
Drill Up: Drill Up exists to view sales data in different regions. When you view sales in Zhejiang Province, you can drill up to view sales in East China.
const sex = [ '男', '女' ];
const PartDrillDown = { drillConfig: { dataSet: [ // 下钻数据源配置 { name: '客户性别', value: 'sex', type: 'text', }, ], },
// 点击下钻后的回调 fetchData: (meta, drillFields) => new Promise((resolve) => { const dataSet = meta.spreadsheet.dataSet; const field = drillFields[0]; const rowDatas = dataSet.getCellMultiData(meta.query, true, true); const drillDownData = []; rowDatas.forEach((data) => { const { city, number, province, sub_type: subType, type } = data; const number0 = Math.ceil(Math.random() * (number - 50)) + 50; const number1 = number - number0; const dataItem0 = { city, number: number0, province, sub_type: subType, type, [field]: sex[0], }; drillDownData.push(dataItem0); const dataItem1 = { city, number: number1, province, sub_type: subType, type, [field]: sex[1], };
drillDownData.push(dataItem1); });
resolve({ drillField: field, // 下钻维度 value 值 drillData: drillDownData, // 下钻数据 }); }), };
import React from 'react';import ReactDOM from 'react-dom';import { SheetComponent } from '@antv/s2-react';const s2Options = {hierarchyType: 'tree', // 树形结构};ReactDOM.render(<SheetComponentdataCfg={s2DataConfig}options={s2Options}partDrillDown={PartDrillDown}/>,document.getElementById('container'),);
🌰 Case: insight into abnormal data : when the sales leader finds that the sales in Central China are abnormal, which is much lower than other regions. He drills down to the provinces to view the sales of all provinces in Central China. When abnormal sales in Hubei Province are found, you can drill down to the city 🏙 through the province and find that the sales in city B are abnormal. Through drilling down, we quickly discovered the root cause of abnormal sales.
const s2Options = {width: 600,height: 480,hierarchyType: 'tree', // 树形结构};<SheetComponentoptions={s2Options}partDrillDown={PartDrillDown}sheetType="pivot" // 透视模式/>
📊 Check out the React version of the drilldown demo
The drill-down component can only be used in table and perspective mode.
const s2Options = {width: 600,height: 480,hierarchyType: 'tree',};<template><SheetComponentref="s2":sheetType="pivot":partDrillDown="partDrillDown":options="s2Options"/></template>
📊 Check out the Vue version of the drilldown demo
Function description: Configure dimension drill-down, currently only supports drill-down in the perspective mode tree structure, row header dimension drill-down
Type: object
, optional , default: {}
parameter | illustrate | type | Defaults | required | Remark | Version |
---|---|---|---|---|---|---|
drillConfig | Drill down menu component configuration items | DrillDownProps | - | ✓ | ||
drillItemsNum | The number of displayed items after the drill-down is completed, and all are displayed by default | number | -1 | |||
fetchData | Callback after clicking the drilldown | FetchCallBack | - | ✓ | ||
clearDrillDown | Clear the drill-down information. When the specified rowId is passed, clear the drill-down information corresponding to the rowId; if the parameter is an empty object {}, clear all the drill-down information | {rowId: string;} | - | Only React components support this property | ||
displayCondition | Configure the display conditions of the drilldown icon , same as HeaderActionIcon | (meta: Node, iconName: string) => boolean | - | Only React components support this property | 1.26.0 returns the iconName and presses a single icon to control the display and hiding |
Note: The drillConfig
and displayCondition
fields in PartDrillDown will affect the re-rendering of the drill-down mode, please note that use memo or state to control its variability.
(meta: Node, drillFields: string[]) => Promise<PartDrillDownInfo>
Function description: Callback parameters after clicking the drilldown: PartDrillDownInfo
Type: object
, required , default value: {}
Function description: Drill down data request parameter configuration
parameter | illustrate | type | required | Defaults |
---|---|---|---|---|
drillData | drill down data | Record<string, string | number>[] | ✓ |
drillField | Drill down dimension value value | string | ✓ |
Type: object
, required , default value: {}
Function description: Drill down menu component configuration items
parameter | illustrate | type | Defaults | required | Remark |
---|---|---|---|---|---|
dataSet | Drill down to data source configuration | DataSet[] | ✓ | ||
className | Transparent style name | string | |||
title | title | string | |||
searchText | Search Box Copywriting | string | |||
clearText | reset button copy | string | |||
disabledFields | Dimensions that do not allow drill-down | string[] | |||
getDrillFields | Internally get the callback of the current drill-down dimension | Function | |||
setDrillFields | Internally set the callback of the current drill-down dimension | Function | |||
extra | Customize the inserted node, inserted between the search box and the drill-down menu | ReactNode | Only React components support this property | ||
drillFields | Dimensions that allow drill-down | string[] | Only React components support this property |
Type: object
, required , default value: {}
Function description: drill down data source configuration
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
name | show name | string | ✓ | |
value | specific value | string | ✓ | |
type | Dimension type, different types correspond to different icons | text | location | date | ||
disabled | Is it allowed to choose | boolean | ||
icon | The icon of the list item | ReactNode |