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)

log

Previous
linear
Next
ordinal

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

The logarithmic scale (log scale) in G2 uses logarithmic functions for data mapping, based on exponential relationships with non-linear distribution, specifically designed for data showing exponential growth. When the numerical range in data spans a very large range and causes parts of the chart to be too dense or have too much blank space, logarithmic scale should be prioritized.

Based on the mathematical formula y = log(base) + b.

  • Linear Scale

  • Logarithmic Scale (log scale)

Usage

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
autoFit: true,
height: 300,
data: [
{ year: '1991', value: 1 },
{ year: '1992', value: 10 },
{ year: '1993', value: 100 },
{ year: '1994', value: 1000 },
{ year: '1995', value: 10000 },
],
encode: { x: 'year', y: 'value' },
scale: {
y: {
type: 'log',
// Tick count
tickCount: 5,
// Generate uniform ticks
tickMethod: (min, max, count, base) => {
// Calculate logarithmic range
const logMin = Math.log(min) / Math.log(base);
const logMax = Math.log(max) / Math.log(base);
// Calculate logarithmic step
const logStep = (logMax - logMin) / (count - 1);
// Generate tick array
const ticks = [];
for (let i = 0; i < count; i++) {
const logValue = logMin + i * logStep;
const value = Math.pow(base, logValue);
// Filter values outside the range
if (value >= min && value <= max) {
ticks.push(Math.round(value));
}
}
return ticks;
},
},
},
children: [
{ type: 'line', labels: [{ text: 'value', style: { dx: -10, dy: -12 } }] },
{ type: 'point', style: { fill: 'white' }, tooltip: false },
],
});
chart.render(); // Render chart

Options

PropertyDescriptionTypeDefault ValueRequired
domainSet the domain range of the datanumber[]Min and 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 range of mapped valuesnumber[] | string[][0, 1]
rangeMinSet the minimum value of the mapped rangenumber | string0
rangeMaxSet the maximum value of the mapped rangenumber | string1
unknownReturn value for undefined, NaN, null empty valuesanyundefined
tickCountSet the recommended number of ticks to generate; tickCount is only a suggestionnumber5
tickMethodSet the method for generating ticks, commonly used for custom ticks(min: number, max: number, count: number) => number[]calculateLogTicks
roundRound output valuesbooleanfalse
clampLimit mapped values to the rangebooleanfalse
niceExtend domain range to make output ticks display more friendlybooleanfalse
interpolateCustom interpolation function(a: number, b: number) => (t: number) => T(a, b) => (t) => a * (1 - t) + b * t
baseSet the logarithmic basenumber10

Configuration and notes:

{
scale: {
y: {
type: 'log', // Note: Do not use log when data returns both positive and negative values.
domainMin: 10,
domainMax: 1000,
base: 100, // Set base to 100,
}
}
}

If you need a minimum value domainMin: 0, please refer to the Chart Examples - Logarithmic Column Chart page.

Examples

Format conversion to linear

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'view',
autoFit: true,
height: 300,
data: [
{ year: '1991', value: 1 },
{ year: '1992', value: 10 },
{ year: '1993', value: 1000 },
{ year: '1994', value: 0.1 },
{ year: '1995', value: 100 },
],
encode: { x: 'year', y: 'value' },
scale: { x: { range: [0, 1] }, y: { type: 'log', tickCount: 4 } },
axis: {
y: {
labelFormatter: (v) => {
return Math.log10(v) + 1;
},
},
},
children: [
{
type: 'line',
labels: [
{
text: 'value',
formatter: (v) => {
return Math.log10(v) + 1;
},
style: { dx: -10, dy: -12 },
},
],
},
{ type: 'point', style: { fill: 'white' }, tooltip: false },
],
});
chart.render(); // Render chart