# echarts-for-react Guide: Setup, Examples & Interactive React Charts
– Typical top results: the official Apache ECharts docs, the echarts-for-react GitHub repo, npm package pages, short tutorials (Dev.to, Medium, personal blogs), example/demo pages, and StackOverflow threads.
– Dominant user intents:
– Informational: “how to use”, “examples”, “options”, “events”.
– Transactional/Commercial: “chart library”, “React chart library”, “which to choose”.
– Navigational: landing on GitHub repo, docs, npm.
– Mixed: “echarts-for-react tutorial” results combine installation + example + code.
– Competitor content structure: most pages cover setup + minimal example + props; few go deep on events, performance, TypeScript, advanced customization or dashboard patterns. That gap is your opportunity: produce a single authoritative walk‑through covering installation, API patterns, events, state updates, TypeScript tips, and dashboard composition.
Why it matters for SEO:
– Featured snippets and People Also Ask expect concise “How to” steps and short code lines.
– Voice search favors question/answer blocks like “How do I install…” and “How do I handle events…”.
– Long-form posts that include code examples, practical gotchas, and a short FAQ perform well for both organic and snippet visibility.
- echarts-for-react
- React ECharts
- echarts-for-react tutorial
- React Apache ECharts
- echarts-for-react installation
- React interactive charts
- echarts-for-react example
- React data visualization
- echarts-for-react setup
- React chart library
- echarts-for-react customization
- React ECharts dashboard
- echarts-for-react events
- React chart component
- echarts-for-react getting started
Secondary / mid-frequency (intent-rich) queries:
- install echarts-for-react npm
- use echarts in react
- react-echarts vs recharts
- echarts-for-react typescript example
- echarts-for-react setOption update data
- echarts-resize react useRef
- echarts-for-react onEvents example
- apache echarts react integration
- interactive charts react tutorial
LSI / related phrases:
- charting library
- data visualization React
- tooltip formatter
- series options
- responsive charts
- performance large datasets
- server side rendering (SSR) and echarts
Intent clusters:
– Getting started / setup: “installation”, “getting started”, “setup”, “example”.
– Usage & customization: “customization”, “tooltip formatter”, “legend”, “responsive”.
– Interactivity & events: “events”, “onEvents”, “click handler”, “toolbox”.
– Integration & architecture: “dashboard”, “state updates”, “TypeScript”, “SSR”.
Collected candidate questions:
1. How to install echarts-for-react?
2. How to update chart data in echarts-for-react?
3. How to handle click and other events in echarts-for-react?
4. Does echarts-for-react support TypeScript?
5. How to make echarts responsive in React?
6. How to customize tooltips and formatters?
7. Is echarts-for-react actively maintained?
8. How to build a dashboard with multiple echarts components?
9. How to improve performance with many points?
10. How to integrate echarts-for-react with Redux or hooks?
Top 3 for final FAQ (most actionable / high snippet potential):
– How to install echarts-for-react?
– How to update chart data in echarts-for-react?
– How to handle click events in echarts-for-react?
Note: code examples are concise—copy, paste, adapt.
### Quick summary (TL;DR)
echarts-for-react is a thin React wrapper around Apache ECharts. Install both ECharts and the wrapper, mount a ReactECharts component with an option object, and wire events via the wrapper’s onEvents prop or ref. Good for interactive, performant charts and full control over options.
### Installation & setup
To start, install ECharts plus the wrapper. The wrapper doesn’t ship ECharts to keep bundle size explicit.
“`bash
# npm
npm install echarts echarts-for-react
# or yarn
yarn add echarts echarts-for-react
“`
Import and render a basic chart. The minimal pattern is straightforward: import the wrapper, pass a configured options object, and keep the options in state if you plan to update data.
A practical pattern uses React hooks and refs. Use the wrapper’s forwarded ref to call chart methods (like resize or dispatchAction) when you need imperative control. This is handy when dealing with window resize, external controls, or exporting chart images.
For more in-depth step-by-step setup and a beginner tutorial, see this community walkthrough: echarts-for-react tutorial.
ECharts centers on a single “option” object that describes series, axes, legends, tooltips, and more. The wrapper simply passes this option to the underlying chart instance (echarts.setOption).
– Keep the options immutable when sensible: create new option objects on significant changes to help React diffing and avoid odd merge behavior.
– For streaming or frequent updates, update only the series data and call setOption with notMerge=false or use setOption with replaceMerge, depending on desired behavior.
A minimal option for a line chart looks like:
“`js
const option = {
xAxis: { type: ‘category’, data: [‘Mon’,’Tue’,’Wed’] },
yAxis: { type: ‘value’ },
series: [{ type: ‘line’, data: [120, 200, 150] }]
};
“`
If you intend to support multiple themes or tree shaking, import only the charts and components you need from ECharts (for custom builds), which helps bundle size.
Interactivity is where ECharts shines: toolboxes, brushing, dataZoom, and events. The wrapper exposes an onEvents prop (an object mapping event names to handlers) and also allows direct access via ref (chartInstance.getEchartsInstance()).
To handle clicks:
“`jsx
const onChartClick = (params) => {
console.log(‘clicked series’, params.seriesName, params.data);
};
“`
Use the ref for imperative actions (dispatchAction, getDataURL, resize). For complex dashboards, coordinate charts by dispatching actions from one chart to another (brush/selection sync).
Practical tips:
– Debounce heavy handlers.
– For keyboard/ARIA accessibility, expose controls outside the chart and call dispatchAction programmatically.
– Use dataZoom for client-side filtering; for huge datasets, perform server-side aggregation then re-render.
Customization is all in the option: formatter callbacks, rich text, axis tick formatting, and custom series. Themes can be provided at init time or by loading a theme object.
TypeScript integrations:
– The wrapper has community type definitions. For stronger typing, install @types or use the upstream types from the project’s repo.
– Annotate the option as echarts.EChartsOption (if types are available in your environment).
– Use React.RefObject to access the instance: (ref.current.getEchartsInstance() as echarts.ECharts).
A few gotchas:
– Server-side rendering: ECharts expects browser APIs. Condition rendering using dynamic import or render only on client.
– Bundle size: importing all of echarts bundles everything. Use ECharts custom bundling to import only necessary charts/components if size matters.
For dashboards with multiple charts, structure state and updates carefully:
1. Keep chart options as derived state from a canonical “data model” to avoid desynced charts.
2. Centralize shared interactions (filters, date ranges) in parent components or a store (React Context, Redux).
3. Use refs for cross-chart imperative actions (e.g., highlight selected series in other charts via dispatchAction).
Suggested architecture:
– Parent holds the dataset and UI state.
– Child chart components accept options and small event handlers.
– For heavy datasets, paginate or aggregate server-side; use virtualized lists for table components accompanying charts.
In short: treat charts as view components; keep data logic separate.
– Prefer smaller option objects and update only changed fields.
– Avoid rebuilding the entire option every render—memoize with useMemo where possible.
– For very large datasets, consider WebGL-based charts or data sampling.
– Monitor bundle size and use code-splitting or dynamic imports for rare chart types.
Checklist before deploy:
– Audit bundle (bundle-analyzer).
– Confirm SSR behavior (hydrate only client-side).
– Add error boundaries around chart components to avoid full-page crashes if the chart library throws.
– Target featured snippets: short “How to install” code line and a three-step “how to update data” block.
– Voice search: include direct Q&A (see FAQ below). Use clear, short answers (one or two sentences).
– Microdata: below is an FAQ JSON‑LD ready to paste for FAQ schema (also included in a script near the end).
Q: How to install echarts-for-react?
A: Install both packages: npm install echarts echarts-for-react (or yarn add). The wrapper does not ship echarts itself, so install ECharts separately and import the wrapper in your component.
Q: How to update chart data in echarts-for-react?
A: Keep your option in React state and update the series/data arrays; pass the new option to the component. For frequent updates, use chart.setOption with appropriate merge settings or call methods via the chart ref for incremental updates.
Q: How to handle click events in echarts-for-react?
A: Use the onEvents prop: pass an object like { click: handler }. Alternatively, get the underlying instance via ref and call chartInstance.on(‘click’, handler) for more advanced needs.
Semantic core (HTML)
- Main cluster: echarts-for-react, React ECharts, echarts-for-react tutorial, React Apache ECharts, echarts-for-react installation, React interactive charts
- Examples & setup: echarts-for-react example, echarts-for-react setup, echarts-for-react getting started, install echarts-for-react npm
- Customization & events: echarts-for-react customization, echarts-for-react events, React chart component, tooltip formatter
- Advanced: React ECharts dashboard, echarts-for-react typescript example, echarts resize react, performance large datasets
- Related LSI: data visualization react, charting library, interactive charts react, responsive charts

Recent Comments