searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

Ant Design Charts的区间曲线面积图的使用

2024-11-18 09:21:48
1
0

1. 先上全部

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

interface Props {
  data: any[];
}

const RangeAreaChart: React.FC<Props> = (props) => {
  const { data } = props;

  const config = {
    data,
    xField: (d) => new Date(d.timestamp * 1000),
    yField: ['low', 'high'], // 指定多个Y轴字段
    style: {
      fillOpacity: 0.3,
      fill: '#64b5f6',
    },
    line: {
      yField: 'value',
      style: {
        stroke: '#FF6B3B',
      },
    },
  };

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

export default RangeAreaChart;

 

2. data的格式:data为数组

const data = [
    { timestamp: 1704067200, value: 3, low: 1, high: 5 },
    { timestamp: 1706745600, value: 4, low: 2, high: 6 },
    { timestamp: 1709164800, value: 3.5, low: 1.5, high: 5.5 },
    { timestamp: 1711843200, value: 5, low: 3, high: 7 },
    { timestamp: 1714435200, value: 4.9, low: 2.9, high: 6.9 },
    { timestamp: 1717113600, value: 6, low: 4, high: 8 },
    { timestamp: 1719705600, value: 7, low: 5, high: 9 },
    { timestamp: 1722384000, value: 9, low: 7, high: 11 },
    { timestamp: 1725062400, value: 13, low: 11, high: 15 },
    { timestamp: 1727654400, value: 15, low: 13, high: 17 },
    { timestamp: 1730332800, value: 17, low: 15, high: 19 },
    { timestamp: 1733011200, value: 19, low: 17, high: 21 },
  ];

 

3. line用于添加额外的折线图。可以用此方法在区间曲线面积图上叠加更多的图表

    line: {
      yField: 'value',
      style: {
        stroke: '#FF6B3B',
      },
0条评论
作者已关闭评论
叶奇微
4文章数
0粉丝数
叶奇微
4 文章 | 0 粉丝
原创

Ant Design Charts的区间曲线面积图的使用

2024-11-18 09:21:48
1
0

1. 先上全部

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

interface Props {
  data: any[];
}

const RangeAreaChart: React.FC<Props> = (props) => {
  const { data } = props;

  const config = {
    data,
    xField: (d) => new Date(d.timestamp * 1000),
    yField: ['low', 'high'], // 指定多个Y轴字段
    style: {
      fillOpacity: 0.3,
      fill: '#64b5f6',
    },
    line: {
      yField: 'value',
      style: {
        stroke: '#FF6B3B',
      },
    },
  };

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

export default RangeAreaChart;

 

2. data的格式:data为数组

const data = [
    { timestamp: 1704067200, value: 3, low: 1, high: 5 },
    { timestamp: 1706745600, value: 4, low: 2, high: 6 },
    { timestamp: 1709164800, value: 3.5, low: 1.5, high: 5.5 },
    { timestamp: 1711843200, value: 5, low: 3, high: 7 },
    { timestamp: 1714435200, value: 4.9, low: 2.9, high: 6.9 },
    { timestamp: 1717113600, value: 6, low: 4, high: 8 },
    { timestamp: 1719705600, value: 7, low: 5, high: 9 },
    { timestamp: 1722384000, value: 9, low: 7, high: 11 },
    { timestamp: 1725062400, value: 13, low: 11, high: 15 },
    { timestamp: 1727654400, value: 15, low: 13, high: 17 },
    { timestamp: 1730332800, value: 17, low: 15, high: 19 },
    { timestamp: 1733011200, value: 19, low: 17, high: 21 },
  ];

 

3. line用于添加额外的折线图。可以用此方法在区间曲线面积图上叠加更多的图表

    line: {
      yField: 'value',
      style: {
        stroke: '#FF6B3B',
      },
文章来自个人专栏
个人的前端开发
2 文章 | 1 订阅
0条评论
作者已关闭评论
作者已关闭评论
0
0