0.0.9 • Published 8 months ago

react-use-echarts v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

react-use-echarts

NPM version NPM downloads GitHub Actions Workflow Status GitHub issues GitHub pull requests GitHub license

A powerful React hooks library for Apache ECharts, making it easy to use ECharts in your React applications with minimal boilerplate.

✨ Features

  • 🎨 Easy to use - Simple and intuitive API with React Hooks
  • 🚀 TypeScript support - Written in TypeScript with complete type definitions
  • 📦 Lightweight - Zero dependencies except for React and ECharts
  • 🛠 Flexible - Full access to ECharts instance and options
  • Auto-updating - Automatically updates chart when data or options change
  • 📱 Responsive - Handles container resizing automatically

📦 Installation

# Using npm
npm install react-use-echarts echarts

# Using yarn
yarn add react-use-echarts echarts

# Using pnpm
pnpm add react-use-echarts echarts

🔨 Usage

import { useEcharts, UseEchartsOptions } from 'react-use-echarts';

function MyChart() {
  const options: UseEchartsOptions['option'] = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: 'line'
    }]
  };

  const { chartRef } = useEcharts({
    option: options
  });

  return <div ref={chartRef} style={{ width: '100%', height: '300px' }} />;
}

📖 API

useEcharts

The main hook for using ECharts in React components.

const { chartRef, setOption, getInstance } = useEcharts({
  option: UseEchartsOptions['option'];      // ECharts options configuration (required)
  theme?: string | object;    // ECharts theme name or configuration
  notMerge?: boolean;        // Whether to not merge with previous options
  lazyUpdate?: boolean;      // Whether to update chart lazily
  showLoading?: boolean;     // Whether to display loading animation
  loadingOption?: object;    // Loading animation configuration
  onEvents?: {              // Event handlers
    [eventName: string]: {
      handler: (params: any) => void;
      query?: string | object;
      context?: object;
    }
  }
});

Returns

  • chartRef: Ref object to attach to the chart container
  • setOption: Function to update chart options
  • getInstance: Function to get the ECharts instance (available after component mounts)

🤝 Contributing

We welcome all contributions. Please read our contributing guidelines first. You can submit any ideas as pull requests or as GitHub issues.

📝 Changelog

Detailed changes for each release are documented in the release notes.

📄 License

MIT © chin

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago

0.0.0

12 months ago