logo

G

  • Tutorials
  • API
  • Examples
  • Plugins
  • Productsantv logo arrow
  • 6.1.26
  • Getting Started
  • Section I - Defining the Scenario
  • Section II - Using the renderer
  • Section III - Adding some interaction
  • Diving Deeper
    • Scene Graph
    • 创造一个“太阳系”
    • 使用相机
    • 使用插件
    • 实现一个简单的动画
    • GPGPU 初体验
    • 进入 3D 世界
    • 使用 Box2D 物理引擎
    • 使用 matter.js 物理引擎
    • 使用 Yoga 布局引擎
    • Takeover D3's rendering
    • Takeover Observable Plot's rendering
    • Choose a renderer
    • Rendering on demand
  • Advanced Topics
    • 性能优化
    • 自定义图形
    • 理解事件传播路径
    • Using react-g
    • Exporting the contents of the canvas
    • Using lite version

Takeover Observable Plot's rendering

Previous
Takeover D3's rendering
Next
Choose a renderer

Resource

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-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

In the previous section we showed How to take over the rendering of D3, and we can do the same for other SVG-based diagram libraries. Observable Plot is a good example.

The chart library also supports passing document objects to plot(), and we pass G's Document object to.

import * as Plot from '@observablehq/plot';
import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
const canvasRenderer = new Renderer();
const canvas = new Canvas({
container: 'container',
width: 640,
height: 400,
renderer: canvasRenderer,
});
const chart = Plot.dot(data, {
x: 'weight',
y: 'height',
stroke: 'sex',
}).plot({
// Pass in our Document object instead of `window.document`
document: canvas.document,
});

It's worth mentioning that we don't need to call canvas.appendChild() manually to add the chart to the canvas, Observable Plot does that internally.

DEMO in Codesandbox

The top half of the figure below shows the rendering of the Observable Plot native SVG, and the bottom half shows the drawing using g-canvas.

observablehq plot

Also thanks to taking over the rendering layer, we can use a plugin like g-plugin-rough-canvas-renderer for hand-drawn style transformation.

DEMO in Codesandbox

sketchy plot