@visactor/vchart-ve-o-theme
v1.12.2
Published
Extended themes for VChart
Downloads
492
Maintainers
Keywords
Readme
@visactor/vchart-ve-o-theme
Description
The extension O Design themes for VChart.
Installing and Using VChart
In React projects, you can use the following command to install react-vchart:
# npm
npm install @visactor/react-vchart
# yarn
yarn add @visactor/react-vchart
The method of drawing charts and more detailed guidance can be found in this tutorial.
Chart Theme Package for O Design
In order to provide a better experience for VChart in the O Design page environment, VisActor has launched an additional theme package called @visactor/vchart-ve-o-theme
. This package has the following features:
- Ready to use out of the box: With simple configuration, VChart styles can be automatically integrated into the O Design language and also automatically adapted to theme packages customized by users based on Arco.
- Responsive:
@visactor/vchart-ve-o-theme
supports listening for changes of light/dark mode and CSS variable update on the page, and automatically updates the theme of the charts on the page.
DEMO
For a complete demo, please visit the this page.
Installation
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
Usage
To access the default functionality, simply execute the initVChartVeOTheme
method once globally for initialization. This statement can usually be placed in the entry file of a React project. As an example:
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 />);
The initVChartVeOTheme
method supports passing in an object as a parameter, whose type declaration is:
interface IInitVChartVeOThemeOption {
/** Initial light/dark mode */
defaultMode?: 'light' | 'dark';
/** Whether to listen for the light/dark mode switching and automatically change the chart theme. The default setting is true */
isWatchingMode?: boolean;
/** Specify a ThemeManager, usually not specified. If multiple versions of vchart coexist, it needs to be specified */
themeManager?: typeof ThemeManager;
/** The initial color palette type, with a default value of 'default' */
colorScheme?: ColorSchemeType | string;
}
Advanced Features
The following will introduce the other built-in features of the @visactor/vchart-ve-o-theme
package in sequence.
Default Color Palette & Industry Color Palette
@visactor/vchart-ve-o-theme
supports 8 sets of data color palettes, namely:
default
- Default color palette (consistent with VChart)finance
- Color palette for financial industrygovernment
- Color palette for government industryconsumer
- Color palette for major consumer industriesautomobile
- Color palette for the automotive industryculturalTourism
- Color palette for the cultural and tourism industrymedical
- Color palette for medical industrynewEnergy
- Color palette for the new energy industry
You can preview by switching color palettes through the dropdown menu in the demo (https://www.visactor.io/vchart/theme/demo/veo).
The theme pack provides initialization and switching functions for these data palettes. In terms of usage, in addition to configuring colorScheme
in the initialization parameter options mentioned earlier, it is also possible to perform hot updates on the data palette. An example is as follows:
// init once globally
const helper = initVChartVeOTheme();
// some your codes... (eg. init charts)
// change the current color scheme
helper.switchVChartColorScheme('finance');
Bar Chart Interaction Plugin
In O Design system, the bar chart elements have the following two default interaction effects:
- When hovering over a bar element with the mouse, highlight all elements in the same group
- Circular markers appear at the edges of the bar elements hovered over by the mouse
The theme package provides a chart plugin to achieve this customized interactive effect. The following functions need to be run globally once (usually placed in the entry file of the React project) to automatically add this interaction to all bar charts:
import { registerBarMarker } from '@visactor/vchart-ve-o-theme';
// initialization
registerBarMarker();
Built in Shapes and Colors
The theme package has customized special legend shapes for VChart (which can also be used with tooltips):
The shape declaration is in the VeOSymbolType
constant of the theme package. Contains the following shape types:
VeOSymbolType.roundSpuare
:Rounded rectangleVeOSymbolType.line
:Short horizontal lineVeOSymbolType.linePoint
:Short horizontal line overlapping circleVeOSymbolType.linePointHollow
:Short horizontal line superimposed with hollow circleVeOSymbolType.lineDash
:Short dashed lineVeOSymbolType.triangleUp
:Upward triangle (used to label lines)VeOSymbolType.triangleDown
:Downward triangle (used to label lines)
The following example shows changing the legend and tooltip shape to VeOSymbolType.linePoint
in a line chart:
const spec = {
type: 'area',
data: {
values: [
{ type: 'Nail polish', country: 'Africa', value: 4229 },
{ type: 'Nail polish', country: 'EU', value: 4376 },
{ type: 'Nail polish', country: 'China', value: 3054 },
{ type: 'Eyebrow pencil', country: 'Africa', value: 3932 },
{ type: 'Eyebrow pencil', country: 'EU', value: 3987 },
{ type: 'Eyebrow pencil', country: 'China', value: 5067 },
{ type: 'Rouge', country: 'Africa', value: 5221 },
{ type: 'Rouge', country: 'EU', value: 3574 },
{ type: 'Rouge', country: 'China', value: 7004 },
{ type: 'Lipstick', country: 'Africa', value: 9256 },
{ type: 'Lipstick', country: 'EU', value: 4376 },
{ type: 'Lipstick', country: 'China', value: 9054 },
{ type: 'Eyeshadows', country: 'Africa', value: 3308 },
{ type: 'Eyeshadows', country: 'EU', value: 4572 },
{ type: 'Eyeshadows', country: 'China', value: 12043 },
{ type: 'Eyeliner', country: 'Africa', value: 5432 },
{ type: 'Eyeliner', country: 'EU', value: 3417 },
{ type: 'Eyeliner', country: 'China', value: 15067 },
{ type: 'Foundation', country: 'Africa', value: 13701 },
{ type: 'Foundation', country: 'EU', value: 5231 },
{ type: 'Foundation', country: 'China', value: 10119 },
{ type: 'Lip gloss', country: 'Africa', value: 4008 },
{ type: 'Lip gloss', country: 'EU', value: 4572 },
{ type: 'Lip gloss', country: 'China', value: 12043 },
{ type: 'Mascara', country: 'Africa', value: 18712 },
{ type: 'Mascara', country: 'EU', value: 6134 },
{ type: 'Mascara', country: 'China', value: 10419 }
]
},
stack: true,
xField: 'type',
yField: 'value',
seriesField: 'country',
legends: [
{
visible: true,
item: {
shape: { style: { symbolType: VeOSymbolType.linePoint } }
}
}
],
tooltip: {
visible: true,
style: {
shape: {
shapeType: VeOSymbolType.linePoint
}
}
}
};
The theme package also includes 5 colors that represent different levels of urgency, declare as a VeOColor
constant, using the same method as VeOSymbolType
.
export const VeOColor = {
/** 致命 */
fatal: '#7E0C06',
/** 高危、不健康 */
critical: '#D7312A',
/** 中危、警告 */
warning: '#EF7D2E',
/** 低危,提示 */
notice: '#F0A50F',
/** 安全,健康 */
safe: '#309256'
};
Static resources
This package contains both static theme JSON resources, which can be used on demand.
- veODesignLight O Design - light
- veODesignLightFinance O Design - light - 金融行业色板
- veODesignLightGovernment O Design - light - 政府行业色板
- veODesignLightConsumer O Design - light - 大消费行业色板
- veODesignLightAutomobile O Design - light - 汽车行业色板
- veODesignLightCulturalTourism O Design - light - 文旅行业色板
- veODesignLightMedical O Design - light - 医疗行业色板
- veODesignLightNewEnergy O Design - light - 新能源行业色板
- veODesignDark O Design - dark
- veODesignDarkFinance O Design - dark - 金融行业色板
- veODesignDarkGovernment O Design - dark - 政府行业色板
- veODesignDarkConsumer O Design - dark - 大消费行业色板
- veODesignDarkAutomobile O Design - dark - 汽车行业色板
- veODesignDarkCulturalTourism O Design - dark - 文旅行业色板
- veODesignDarkMedical O Design - dark - 医疗行业色板
- veODesignDarkNewEnergy O Design - dark - 新能源行业色板
When in use, directly reference the corresponding JSON file of the theme from the package, and only need to execute it globally once:
import ttPlatformLight from '@visactor/vchart-ve-o-theme/public/veODesignLight.json';
import VChart from '@visactor/vchart';
// register the theme
VChart.ThemeManager.registerTheme('veODesignLight', veODesignLight);
// apply the theme
VChart.ThemeManager.setCurrentTheme('veODesignLight');
Debug
Run the following command from any location in the project to start the dev server:
rush veo