AntV
AntV Infographic
文档
参考
示例
AI
企业版
  • 快速开始
    • 入门指南
    • 信息图语法
  • 核心概念
    • 设计
    • 模版
    • 数据
    • 主题
    • 资源
  • 自定义设计
    • 自定义结构
    • 自定义数据项
    • 自定义模版
    • 自定义主题
    • 自定义色板
    • 自定义字体
    • 自定义资源加载器
    • 自定义图案
  • 信息图理论
    • 信息图分类
    • 核心理论
    • 信息图构成要素
    • 信息图设计
  • 参与贡献
    • 项目介绍
    • 开源计划
    • 贡献指南
    • 代码规范
    • 提交 PR
文档
自定义设计

自定义色板

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

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

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({ // 其他配置项... themeConfig: { palette: 'discrete-palette', // 使用自定义色板 }, });

上一章自定义主题
下一章自定义字体

AntV Infographic
Copyright © Ant Group Co.
文档
快速开始
核心概念
自定义设计
信息图理论
API 参考
JSX
API
设计资产
更多
更多示例
AI 在线体验
GitHub
参与贡献
友情链接
AntV
G2
G6
L7
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({
// 其他配置项...
themeConfig: {
palette: 'discrete-palette', // 使用自定义色板
},
});