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

Conditions

Previous
Table Mode
Next
Totals

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...

S2 comes with field tagging feature. Users can set different rendering logics based on business semantics to mark and analyze key data. Field tag types include:

  • Text field flag (all cell types)
  • background field marker (all cell types)
  • Histogram (interval) field markers (only data cells are supported)
  • Icon (icon) field markers (currently supports pivot table data cells, row and column header cells)

The figure below visually shows the form of the four field tags:

preview

Get started quickly

The S2 field marking feature is configured by configuring the Conditions attribute in s2Options .

// 构建 options
const s2Options = {
width: 600,
height: 600,
// 通过配置 conditions 实现字段标记
conditions: {
text: [
{
field: "price",
mapping(fieldValue, data) {
return {
// fill 是文本字段标记下唯一必须的字段,用于指定文本颜色
fill: "#5B8FF9",
};
},
},
],
},
};

configuration explanation

The Conditions attribute can configure four different fields, corresponding to four different field tags.

  • text , background and interval are all of Condition array type

    • Contains field and mapping two fields
    • If a field ID matches multiple field marking rules in the same scope, the last rule shall prevail.
  • icon is slightly different, it is IconCondition array type

    • One more position field is used to specify the position of the icon relative to the text

Focus on explaining the two fields of field and mapping :

field

field is used to specify which fields to apply the field mark to, and its value range will vary depending on the form of the table:

  • For pivot tables, the field value range or regular matching range is values ​​, and the scope of action is the row header, column header, corner header and data cells
  • For the detailed table, the field value range or regular matching range is columns , and the range of action is the data cell
pivot mode
table mode

​mapping

mapping is a callback function that handles field marking:

parameterillustratetypeDefaultsrequired
fieldValueThe value of the corresponding field of the cellnumber | string | null-
dataThe entire row of data corresponding to the cellobject-✓
return valueillustratetypeDefaultsrequired
fillWhen used as a text field tag, it represents the text fill color <br data-mdast="html">When it is used as a background field tag, it represents the cell background fill color <br data-mdast="html">It is used as a column When the graph field is marked, it represents the fill color of the histogram <br data-mdast="html">When it is used for the icon field mark, it represents the icon fill color
string-✓
iconFor icon field tags only, specifies the icon typestring-
isCompareOnly used for histogram field marking, when true , you can customize the maximum and minimum values ​​of the histogramboolean-
minValueIt is only used when the histogram field is marked and isCompare is true , and the minimum value of the histogram can be customizednumber-
maxValueOnly used when the histogram field is marked and isCompare is true , customize the maximum value of the histogramnumber-
fieldValueOnly used when the histogram field is marked and isCompare is true , customize the length of the histogramnumber-

If the return value of the mapping function is empty, it means that the field mark of the cell is not rendered

S2 currently has a list of built-in icons:

icon nameicon iconFunctional descriptionicon nameicon iconFunctional description
Cell DowniconYoY declineExpandColIconiconSchedule HideExpand
CellUpiconYoY risePlusicontree form expansion
GlobalAsciconglobal ascendingMinusiconTree form collapsed
GlobalDesciconglobal descendingSortDowniconSchedule descending
GroupAsciconascending order within groupSortDownSelectediconSchedule descending selection status
GroupDescicondescending order within groupSortUpiconSchedule Ascending
trendiconTrendSortUpSelectediconSchedule ascending selection status
ArrowUpiconindicator risesArrowDowniconindicators drop
DrillDownIconicondrill down

​

🎨 field mark detailed configuration refer to Conditions API documentation.

characteristic

custom icon position

By setting the position attribute in the icon field tag, you can set whether the icon is on the left or right of the text. (Currently, header cells do not support switching)

The icon for the price field is to the right of the text, and the icon for the cost field is to the left of the text:

Custom histogram range

You can customize the interval range of the histogram by displaying the return value of the mapping attribute in the specified interval field tag and setting the value of the isCompare attribute to true , and specifying the values ​​of maxValue and minValue .

If the value of the isCompare attribute in the return value of the mapping 函数is false or the attribute is not returned. At this time maxValue and minValue will use the maximum and minimum values ​​of the field in all chart data as interval ranges

The price field uses a custom schema, and the cost field uses the default schema:

Two-way histogram

When the interval of the histogram has positive and negative points, and with the fill attribute of the return value of the mapping function, a positive and negative two-way histogram with different colors can be drawn:

​📊 See more field markup examples .

Gradient histogram

The underlying graphic drawing of S2 uses the AntV/g rendering engine. With its powerful drawing capabilities, the fill field is not only a color attribute, but also gradient colors , textures , etc. can be used.

The price field uses a gradient color:

​📊 See more field markup examples .

Turn on text intelligent inversion

By displaying the return value of the mapping function in the specified background field tag the intelligentReverseTextColor attribute value is true . When the mark background color is dark and the text color and background color combination does not meet the Level AA standards of the WCAG2.0 guidelines, the text color will change to white. When the marker background color is bright, the text color defaults to black. Priority: intelligentReverseTextColor of background condition < fill of text condition

​📊 See more field markup examples .