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

  const option = useMemo(() => {
    const chartData: any = [60, 50, 60, 70, 50, 70, 50, 60, 70, 50, 80, 50, 60, 70, 50, 60, 50, 60, 70, 50]
    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: '0',  // 左边距
        right: '0', // 右边距
        top: '0',   // 上边距
        bottom: '0' // 下边距
      },
      series: [
        {
          data: chartData,
          symbol: "none",
          type: 'line',
          lineStyle: {
            color: "#57EF58",
            width: 3
          },
          smooth: true,
          areaStyle: {
            // 区域填充样式。设置后显示成区域面积图。
            color: {
              type: 'linear',
              x: 0,
              y: 1,
              x2: 0,
              y2: 0.2,
              colorStops: [
                {
                  offset: 0,
                  color: 'rgba(143, 255, 143, 0.05)', // 0% 处的颜色
                },

                {
                  offset: 1,
                  color: 'rgba(134, 255, 135, 0.4)', // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
        },
      ],
    }
  }, [data])

  return (
    <ReactEcharts
      option={option} // option：图表配置项
      style={style}
    />
  )
}

export default LineCharts