import { useMemo } from 'react'
import ReactEcharts from 'echarts-for-react';
const LineCharts = ({ data }: { data: any[] }) => {

  const option = useMemo(() => {
    const chartData: any = data?.map(item => item.value)
    const showXAis = true
    return {
      xAxis: {
        type: 'category',
        boundaryGap: false,
        show: showXAis,
        data: showXAis ? data?.map(item => item.name) : [],
        axisLabel: {
          color: '#CBEDFF',
          interval: 3 // 设置为0以显示所有坐标点  
        },
        axisLine: {
          show: false,
        },
      },
      yAxis: {
        type: 'value',
        show: false,
      },
      grid: {
        left: '5%',  // 左边距
        right: '5%', // 右边距
        top: '10%',   // 上边距
        bottom: '30%' // 下边距
      },
      series: [
        {
          data: chartData,
          symbol: "none",
          type: 'line',
          lineStyle: {
            color: "#57EFE5",
          },

          areaStyle: {
            // 区域填充样式。设置后显示成区域面积图。
            color: {
              type: 'linear',
              x: 0,
              y: 1,
              x2: 0,
              y2: 0.2,
              colorStops: [
                {
                  offset: 0,
                  color: 'rgba(87, 239, 229, 0)', // 0% 处的颜色
                },

                {
                  offset: 1,
                  color: 'rgba(87, 239, 229, 0.36)', // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
        },
      ],
    }
  }, [data])

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

export default LineCharts