Convert Figma logo to code with AI

ant-design logoant-design-charts

A React Chart Library

1,910
359
1,910
248

Top Related Projects

23,884

Redefined chart library built with React and D3

64,568

Simple HTML5 Charts using the <canvas> tag

108,427

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

60,384

Apache ECharts is a powerful, interactive charting and data visualization library for browser

📊 Interactive JavaScript Charts built on SVG

Quick Overview

Ant Design Charts is a React chart library based on G2Plot, providing a set of high-quality statistical charts for data visualization. It offers a wide range of chart types and is designed to work seamlessly with the Ant Design ecosystem, making it an excellent choice for React-based applications that require data visualization capabilities.

Pros

  • Easy integration with Ant Design and React applications
  • Wide variety of chart types available
  • Responsive and interactive charts out of the box
  • Customizable appearance and behavior

Cons

  • Limited documentation for advanced customization
  • Steeper learning curve compared to simpler charting libraries
  • Occasional performance issues with large datasets
  • Dependency on G2Plot may limit flexibility in some cases

Code Examples

  1. Creating a basic line chart:
import { Line } from '@ant-design/charts';

const data = [
  { year: '2015', value: 3 },
  { year: '2016', value: 4 },
  { year: '2017', value: 3.5 },
  { year: '2018', value: 5 },
  { year: '2019', value: 4.9 },
];

const LineChart = () => {
  const config = {
    data,
    xField: 'year',
    yField: 'value',
  };

  return <Line {...config} />;
};
  1. Creating a pie chart with custom colors:
import { Pie } from '@ant-design/charts';

const data = [
  { type: 'A', value: 27 },
  { type: 'B', value: 25 },
  { type: 'C', value: 18 },
  { type: 'D', value: 15 },
  { type: 'E', value: 10 },
];

const PieChart = () => {
  const config = {
    data,
    angleField: 'value',
    colorField: 'type',
    radius: 0.8,
    color: ['#1890FF', '#13C2C2', '#2FC25B', '#FACC14', '#F04864'],
  };

  return <Pie {...config} />;
};
  1. Creating an interactive bar chart:
import { Column } from '@ant-design/charts';

const data = [
  { city: 'New York', population: 8419000 },
  { city: 'Los Angeles', population: 3898000 },
  { city: 'Chicago', population: 2746000 },
  { city: 'Houston', population: 2313000 },
  { city: 'Phoenix', population: 1680000 },
];

const BarChart = () => {
  const config = {
    data,
    xField: 'city',
    yField: 'population',
    label: {
      position: 'middle',
      style: {
        fill: '#FFFFFF',
        opacity: 0.6,
      },
    },
    meta: {
      city: { alias: 'City' },
      population: { alias: 'Population' },
    },
    interactions: [{ type: 'element-active' }],
  };

  return <Column {...config} />;
};

Getting Started

To use Ant Design Charts in your React project:

  1. Install the package:
npm install @ant-design/charts
  1. Import and use the desired chart component in your React component:
import React from 'react';
import { Line } from '@ant-design/charts';

const MyChart = () => {
  const data = [
    { year: '2020', value: 3 },
    { year: '2021', value: 4 },
    { year: '2022', value: 3.5 },
  ];

  const config = {
    data,
    xField: 'year',
    yField: 'value',
  };

  return <Line {...config} />;
};

export default MyChart;

Competitor Comparisons

23,884

Redefined chart library built with React and D3

Pros of Recharts

  • More lightweight and focused solely on chart components
  • Highly customizable with a declarative API
  • Extensive documentation and examples

Cons of Recharts

  • Less out-of-the-box theming options
  • Fewer advanced chart types compared to Ant Design Charts

Code Comparison

Recharts:

import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';

<LineChart width={600} height={300} data={data}>
  <Line type="monotone" dataKey="pv" stroke="#8884d8" />
  <CartesianGrid stroke="#ccc" />
  <XAxis dataKey="name" />
  <YAxis />
</LineChart>

Ant Design Charts:

import { Line } from '@ant-design/charts';

<Line
  data={data}
  xField="name"
  yField="pv"
  point={{ size: 5, shape: 'diamond' }}
  label={{ style: { fill: '#aaa' } }}
/>

Both libraries offer React-based chart components, but Recharts provides more granular control over individual chart elements, while Ant Design Charts offers a more concise API with built-in styling options.

64,568

Simple HTML5 Charts using the <canvas> tag

Pros of Chart.js

  • Lightweight and fast, with a small file size
  • Extensive documentation and large community support
  • Highly customizable with a wide range of chart types

Cons of Chart.js

  • Less integrated with React ecosystem compared to Ant Design Charts
  • Requires more manual configuration for complex visualizations
  • Limited built-in theming options

Code Comparison

Chart.js:

import Chart from 'chart.js/auto';

new Chart(ctx, {
    type: 'bar',
    data: chartData,
    options: chartOptions
});

Ant Design Charts:

import { Bar } from '@ant-design/charts';

<Bar
    data={chartData}
    xField='x'
    yField='y'
    {...chartConfig}
/>

Chart.js offers a more traditional JavaScript approach, while Ant Design Charts provides a React-specific implementation with declarative props. Chart.js requires manual DOM manipulation and configuration, whereas Ant Design Charts integrates seamlessly with React components.

Chart.js is a versatile, lightweight library suitable for various projects, while Ant Design Charts excels in React-based applications, offering easier integration with the Ant Design ecosystem and simplified configuration for complex visualizations.

108,427

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

Pros of d3

  • Highly flexible and customizable, allowing for complex and unique visualizations
  • Extensive community support and a wide range of examples and resources
  • Direct manipulation of the DOM for fine-grained control over chart elements

Cons of d3

  • Steeper learning curve, requiring more time and effort to create basic charts
  • More verbose code, often requiring more lines to achieve simple visualizations
  • Less out-of-the-box functionality for common chart types

Code Comparison

d3:

const svg = d3.select("body").append("svg")
    .attr("width", 400)
    .attr("height", 300);

svg.selectAll("rect")
    .data(data)
    .enter()
    .append("rect")
    .attr("x", (d, i) => i * 70)
    .attr("y", (d, i) => 300 - 10 * d)
    .attr("width", 65)
    .attr("height", (d, i) => d * 10);

ant-design-charts:

import { Bar } from '@ant-design/charts';

const config = {
  data,
  xField: 'x',
  yField: 'y',
};

return <Bar {...config} />;

The code comparison demonstrates that d3 requires more manual setup and configuration, while ant-design-charts provides a more declarative and concise approach to creating charts.

60,384

Apache ECharts is a powerful, interactive charting and data visualization library for browser

Pros of ECharts

  • More comprehensive and feature-rich, offering a wider range of chart types and customization options
  • Better performance for large datasets and complex visualizations
  • Stronger community support and more frequent updates

Cons of ECharts

  • Steeper learning curve due to its extensive API and configuration options
  • Larger file size, which may impact load times for web applications

Code Comparison

Ant Design Charts:

import { Line } from '@ant-design/charts';

const Page: React.FC = () => {
  const data = [
    { year: '1991', value: 3 },
    { year: '1992', value: 4 },
    { year: '1993', value: 3.5 },
  ];
  return <Line data={data} xField="year" yField="value" />;
};

ECharts:

import * as echarts from 'echarts';

const chart = echarts.init(document.getElementById('main'));
const option = {
  xAxis: { type: 'category', data: ['1991', '1992', '1993'] },
  yAxis: { type: 'value' },
  series: [{ data: [3, 4, 3.5], type: 'line' }]
};
chart.setOption(option);

Both libraries offer declarative ways to create charts, but ECharts requires more manual setup and configuration. Ant Design Charts provides a more React-friendly approach with simpler props, while ECharts offers greater flexibility and control over chart elements.

📊 Interactive JavaScript Charts built on SVG

Pros of ApexCharts

  • More extensive customization options and chart types
  • Better performance with large datasets
  • Supports server-side rendering

Cons of ApexCharts

  • Steeper learning curve due to more complex API
  • Larger bundle size compared to Ant Design Charts

Code Comparison

ApexCharts:

import ApexCharts from 'apexcharts'

const options = {
  chart: { type: 'bar' },
  series: [{ data: [30, 40, 45, 50, 49, 60, 70, 91, 125] }]
}

const chart = new ApexCharts(document.querySelector("#chart"), options)
chart.render()

Ant Design Charts:

import { Bar } from '@ant-design/charts';

const data = [
  { year: '1991', value: 3 },
  { year: '1992', value: 4 },
  { year: '1993', value: 3.5 },
];

const config = {
  data,
  xField: 'year',
  yField: 'value',
};

<Bar {...config} />

ApexCharts offers more flexibility and control over chart creation, but requires more setup code. Ant Design Charts provides a simpler, more declarative API, making it easier to create basic charts quickly. The choice between the two depends on the specific project requirements, desired customization level, and developer preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

@ant-design/charts

A React chart library, based on G2, G6, X6, L7.

npm npm GitHub stars npm License

Website • Quick Start • Examples • FAQ •

Case

Statistical charts

✨ Features

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

📦 Installation

$ npm install @ant-design/charts

🔨 Usage

import React from 'react';
import { Line } from '@ant-design/charts';

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

  const props = {
    data,
    xField: 'year',
    yField: 'value',
  };

  return <Line {...props} />
};
export default Page;

Preview

Development

Clone locally:

$ git clone git@github.com:ant-design/ant-design-charts.git
$ cd ant-design-charts
$ pnpm install
$ pnpm build:lib & pnpm start

🤝 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

NPM DownloadsLast 30 Days