AntV Infographic
Home
Learn
Reference
Gallery
Icon
Editor
AI
Enterprise
  • 快速开始
    • 入门指南
    • 信息图语法
  • 核心概念
    • 设计
    • 模版
    • 数据
    • 主题
    • 资源
  • 自定义设计
    • 自定义结构
    • 自定义数据项
    • 自定义模版
    • 自定义主题
    • 自定义色板
    • 自定义字体
    • 自定义资源加载器
    • 自定义图案
  • 信息图理论
    • 信息图分类
    • 核心理论
    • 信息图构成要素
    • 信息图设计
  • 参与贡献
文档
自定义设计

自定义色板

如果你不了解色板的概念,可以查看核心概念-主题-色板

通过 registerPalette 方法可以注册自定义色板,从而在信息图中使用。

JS
import {registerPalette, Infographic} from '@antv/infographic'; // 注册离散色板,即一个颜色字符串数组 registerPalette('discrete-palette', ['#FF356A', '#7BC9FF', '#FFD166']); // 注册连续色板,即一个返回颜色字符串的函数 registerPalette('continuous-palette', (ratio) => { const r = Math.round(255 * ratio); const g = Math.round(200 * (1 - ratio)); const b = 150; return `rgb(${r}, ${g}, ${b})`; }); const infographic = new Infographic({ // 其他配置项... }); infographic.render(` theme palette discrete-palette `);

自定义色板适用于品牌配色或特定业务配色,注册后即可在 themeConfig.palette 中按名称使用。

Previous自定义主题
Next自定义字体

AntV Infographic
Copyright © Ant Group Co.
Docs
Quick Start
Core Concepts
Custom Design
Infographic Theory
API Reference
JSX
API
Design Assets
More
More Examples
AI Generated Infographics
GitHub
Contribute
Friendly Links
AntV
G2
G6
L7
JS
import {registerPalette, Infographic} from '@antv/infographic';

// 注册离散色板,即一个颜色字符串数组
registerPalette('discrete-palette', ['#FF356A', '#7BC9FF', '#FFD166']);

// 注册连续色板,即一个返回颜色字符串的函数
registerPalette('continuous-palette', (ratio) => {
const r = Math.round(255 * ratio);
const g = Math.round(200 * (1 - ratio));
const b = 150;
return `rgb(${r}, ${g}, ${b})`;
});

const infographic = new Infographic({
// 其他配置项...
});

infographic.render(`
theme
palette discrete-palette
`);