Ant Design Charts

A React Chart Library

README

@ant-design/charts



A React chart library, based on G2Plot, G6, X6, L7Plot.

build
npm
npm GitHub stars npm License

WebsiteQuick StartGalleryFAQBlog


Case


Statistical charts


Flowchart


Maps


Relation Graphs


✨ Features


- Easy to use
- TypeScript
- Pretty & Lightweight
- Responsive
- Storytelling

📦 Installation


  1. ``` sh | pure
  2. $ npm install @ant-design/charts
  3. ```

🔨 Usage


  1. ```tsx | pure
  2. import React from 'react';
  3. import { Line } from '@ant-design/charts';

  4. const Page: React.FC = () => {
  5.   const data = [
  6.     { year: '1991', value: 3 },
  7.     { year: '1992', value: 4 },
  8.     { year: '1993', value: 3.5 },
  9.     { year: '1994', value: 5 },
  10.     { year: '1995', value: 4.9 },
  11.     { year: '1996', value: 6 },
  12.     { year: '1997', value: 7 },
  13.     { year: '1998', value: 9 },
  14.     { year: '1999', value: 13 },
  15.   ];

  16.   const config = {
  17.     data,
  18.     width: 800,
  19.     height: 400,
  20.     autoFit: false,
  21.     xField: 'year',
  22.     yField: 'value',
  23.     point: {
  24.       size: 5,
  25.       shape: 'diamond',
  26.     },
  27.     label: {
  28.       style: {
  29.         fill: '#aaa',
  30.       },
  31.     },
  32.   };

  33.   let chart;

  34.   // Export Image
  35.   const downloadImage = () => {
  36.     chart?.downloadImage();
  37.   };

  38.   // Get chart base64 string
  39.   const toDataURL = () => {
  40.     console.log(chart?.toDataURL());
  41.   };

  42.   return (
  43.     <div>
  44.       <button type="button" onClick={downloadImage} style={{ marginRight: 24 }}>
  45.         Export Image
  46.       </button>
  47.       <button type="button" onClick={toDataURL}>
  48.         Get base64
  49.       </button>
  50.       <Line {...config} onReady={(chartInstance) => (chart = chartInstance)} />
  51.     </div>
  52.   );
  53. };
  54. export default Page;
  55. ```

Preview


📜 Document & API


See chart API for details. Common props:

| Property | Description | Type | defaultValue |
| :--- | :--- | :--- | :--- |
| onReady | chart loaded callback | (chart)=> void | - |
| onEvent | chart events | (chart, event)=> void | - |
| loading | loading status | boolean | - |
| loadingTemplate | loading template | React.ReactElement | - |
| errorTemplate | custom error template | (e: Error) => React.ReactNode | - |
| className | container class | string | - |
| style | container style | React.CSSProperties | - |

🤝 How to Contribute


Your contributions are always welcome! Please Do have a look at the issues first.

📧 Contact us


DingTalk group number: 44788198 .


License


MIT