适用于源力设计的主题
安装和使用 VChart
在 React 工程中,可以使用以下命令安装 react-vchart:
# 使用 npm 安装 npm install @visactor/react-vchart # 使用 yarn 安装 yarn add @visactor/react-vchart
绘制图表以及更详细的指引详见:https://visactor.io/vchart/guide/tutorial_docs/Cross-terminal_and_Developer_Ecology/react
适用于源力设计的图表主题包
为了使 VChart 在源力页面环境中获得更好的体验,VisActor 额外推出了 @visactor/vchart-ve-o-theme 主题包。这个包有以下特性:
-
开箱即用:经过简单的配置,就可以使 VChart 样式自动融入源力设计语言,自动适配 Arco 系的主题包。
-
响应式:
@visactor/vchart-ve-o-theme支持监听页面上的亮暗模式变化,自动对页面上的 VChart 图表的主题进行热更新。
DEMO
完整 demo 请访问此页面。

安装
https://www.npmjs.com/package/@visactor/vchart-ve-o-theme
# npm npm install @visactor/vchart-ve-o-theme # yarn yarn add @visactor/vchart-ve-o-theme
基本使用
实现默认的功能,只需要在全局执行一次 initVChartVeOTheme 方法进行初始化。这个语句通常可以放在 react 项目的入口文件中。如以下示例:
import React from 'react'; import { createRoot } from 'react-dom/client'; import App from './app.jsx'; import { initVChartVeOTheme } from '@visactor/vchart-ve-o-theme'; // initialization initVChartVeOTheme(); const dom = document.querySelector('#root'); const root = createRoot(dom); root.render(<App />);
initVChartVeOTheme 方法支持传入一个对象作为 option,其类型声明为:
interface IInitVChartVeOThemeOption { /** 初始亮暗色模式 */ defaultMode?: 'light' | 'dark'; /** 是否监听亮暗色模式自动更改图表主题,默认为 true */ isWatchingMode?: boolean; /** arco css 变量前缀,例如:原始变量名为 --color-data-1,配置为 "arco" 后变为 --arco-color-data-1 */ prefix?: string; /** 指定 ThemeManager,一般不用指定,如果遇到多版本 vchart 共存时需要指定 */ themeManager?: typeof ThemeManager; /** 指定初始的数据色板 */ colorScheme?: ColorSchemeType | string; }
高级功能
以下将依次介绍 @visactor/vchart-ve-o-theme 主题包内置的其他功能。
默认色板 + 行业色板
@visactor/vchart-ve-o-theme 支持 8 套数据色板,分别为:
default- 默认色板(和默认 VChart 一致)finance- 金融行业色板government- 政府行业色板consumer- 大消费行业色板automobile- 汽车行业色板culturalTourism- 文旅行业色板medical- 医疗行业色板newEnergy- 新能源行业色板
可在 demo 中(https://www.visactor.io/vchart/theme/demo/veo)通过下拉框切换色板进行预览。
主题包提供了这些数据色板的初始化和切换的功能。在使用上,除了可以在上文提到的初始化参数 option 中配置 colorScheme,也可以对数据色板进行热更新。示例如下:
// init once globally const helper = initVChartVeOTheme(); // some your codes... (eg. init charts) // change the current color scheme helper.switchVChartColorScheme('finance');
应用 finance 色板的图表如下图所示:
