logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.3
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • Chart
      • Components of G2 Charts
      • How to Use Charts
    • Mark
      • Overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • point
      • polygon
      • range
      • rangeX
      • rangeY
      • rect
      • shape
      • text
      • vector
      • connector
      • wordCloud
    • View
    • Data
      • Overview
      • custom
      • ema
      • fetch
      • filter
      • fold
      • inline
      • join
      • kde
      • log
      • map
      • pick
      • rename
      • slice
      • sort
      • sortBy
    • Encode
    • Scale
      • Overview
      • band
      • linear
      • log
      • ordinal
      • point
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
      • pow
    • Transform
      • Overview
      • bin
      • binX
      • diffY
      • dodgeX
      • flexX
      • group
      • groupColor
      • groupX
      • groupY
      • jitter
      • jitterX
      • jitterY
      • normalizeY
      • pack
      • sample
      • select
      • selectX
      • selectY
      • sortColor
      • sortX
      • sortY
      • stackEnter
      • stackY
      • symmetryY
    • Coordinate
      • Overview
      • fisheye
      • parallel
      • polar
      • theta
      • transpose
      • radial
      • cartesian3D
      • helix
    • Style
    • Animate
      • Overview
      • fadeIn
      • fadeOut
      • growInX
      • growInY
      • morphing
      • pathIn
      • scaleInX
      • scaleInY
      • scaleOutX
      • scaleOutY
      • waveIn
      • zoomIn
      • zoomOut
    • State
    • Interaction
      • Overview
      • brushAxisHighlight
      • brushHighlight
      • brushXHighlight
      • brushYHighlight
      • brushFilter
      • brushXFilter
      • brushYFilter
      • chartIndex
      • elementHighlight
      • elementHighlightByColor
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
      • fisheye
    • Composition
      • Overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • Overview
      • academy
      • classic
      • classicDark
    • Events
    • Color Mapping
  • Chart Component
    • Title
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • Data Label
  • Extra Topics
    • Graph
      • forceGraph
      • pack
      • sankey
      • tree
      • treemap
    • Geo
      • geoPath
      • geoView
    • 3D
      • Draw 3D Chart
      • point3D
      • line3D
      • interval3D
      • surface3D
    • Plugin
      • renderer
      • rough
      • lottie
      • a11y
    • Package on demand
    • Set pattern
    • Server-Side Rendering (SSR)
    • Spec Function Expression Support (Available in 5.3.0)
  • Whats New
    • New Version Features
    • Migration from v4 to v5
  • Frequently Asked Questions (FAQ)

sqrt

Previous
quantize
Next
threshold

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

Overview

sqrt is a continuous non-linear scale that is essentially a pow scale with a fixed exponent of 0.5. The mapping function of the sqrt scale is y = x ^ 0.5 + b, where x is the input data and b is the offset.

The sqrt scale is a type of continuous scale that is suitable for:

  • Data with large numerical range differences that need compression
  • Visualization scenarios that emphasize smaller numerical differences
  • Visual channels that require square root transformation, such as area mapping

Compared to linear scales, sqrt scales have a higher compression degree for large values and are suitable for handling data with large variation ranges.

Mapping Effect Examples

The sqrt scale can make data more evenly distributed visually, especially for datasets with large numerical ranges.

  • Using sqrt scale effect

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
autoFit: true,
data: [
{ year: '1991', value: 1 },
{ year: '1992', value: 4 },
{ year: '1993', value: 9 },
{ year: '1994', value: 16 },
{ year: '1995', value: 25 },
],
encode: { x: 'year', y: 'value' },
scale: { y: { type: 'sqrt' } },
children: [
{ type: 'line', labels: [{ text: 'value', style: { dx: -10, dy: -12 } }] },
{ type: 'point', style: { fill: 'white' }, tooltip: false },
],
});
chart.render();
  • Without sqrt scale effect

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
autoFit: true,
data: [
{ year: '1991', value: 1 },
{ year: '1992', value: 4 },
{ year: '1993', value: 9 },
{ year: '1994', value: 16 },
{ year: '1995', value: 25 },
],
encode: { x: 'year', y: 'value' },
children: [
{ type: 'line', labels: [{ text: 'value', style: { dx: -10, dy: -12 } }] },
{ type: 'point', style: { fill: 'white' }, tooltip: false },
],
});
chart.render();

Options

PropertyDescriptionTypeDefault ValueRequired
domainSet the domain range of the datanumber[]Min-max range of input data
domainMinSet the minimum value of the data domainnumberMinimum value of input data
domainMaxSet the maximum value of the data domainnumberMaximum value of input data
rangeSet the value range for data mappingnumber[] | string[][0, 1]
rangeMinSet the minimum value of the data mapping rangenumber | string0
rangeMaxSet the maximum value of the data mapping rangenumber | string1
unknownThe returned data for null values like undefined, NaN, nullanyundefined
tickCountSet the recommended number of ticks to generate, tickCount is only a suggested value, not absolutenumber5
tickMethodSet the method for generating ticks, commonly used for custom ticks(min: number, max: number, count: number) => number[]d3-ticks
roundRound the output valuesbooleanfalse
clampLimit the mapped values to the rangebooleanfalse
niceExtend the domain range to make the output ticks display more nicelybooleanfalse
interpolateCustom interpolation function(a: number, b: number) => (t: number) => T(a, b) => (t) => a * (1 - t) + b * t
exponentSet the exponent, for sqrt scale, this value is fixed at 0.5number0.5

Examples

Basic Usage

Use sqrt scale to map point sizes in a scatter plot to make numerical differences more apparent.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'point',
autoFit: true,
data: {
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/bubble.json',
},
encode: {
x: 'GDP',
y: 'LifeExpectancy',
size: 'Population',
color: 'continent',
shape: 'point',
},
scale: { size: { type: 'sqrt', range: [4, 50] } },
style: { fillOpacity: 0.3, lineWidth: 1 },
legend: { size: false },
});
chart.render();

Code Explanation

  • This is a bubble chart (point chart), where each point represents a country.
  • Data is fetched remotely and includes fields like GDP, life expectancy, population, etc.
  • The encode section maps GDP to the x-axis, life expectancy to the y-axis, population to point size, and continent to color.
  • scale.size uses sqrt to map population through power transformation to point radius, with range: [4, 20] controlling the minimum and maximum point sizes.
  • Visual styles set transparency and stroke width, with size legend disabled.
  • The chart is rendered with chart.render().

Combined with Color Gradient

Using sqrt scale for color gradient mapping

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
autoFit: true,
children: [
{
type: 'point',
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/56b6b137-e04e-4757-8af5-d75bafaef886.csv',
},
encode: { x: 'date', y: 'value', color: 'value', shape: 'point' },
scale: {
color: { type: 'sqrt', domain: [0, 1], range: ['#1689F1', '#1AC07D'] },
},
style: { stroke: '#000', strokeOpacity: 0.2 },
tooltip: {
items: [
{
channel: 'x',
name: 'year',
valueFormatter: (d) => d.getFullYear(),
},
{ channel: 'y' },
],
},
},
{ type: 'lineY', data: [0], style: { stroke: '#000', strokeOpacity: 0.2 } },
],
});
chart.render();

Code Explanation

  • This is a point chart (scatter plot) with auxiliary lines.
  • The main component is a point chart with data also fetched remotely, including date and value fields.
  • The encode section maps date to the x-axis, value to the y-axis, and value is also mapped to color.
  • scale.color uses sqrt to map value through power transformation to color gradient (blue to green), with domain: [0, 1] specifying the input data range.
  • Points have black strokes with some transparency.
  • Tooltip is configured with custom year formatting.
  • A y=0 auxiliary line (lineY) is also added.
  • The chart is rendered with chart.render().

In this example, data is mapped to color through the sqrt scale, which can better display regional differences compared to linear mapping.