It is a project showing use cases of echarts-react-wrapper npm package for embedding Apache ECharts charts in a React application.
npm install echarts-wrapper-react
npm install echarts
Prop | Type | Description | Default | Example |
---|---|---|---|---|
option (required) | EChartsOption | The ECharts option configuration object. Refer to the ECharts documentation for more details. | N/A | Example |
theme | string | object | Theme configuration for ECharts. This can be either a string representing the theme name like "dark" or "light" or an object defining the theme. | N/A | |
opts | EChartsInitOpts | Additional options for initializing ECharts, such as devicePixelRatio and renderer. | N/A | |
autoResize | boolean | Determines whether the chart should automatically resize when the window is resized. | true | |
onEvents | EChartsReactComponentProps["onEvents"] | Event handlers for ECharts events. Each key represents an event type, and the corresponding value is a function that handles the event. | N/A | Example |
width | PixelValue | Width of the chart. Accepts a string representing a CSS pixel value. | N/A | |
height | PixelValue | Height of the chart. Accepts a string representing a CSS pixel value. | N/A | |
loadingType | string | Type of loading animation for ECharts like "default". | N/A | |
loadingOption | object | Configuration options for the loading inside showLoading, such as text, color, and maskColor. | N/A | |
notMerge | boolean | Config for ECharts, default is false. | false | |
lazyUpdate | boolean | Config for ECharts, default is false. | false |
This example demonstrates how to use the theme prop to apply custom styling to the chart.
import { EChartsReact, EChartsOption } from 'echarts-wrapper-react';
import { registerTheme } from 'echarts';
const greenOrangeTheme = {
color: [
'#32CD32', // Lime Green
'#FFA500', // Orange
'#228B22', // Forest Green
'#FF8C00', // Dark Orange
'#006400', // Dark Green
'#FF4500', // Orange Red
'#ADFF2F', // Green Yellow
'#FF6347', // Tomato
],
backgroundColor: '#F0FFF0', // Honeydew background
textStyle: {
color: '#228B22', // Forest Green text
},
};
registerTheme('greenOrangeTheme', greenOrangeTheme);
//define option
return (
<div style={{ width: '50vw', height: '50vh' }}>
<EChartsReact option={option} theme="greenOrangeTheme" />
</div>
)
You can customize the theme using the ECharts Theme Builder.
You can use "dark" and "light" themes as well.
import { EChartsReact, EChartsOption, EChartsReactComponentProps } from 'echarts-wrapper-react';
const BasicLineChart = () => {
//define option
const opts: EChartsReactComponentProps['opts'] = {
devicePixelRatio: 2,
renderer: 'svg',
};
return (
<div style={{ width: '50vw', height: '50vh' }}>
<EChartsReact option={option} opts={opts} />
</div>
);
};