ReactJS : Simple way to use Echart in React


In this tutorial, we’ll show you how to implement ECharts in a React application to create beautiful, interactive data visualizations. I’ve been experimenting with various JavaScript charting libraries, and ECharts has quickly become one of my favorites. It strikes a great balance between simplicity and flexibility, making it an excellent choice for frontend developers. The library is well-documented, offers plenty of sample configurations, and is relatively easy to set up in a React project. Since ECharts is Canvas-based, styling with CSS is limited—but it still allows a high level of visual customization through its rich configuration options. Everything I’ve needed to do so far has been fully achievable with ECharts.


Let’s Get Started — The Easy Way

Getting started with ECharts in React is simpler than you might think.

React is a free and open-source JavaScript library for building fast, efficient, and dynamic user interfaces or UI components. It’s widely used for creating scalable frontend applications.

On the other hand, ECharts is a powerful, open-source JavaScript charting library developed by Apache. It allows developers to build interactive, highly customizable, and visually appealing charts with ease. Whether you're working on dashboards, reports, or data-driven UIs, ECharts is a fantastic tool to bring your data to life.

First, install ECharts and the React wrapper

npm install echarts echarts-for-react

Build Your First Bar Chart

import React from "react";

import ReactEcharts from "echarts-for-react";


function App() {

  const option = {

    tooltip: {},

    xAxis: {

      type: 'category',

      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

    },

    yAxis: { type: 'value' },

    series: [

      {

        data: [120, 200, 150, 80, 70, 110, 130],

        type: 'bar',

        showBackground: true,

        backgroundStyle: { color: 'rgba(180,180,180,0.2)' },

        label: { show: true, position: 'top' },

      }

    ]

  };


  return <ReactEcharts option={option} style={{ height: '400px' }} />;

}


export default App;


Now, go back to your browser



The full source code for this project can be found here

For more interesting topics and hands-on guides, check out my other blog posts and keep levelling up your frontend skills!

Comments

Popular posts from this blog

How to Format Numbers with Commas and Decimals in JavaScript

React Hooks in Modern Web Development