logo

S2

  • Manual
  • API
  • Examples
  • Playground
  • ChangeLog
  • Productsantv logo arrow
  • 2.x
  • Introduction
  • Quick Start
  • Basic Tutorial
    • Base Concept
    • Sheet Type
      • Pivot Mode
        Updated
      • Table Mode
    • Conditions
      Updated
    • Totals
    • Sort
      • Custom Sort
        Updated
      • Group Sort
        Updated
    • Theme
      Updated
    • Tooltip
      Updated
    • Internationalization
    • 数据格式化
      New
    • Multi Line
      New
    • Pagination
      New
  • Advanced Tutorial
    • Advanced Tutorial
      • Link
      • Render Chart In Cell
      • Draw Chart With @antv/g2
    • Custom
      • Customize Hook
        Updated
      • Customize Tree
        New
      • Customize Icon
      • Customize Cell Alignment
      • Customize Cell Size
        Updated
      • Customize Order
      • Custom Collapse/Expand Nodes
    • Interaction
      • Basic Interaction
      • Custom Interaction
      • Hide Columns
      • Cell Resize
      • Merge Cell
      • Scroll
      • Copy
        New
      • Highlight and select cell
        New
    • Analyze Component
      • Introduction
        New
      • Advanced Sort
        Updated
      • Switcher
      • Export
        Updated
      • Pagination
      • Drill Down
    • Sheet Component
      • Editable Mode
      • Strategy Sheet
        Updated
    • HD Adapter
    • Get Instance
    • Get Cell Data
      Updated
    • Table adaptive
    • AntV/G Plugins
      New
    • Pivot Chart
      Experimental
    • Vue 3.0
  • Extended Reading
    • Data Process
      • Pivot
      • Table
    • Layout
      • Pivot
      • Table
    • Performance
      Updated
  • Contribution
  • FAQ
  • S2 2.0 Migration Guide

Theme

Previous
Group Sort
Next
Tooltip

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Introduction

There are 3 out-of-the-box theme configurations built into S2, and powerful theme customization functions are also provided. View APIs

color

In the color usage of S2, we will first select a theme color, and use the theme color to generate a set of标准色板:

  • There are 11 color positions in the standard color palette, and the theme color is located on index 6
  • Use the theme color plus different degrees of white to白5 lighter colors, placed on index 0~5
  • Use the theme color plus different degrees of黑to generate 5 darker colors and place them on indexes 6~11

The following is an example of using #0A78F4 and #FF5500 different theme colors to generate a standard color palette:

#0A78F4 standard palette#FF5500 standard palette

Swatch Palette

The swatch is defined as Palette , from which the color will be taken when the theme schema is generated, and its color comes from the standard swatch. The key properties of Palette are:

  • basicColors: the basic color, with a total of 15 color bits, which essentially determines the color scheme of the table. When generating the theme schema, the color will be selected from the fixed index of basicColors. If the background color of the row header is fixed, the color of basicColors[1] will be taken
  • basicColorRelations: the corresponding relationship between basicColors and standard swatches. For example, in the built-in colorful theme, basicColors[1] is the color of index 0 in the standard swatches.

Thus S2 guarantees that all the colors used in drawing come from the theme color or the derived color of the theme color. In this way, the color of the table interface is unified, and it is also convenient for users to generate personalized themes according to the theme colors they need.

ThemeSchema

The theme schema is defined as S2Theme , which describes the theme style of cells and interactions in detail, and its attributes include color, line thickness, text size, text alignment, etc. Throughout the schema, all colors will be taken from the Palette :

  • basicColors: Basic colors, such as corner/column/row header background, font/icon color
  • semanticColors: Semantic colors, such as the color values ​​referred to by red and green
  • others: Supplementary colors, some fixed special colors, such as search results
const s2 = new PivotSheet(container, s2DataConfig, s2Options);
s2.setTheme({
background: {
color: '#353c59',
},
});
s2.render(false);

custom theme

The setThemeCfg method on the s2 instance is the entry point for all theme configurations. This method receives a parameter of type ThemeCfg . You can:

  • Use a preset theme via ThemeCfg.name
  • Generate a theme by customizing the swatches of ThemeCfg.palette
  • Generate the theme through the ThemeCfg.theme custom schema (can be used with the above two properties at the same time, that is, override the theme generated by them)

Choose a preset theme

You can use the corresponding theme by specifying the theme name:

const s2 = new PivotSheet(container, s2DataConfig, s2Options);
// name 可为 default, colorful, gray
s2.setThemeCfg({ name: 'colorful' });
s2.render(false);

S2 has 3 built-in theme effects:

Defaultdefault
Colorful bluecolorful
Simple graygray

​📊 See more theme examples .

custom schema

If the built-in themes do not meet your requirements, you can override specific configurations by customizing the schema .

At this point you can call s2.setTheme or s2.setThemeCfg() to configure the theme object. View the complete schema configuration :

const s2 = new PivotSheet(container, s2DataConfig, s2Options);
const customTheme = {
background: {
color: '#353c59',
},
};
// s2.setThemeCfg({ theme: customTheme })
s2.setTheme(customTheme)
s2.render(false);

Customize cell alignment

View details and full API

s2.setTheme({
rowCell: {
text: {
textAlign: 'left',
},
bolderText: {
textAlign: 'left',
},
},
});

Custom cell background color

View full API

s2.setTheme({
rowCell: {
cell: {
backgroundColor: '#dcdcdc',
},
},
});

custom scrollbar style

View full API

s2.setTheme({
scrollBar: {
thumbColor: '#666',
thumbHorizontalMinSize: 20,
thumbVerticalMinSize: 20,
},
});

custom swatches

Although the custom schema is flexible, it has a heavy mental burden and requires a more detailed understanding of the schema structure. Therefore, we also provide a custom color palette function. At this time, you need to configure the palette object for setThemeCfg . View full swatch configuration :

Optional swatch color

You can refer to the built-in swatches to personalize basicColors and semanticColors . The selected colors will be used to draw different parts of the table. For the relationship between colors, please refer to the swatch comparison table below .

In addition, in order to facilitate the deployment of exclusive color palettes, S2 officially provides a self-service color palette tool , which helps you quickly adjust color palettes, copy and paste them into projects for use with one click.

const s2 = new PivotSheet(container, s2DataConfig, s2Options);
const s2Palette = {
// 基础配色色板
basicColors: [
'#FFFFFF',
'#F8F5FE',
'#EDE1FD',
'#873BF4',
'#7232CF',
'#AB76F7',
'#FFFFFF',
'#DDC7FC',
'#9858F5',
'#B98EF8',
'#873BF4',
'#282B33',
'#121826',
],
// 语义化色板
semanticColors: {
red: '#FF4D4F',
green: '#29A294',
},
};
s2.setThemeCfg({ palette: s2Palette });
s2.render(false);

Automatically generated by theme color

There is a large degree of freedom in the deployment of self- selected swatch colors , but each color needs to be determined individually, and the overall process is relatively complicated. To meet users' general theme demands, S2 also provides the function of generating color palettes based on theme colors.

import { getPalette, generatePalette, PivotSheet } from '@antv/s2';
const s2 = new PivotSheet(container, s2DataConfig, s2Options);
// 主题色
const themeColor = '#EA1720';
// 使用内置的 colorful 色板作为参考色板
// 根据风格差异,你也可以选择 default、gray 作为参考色板
const palette = getPalette('colorful');
// 使用参考色板 & 主题色值生成新色板
const newPalette = generatePalette({ ...palette, brandColor: themeColor });
// 使用新色板设置主题
s2.setThemeCfg({
palette: newPalette,
});
s2.render(false);

Preset theme color palette comparison table

SwatchesCoveragecorresponds to the key of the schema
Basic color - basicColors
defaultsimple graycolorful blue
#000000#000000#FFFFFFCorner header cell bold text color
cornerCell.bolderText.fill
Corner header cell text color
cornerCell.text.fill
Corner header cell icon color
cornerCell.icon.fill
Row header cell icon color
rowCell.cell.icon.fill
Column header cell bold text color
colCell.bolderText.fill
column header cell text color
colCell.text.fill
column header cell icon color
colCell.icon.fill
data cell icon color
dataCell.icon.fill
#F5F8FE#FAFBFB#F5F8FFRow header cell background fill color
rowCell.cell.backgroundColor
Data cell background fill color
dataCell.cell.backgroundColor
#E0E9FD#F0F2F4#E1EAFEThe background fill color of the mouse hover state of the row header cell
rowCell.interactionState.hover.backgroundColor
The background fill color of the mouse-selected state of the row header cell
rowCell.interactionState.selected.backgroundColor
Data cell mouse hover background fill color
dataCell.interactionState.hover.backgroundColor
Data cell mouse hover focus state background fill color
dataCell.interactionState.hoverFocus.backgroundColor
Data cell mouse selected background fill color
dataCell.interactionState.selected.backgroundColor
#E0E9FD#F0F2F4#3471F9Corner header cell background fill color
cornerCell.cell.backgroundColor
Column header cell background fill color
colCell.cell.backgroundColor
#CCDBFC#E7E9ED#2C60D4Column header cell mouse hover background fill color
colCell.cell.interactionState.hover.backgroundColor
The background fill color of the mouse selected state of the column header cell
colCell.cell.interactionState.selected.backgroundColor
#234DAB#6E757F#2C60D4Brush the background fill color of the pre-selected state mask
prepareSelectMask.backgroundColor
#326EF4#565C64#2C60D4Row header cell link text color
rowCell.text.linkTextFill
#326EF4#9DA7B6#3471F9Data cell histogram fill color
dataCell.cell.miniBarChartFillColor
resize mask background color
resizeArea.background
resize hotspot guide color
resizeArea.guideLineColor
resize background color of hotspot hover state
resizeArea.interactionState.hover. backgroundColor
#FFFFFF#FFFFFF#FFFFFFData cell background fill color
dataCell.cell.backgroundColor
table background fill color
background.color
#E0E9FD#F0F2F4#E1EAFERow header cell horizontal border color
rowCell.cell.horizontalBorderColor
Row header cell vertical border color
rowCell.cell.verticalBorderColor
Data cell horizontal border color
dataCell.cell.horizontalBorderColor
Data cell vertical border color
dataCell.cell.verticalBorderColor
#CCDBFC#E7E9ED#5286FAHorizontal border color of corner header cells
cornerCell.cell.horizontalBorderColor
Corner header cell vertical border color
cornerCell.cell.verticalBorderColor
Column header cell horizontal border color
colCell.cell.horizontalBorderColor
Column header cell vertical border color
colCell.cell.verticalBorderColor
#326EF4#BAC1CC#5286FAThe horizontal border color of the table body (level one horizontal dividing line)
splitLine.verticalBorderColor
#326EF4#BAC1CC#3471F9The vertical border color of the table body (first-level vertical dividing line)
splitLine.horizontalBorderColor
#000000#000000#000000Data cell bold text color
dataCell.bolderText.fill
data cell text color
dataCell.text.fill
#000000#000000#000000Row header cell bold text color
rowCell.bolderText.fill
Row header cell bold link text color
rowCell.bolderText.linkTextFill
Row header cell link text color
rowCell.text.linkTextFill
Data cell mouse hover focused state border color
dataCell.interactionState.hoverFocus.borderColor
The border color of the data cell mouse selection pre-center state
dataCell.interactionState.prepareSelect.borderColor
Semantic Colors - semanticColors
red: #FF4D4Fred: #FF4D4Fred: #FF4D4FColor of the arrow icon on the data cell
dataCell.icon.downIconColor
green: #29A294green: #29A294green: #29A294Data cell down arrow icon color
dataCell.icon.upIconColor