logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.5
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • G2's complete configuration system
    • Chart
      • Components of G2 Charts
      • Chart Lifecycle
    • 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)

classicDark

Previous
classic
Next
Events

Resource

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

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

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-Interactive solution
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Classic dark theme. When using a dark theme, it's usually necessary to configure additional view styles to ensure the chart has better visual effects on dark backgrounds.

Configuring View Background

import { Chart } from '@antv/g2';
const chart = new Chart({ container: 'container' });
chart.options({
type: 'interval',
theme: { type: 'classicDark', view: { viewFill: '#141414' } },
data: [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Role-playing', sold: 120 },
{ genre: 'Action', sold: 350 },
{ genre: 'Simulation', sold: 150 },
],
encode: { x: 'genre', y: 'sold', color: 'genre' },
});
chart.render();

Using viewStyle for More Detailed View Configuration

import { Chart } from '@antv/g2';
const chart = new Chart({ container: 'container' });
chart.options({
type: 'interval',
theme: 'classicDark',
data: [
{ category: 'A', value: 23 },
{ category: 'B', value: 45 },
{ category: 'C', value: 56 },
{ category: 'D', value: 78 },
{ category: 'E', value: 32 },
],
encode: { x: 'category', y: 'value', color: 'category' },
axis: {
x: { grid: true, gridStroke: '#404040' },
y: { grid: true, gridStroke: '#404040' },
},
viewStyle: {
viewFill: '#1f1f1f',
plotFill: '#2a2a2a',
plotStroke: '#404040',
plotLineWidth: 1,
},
});
chart.render();

Complete Dark Theme Configuration Example

import { Chart } from '@antv/g2';
const chart = new Chart({ container: 'container' });
chart.options({
type: 'line',
theme: {
type: 'classicDark',
view: { viewFill: '#0f0f0f', plotFill: '#1a1a1a' },
},
data: [
{ year: '2018', value: 30 },
{ year: '2019', value: 40 },
{ year: '2020', value: 35 },
{ year: '2021', value: 50 },
{ year: '2022', value: 49 },
{ year: '2023', value: 70 },
],
encode: { x: 'year', y: 'value' },
style: { stroke: '#60a5fa', lineWidth: 3 },
axis: {
x: {
grid: true,
gridStroke: '#fff',
gridLineWidth: 2,
labelFill: '#d1d5db',
},
y: {
grid: true,
gridStroke: '#fff',
gridLineWidth: 2,
labelFill: '#d1d5db',
},
},
});
chart.render();

Coordinating with Container Background Color

If your webpage or application uses a dark theme, it's recommended to ensure the chart's background color coordinates with the container background color:

import { Chart } from '@antv/g2';
// Simulate dark container background
const container = document.getElementById('container');
if (container) {
container.style.backgroundColor = '#111827';
container.style.padding = '20px';
container.style.borderRadius = '8px';
}
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'area',
theme: { type: 'classicDark', view: { viewFill: '#111827' } },
data: [
{ month: 'Jan', sales: 120 },
{ month: 'Feb', sales: 140 },
{ month: 'Mar', sales: 110 },
{ month: 'Apr', sales: 180 },
{ month: 'May', sales: 160 },
{ month: 'Jun', sales: 200 },
],
encode: { x: 'month', y: 'sales' },
style: {
fill: 'linear-gradient(to top, rgba(59, 130, 246, 0.3), rgba(59, 130, 246, 0.1))',
stroke: '#3b82f6',
lineWidth: 2,
},
});
chart.render();