echarts-for-react is a robust and widely-used React component that seamlessly integrates Apache ECharts, a powerful charting library, into React applications. It provides a declarative way to render various types of charts and visualizations, abstracting away direct ECharts instance management. The current stable version is 3.0.6. The project maintains an active development pace with frequent minor updates and bug fixes, building upon the significant v3.0.0 release that introduced ECharts v5 support and a full TypeScript rewrite. Key differentiators include its simplicity, direct exposure of ECharts options as React props, comprehensive TypeScript support, and the ability to manually import ECharts modules for bundle size optimization, making it a preferred choice for React developers needing advanced data visualization.
npm install echarts-for-reactVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a functional React component rendering a basic ECharts bar chart. It shows how to define chart options, handle chart readiness and events, and access the ECharts instance for manual operations like resizing. It also includes the necessary ECharts module imports and registration for best practice.
Review your code for TypeScript compatibility. Ensure ECharts peer dependency is at least `^3.0.0`, with `^5.0.0` or `^6.0.0` recommended to align with modern ECharts features and `echarts-for-react` capabilities. Migrate to TypeScript if possible for better type safety.
Use `import ReactEChartsCore from 'echarts-for-react/lib/core';` and manually import only the required charts, components, and renderers from `echarts/charts`, `echarts/components`, and `echarts/renderers`. Then, register them using `echarts.use([...])`.
Ensure `echarts` is installed in your project: `npm install echarts` or `yarn add echarts`.
Obtain the ECharts instance (e.g., via the `onChartReady` callback or a React `ref`) and call `instance.resize()` whenever the container's size changes. Consider using a `ResizeObserver` for robust detection of DOM element dimension changes.
Install `echarts` in your project: `npm install echarts` or `yarn add echarts`. Verify that it's correctly listed in your `package.json`.
Ensure `echarts-for-react` is `v3.0.0` or higher, and `echarts` is also up-to-date (e.g., `^5.0.0` or `^6.0.0`). Check your `tsconfig.json` for correct module resolution and ensure `EChartsOption` type is imported if explicitly used.
Manually import all required ECharts components, charts, and renderers (e.g., `GridComponent`, `BarChart`, `CanvasRenderer`) from their respective `echarts/components`, `echarts/charts`, and `echarts/renderers` paths, then register them using `echarts.use([Component1, ChartType1, ...])`.