import ReactEcharts from 'echarts-for-react';
import { CSSProperties, useMemo } from 'react';
const LineCharts = ({
  style = {},
  data,
}: {
  style?: CSSProperties;
  data: any[];
}) => {
  const option = useMemo(() => {
    const showXAis = false;
    return {
      tooltip: {
        trigger: 'axis',
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        show: showXAis,
        data: data?.map((item: any) => item.name) || [],
      },
      yAxis: {
        type: 'value',
        show: false,
      },
      grid: {
        left: '5%', // 左边距
        right: '0', // 右边距
        top: '10%', // 上边距
        bottom: '10%', // 下边距
      },
      series: [
        {
          data: data,
          symbol: 'none',
          type: 'line',
          lineStyle: {
            color: '#57EF58',
          },

          areaStyle: {
            // 区域填充样式。设置后显示成区域面积图。
            color: {
              type: 'linear',
              x: 0,
              y: 1,
              x2: 0,
              y2: 0.2,
              colorStops: [
                {
                  offset: 0,
                  color: 'rgba(87, 239, 88, 0)', // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: 'rgba(87, 239, 88, 0.36)', // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
        },
      ],
    };
  }, [data]);

  return (
    <ReactEcharts
      option={option} // option：图表配置项
      style={{ width: '195px', height: '26px', ...style }}
    />
  );
};

export default LineCharts;
