Skip to main content

Chart

An ECharts wrapper component with React integration, theme support, and chart linking.

VEF-specific component. Wraps Apache ECharts via echarts-for-react.

When to Use

  • Render any ECharts chart (line, bar, pie, scatter, etc.) in a React component.
  • Link multiple charts to synchronize tooltips and data zoom.

Basic Usage

import { Chart } from '@vef-framework-react/components';
import type { ChartOption } from '@vef-framework-react/components';

const option: ChartOption = {
xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] },
yAxis: { type: 'value' },
series: [{ type: 'bar', data: [120, 200, 150, 80, 70] }],
};

export default function Demo() {
return <Chart option={option} style={{ height: 300 }} />;
}

With Theme

<Chart
option={option}
theme="walden"
style={{ height: 300 }}
/>

Built-in themes: "walden", "wonderland". You can also pass a custom ECharts theme object.

Loading State

<Chart option={option} loading={isLoading} style={{ height: 300 }} />

Using useChart Hook

For imperative access to the ECharts instance:

import { useChart } from '@vef-framework-react/components';
import type { ChartOption } from '@vef-framework-react/components';

const option: ChartOption = { /* ... */ };

export default function Demo() {
const ref = useChart({
option,
onReady: (chart) => {
chart.on('click', (params) => console.log(params));
},
});

return <div ref={ref} style={{ height: 300 }} />;
}

Linked Charts

import { Chart, connectCharts, disconnectCharts } from '@vef-framework-react/components';
import { useEffect } from 'react';

export default function Demo() {
useEffect(() => {
connectCharts('dashboard-group');
return () => disconnectCharts('dashboard-group');
}, []);

return (
<>
<Chart option={option1} group="dashboard-group" style={{ height: 200 }} />
<Chart option={option2} group="dashboard-group" style={{ height: 200 }} />
</>
);
}

API

ChartProps

PropTypeDefaultDescription
optionEChartsOptionrequiredECharts option configuration
theme'walden' | 'wonderland' | objectChart theme
loadingbooleanfalseShow loading overlay
widthnumber | 'auto''auto'Chart width
heightnumber | 'auto''auto'Chart height
groupstringGroup name for linked charts
deepMemobooleanfalseDeep comparison for option memoization
renderer'canvas' | 'svg''canvas'Rendering mode
onReady(chart: ECharts) => voidCalled when chart is initialized
onBeforeDispose(chart: ECharts) => voidCalled before chart is disposed
classNamestringCSS class
styleCSSPropertiesInline style

useChart(options)

Returns a RefObject<HTMLDivElement> to attach to a container div. Accepts all ChartProps fields.

connectCharts(group) / disconnectCharts(group)

Connect/disconnect charts in the same group for synchronized interactions.

Best Practices

  • Always set an explicit height via style — ECharts needs a bounded container.
  • Use loading to show a loading state while fetching chart data.
  • Use group + connectCharts to synchronize tooltips across multiple charts on a dashboard.