logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.47
  • Introduction
  • Data
  • Getting Started
    • Quick Start
    • Installation
    • Integration
      • react
      • vue
      • angular
    • Step-by-step guide
  • Graph
    • Extensions En
    • Graph
    • Options
    • extension
  • Element
    • Element Overview
    • Element State
    • Node
      • Node Overview
      • Build-in Node
        • Common Node Configurations
        • Diamond
        • Donut
        • Ellipse
        • Hexagon
        • Html
        • Image
        • Rect
        • Star
        • Triangle
        • Circle
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Build-in Edge
        • Common Edge Configurations
        • Cubic Bezier Curve
        • CubicHorizontal Bezier Curve
        • CubicVertical Bezier Curve
        • Line
        • Polyline
        • Quadratic Bezier Curve
      • Custom Edge
    • Combo
      • Combo Overview
      • Build-in Combo
        • Circle
        • Combo Configuration Options
        • Rect
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Build-in Layout
      • 3D Force-Directed Layout
      • AntvDagre Layout
      • Circular Layout
      • ComboCombined Layout
      • Common Layout Configuration Options
      • CompactBox
      • Concentric Layout
      • D3 Force-Directed Layout
      • Dagre Layout
      • Dendrogram Layout
      • Fishbone Layout
      • Force Force-directed Layout
      • ForceAtlas2 Force-directed Layout
      • Fruchterman Force-directed Layout
      • Grid Layout
      • Indented Tree
      • MDS High-dimensional Data Dimensionality Reduction Layout
      • Mindmap Tree
      • Radial Layout
      • Random Layout
      • Snake Layout
    • Custom Layout
  • Behavior
    • Behavior Overview
    • Build-in Behavior
      • AutoAdaptLabel
      • BrushSelect
      • ClickSelect
      • CollapseExpand
      • CreateEdge
      • DragCanvas
      • DragElement
      • DragElementForce
      • FixElementSize
      • FocusElement
      • HoverActivate
      • LassoSelect
      • OptimizeViewportTransform
      • ScrollCanvas
      • ZoomCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Build-in Plugin
      • Background
      • BubbleSets
      • Contextmenu
      • EdgeBundling
      • EdgeFilterLens
      • Fisheye
      • Fullscreen
      • GridLine
      • History
      • Hull
      • Legend
      • Minimap
      • Snapline
      • Timebar
      • Toolbar
      • Tooltip
      • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • Build-in Transform
      • MapNodeSize
      • PlaceRadialLabels
      • ProcessParallelEdges
    • Custom Transform
  • Theme
    • Theme Overview
    • Custom Theme
    • Palette
    • Custom Palette
  • Animation
    • Animation Overview
    • Custom Animation
  • Further Reading
    • Event
    • renderer
    • coordinate
    • download-image
    • Using Iconfont
    • Use 3D
    • Bundle Project
  • What's new
    • Feature
    • Upgrade To 5.0
  • FAQ
  • contribute

Timebar

Previous
Snapline
Next
Toolbar

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 Timebar plugin is an important tool for exploring time-series data. It can display the time distribution of data in the form of a timeline or trend chart, and supports interactions such as time interval filtering and dynamic playback, helping users better understand the changes in data over time.

Use Cases

  • Need to display and analyze the time distribution of time-series data
  • Need to filter and explore graph data through the time dimension
  • Need to dynamically display the process of data changing over time

Basic Usage

Below is a simple example of initializing the Timebar plugin:

const graph = new Graph({
plugins: [
{
type: 'timebar',
data: timeData, // Time data
width: 450, // Timebar width
height: 60, // Timebar height
position: 'bottom', // Position
loop: false, // Whether to loop playback
},
],
});

Online Experience

createGraph(
{
data: {
nodes: new Array(25).fill(0).map((_, index) => ({
id: `node-${index}`,
data: {
timestamp: new Date('2023-08-01').getTime() + (index % 5) * 3600 * 24 * 1000,
value: index % 10,
label: new Date(new Date('2023-08-01').getTime() + (index % 5) * 3600 * 24 * 1000).toLocaleString(),
},
})),
edges: new Array(25).fill(0).map((_, i) => ({
id: `edge-${i}`,
source: `node-${i % 12}`,
target: `node-${(i % 10) + 15}`,
data: {
edgeType: 'e1',
},
})),
},
layout: { type: 'grid', cols: 5 },
node: {
style: { size: 24, fill: '#7e3feb' },
palette: { field: 'cluster' },
},
edge: { style: { stroke: '#8b9baf' } },
behaviors: ['drag-canvas'],
plugins: [
'grid-line',
{
type: 'timebar',
key: 'timebar',
data: [10, 2, 3, 4, 15].map((value, index) => ({
time: new Date(new Date('2023-08-01').getTime() + index * 3600 * 24 * 1000),
value,
label: new Date(new Date('2023-08-01').getTime() + index * 3600 * 24 * 1000).toLocaleString(),
})),
timebarType: 'time',
height: 100,
},
],
autoFit: 'view',
padding: [10, 0, 100, 0],
},
{ width: 600, height: 400 },
(gui, graph) => {
const options = {
type: 'timebar',
position: 'bottom',
enable: true,
timebarType: 'time',
className: 'g6-timebar',
width: 450,
height: 100,
zIndex: 3,
elementTypes: ['node'],
mode: 'modify',
loop: false,
};
const optionFolder = gui.addFolder('Timebar Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'height', 40, 100, 1);
optionFolder.add(options, 'width', 200, 800, 1);
optionFolder.add(options, 'position', ['bottom', 'top']);
optionFolder.add(options, 'timebarType', ['time', 'chart']);
optionFolder.add(options, 'loop');
optionFolder.onChange(({ property, value }) => {
graph.updatePlugin({
key: 'timebar',
[property]: value,
});
graph.render();
});
const apiFolder = gui.addFolder('Timebar API');
const instance = graph.getPluginInstance('timebar');
apiFolder.add(instance, 'play');
apiFolder.add(instance, 'pause');
apiFolder.add(instance, 'forward');
apiFolder.add(instance, 'backward');
apiFolder.add(instance, 'reset');
},
);

Configuration Options

PropertyDescriptionTypeDefault ValueRequired
typePlugin typestringtimebar✓
keyUnique identifier for the plugin, can be used to get the plugin instance or update plugin optionsstring-
classNameAdditional class name for the toolbar DOMstringg6-timebar
xX position (position will be invalid if set)number-
yY position (position will be invalid if set)number-
widthTimebar widthnumber450
heightTimebar heightnumber60
positionTimebar positionbottom | topbottom
paddingPaddingnumber | number[]10
dataTime datanumber[] | { time: number; value: number }[]-✓
timebarTypeTimebar display typetime | charttime
elementTypesFilter element types(node | edge | combo)[][node]
modeControl element filtering method, supports the following two configurations:
- modify: filter by modifying graph data
- visibility: filter by modifying element visibility
modify | visibilitymodify
valuesCurrent time valuenumber | [number, number] | Date | [Date, Date]-
loopWhether to loop playbackbooleanfalse
getTimeMethod to get element time(datum: ElementDatum) => number-
labelFormatterCustom time formatting in chart mode(time: number | Date) => string-
onChangeCallback when the time interval changes(values: number | [number, number]) => void-
onResetCallback when reset() => void-
onSpeedChangeCallback when playback speed changes(speed: number) => void-
onPlayCallback when playback starts() => void-
onPauseCallback when paused() => void-
onBackwardCallback when moving backward() => void-
onForwardCallback when moving forward() => void-

timebarType

The timebarType property is used to control the display type of the timebar, supporting the following two configurations:

  • time: Displayed as a timeline, refer to Time Mode Example
  • chart: Displayed as a trend chart, at this time the data configuration item under timebar needs to pass an additional value field as chart data, refer to Chart Mode Example

Code Examples

Basic Usage

The simplest configuration method:

const graph = new Graph({
layout: { type: 'grid', cols: 5 },
plugins: [
{
type: 'timebar',
data: [
{
time: new Date('2023-08-01').getTime(),
value: 5,
},
{
time: new Date('2023-08-02').getTime(),
value: 10,
},
{
time: new Date('2023-08-03').getTime(),
value: 15,
},
],
},
],
data: {
nodes: [
{
id: 'node1',
label: 'Node 1',
// By default, elementTypes=['node'], so nodes need to set data.timestamp to display sequentially according to the timeline
data: {
timestamp: new Date('2023-08-01').getTime(),
},
},
{
id: 'node2',
label: 'Node 2',
data: {
timestamp: new Date('2023-08-02').getTime(),
},
},
{
id: 'node3',
label: 'Node 3',
data: {
timestamp: new Date('2023-08-03').getTime(),
},
},
],
edges: [
{
id: 'edge1',
source: 'node1',
target: 'node2',
// Scenario 1: By default, elementTypes = ['node']
// - Edges do not need to set data.timestamp, the display/hide of edges depends entirely on whether the two connected nodes are visible
// Scenario 2: If elementTypes includes 'edge', for example, elementTypes = ['node', 'edge']
// - At this time, edges must set data.timestamp, and the display of edges is controlled by it
// data: {
// timestamp: new Date('2023-08-01').getTime()
// }
},
{
id: 'edge2',
source: 'node2',
target: 'node3',
},
{
id: 'edge3',
source: 'node3',
target: 'node1',
},
],
},
});

The effect is as follows:

createGraph(
{
width: 600,
height: 400,
layout: { type: 'grid', cols: 5 },
plugins: [
{
type: 'timebar',
data: [
{
time: new Date('2023-08-01').getTime(),
value: 5,
},
{
time: new Date('2023-08-02').getTime(),
value: 10,
},
{
time: new Date('2023-08-03').getTime(),
value: 15,
},
],
},
],
data: {
nodes: [
{
id: 'node1',
label: 'Node 1',
data: {
timestamp: new Date('2023-08-01').getTime(),
},
},
{
id: 'node2',
label: 'Node 2',
data: {
timestamp: new Date('2023-08-02').getTime(),
},
},
{
id: 'node3',
label: 'Node 3',
data: {
timestamp: new Date('2023-08-03').getTime(),
},
},
],
edges: [
{
id: 'edge1',
source: 'node1',
target: 'node2',
},
{
id: 'edge2',
source: 'node2',
target: 'node3',
},
{
id: 'edge3',
source: 'node3',
target: 'node1',
},
],
},
},
{ width: 600, height: 400 },
);

Custom Styles

width, height, padding, className can customize the display effect of the timebar, but note that className only acts on the outer DOM container and cannot affect the internal Canvas rendering content of the timebar (timeline, chart, play button, etc.).

const graph = new Graph({
plugins: [
{
type: 'timebar',
className: 'custom-timebar', // Note: Since the content is Canvas rendered, CSS styles cannot affect the internal content of the timebar
width: 400, // Set timebar width
height: 80, // Set timebar height
padding: [20, 20, 10, 20], // Set padding [top, right, bottom, left]
position: 'bottom', // Keep position at the bottom
data: timeData,
// labelFormatter: (time) => {
// return new Date(time).toLocaleDateString();
// }
},
],
});

CSS can only set the style of the timebar container:

.custom-timebar {
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

The effect is as follows:

createGraph(
{
data: () => {
return {
nodes: [
{
id: 'node1',
style: { x: 100, y: 100, label: 'Node 1' },
data: {
timestamp: new Date('2023-08-01').getTime(),
},
},
{
id: 'node2',
style: { x: 200, y: 100, label: 'Node 2' },
data: {
timestamp: new Date('2023-08-01').getTime() + 3600 * 24 * 1000,
},
},
{
id: 'node3',
style: { x: 150, y: 200, label: 'Node 3' },
data: {
timestamp: new Date('2023-08-01').getTime() + 3600 * 24 * 1000 * 2,
},
},
],
edges: [
{ id: 'edge1', source: 'node1', target: 'node2' },
{ id: 'edge2', source: 'node2', target: 'node3' },
{ id: 'edge3', source: 'node3', target: 'node1' },
],
};
},
node: {
style: {
size: 20,
label: true,
},
},
edge: {
style: {
stroke: '#91d5ff',
lineWidth: 1,
},
},
plugins: [
{
type: 'timebar',
className: 'custom-timebar',
width: 400,
height: 80,
padding: [20, 20, 10, 20],
position: 'bottom',
data: [
{
time: new Date('2023-08-01').getTime(),
value: 5,
},
{
time: new Date('2023-08-01').getTime() + 3600 * 24 * 1000,
value: 10,
},
{
time: new Date('2023-08-01').getTime() + 3600 * 24 * 1000 * 2,
value: 15,
},
],
labelFormatter: (time) => {
return new Date(time).toLocaleDateString();
},
},
],
},
{ width: 600, height: 400 },
(gui, graph) => {
gui?.hide();
const style = document.createElement('style');
style.innerHTML = `
.custom-timebar {
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
`;
document.head.appendChild(style);
},
);

Real Cases

  • Time Mode
  • Chart Mode