【山竹记账前端-react】24.数据可视化


大纲链接 §

[toc]


1. 统计页面 ⇧

@/route/routes.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// import...
import { StatisticsPage } from '@/pages/StatisticsPage'
import type { RouteObject } from 'react-router-dom'

export const routes: RouteObject[] = [
  { path: '/', element: <Root /> },
  // ...
  { path: '/statistics', element: <StatisticsPage /> },
  { path: '/export', element: <div>敬请期待</div> },
  { path: '/notify', element: <div>敬请期待</div> },
  { path: '/tech_stack', element: <div>敬请期待</div> },
]

@/pages/StatisticsPage.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { DateRangePicker, type DateTabRangeStr } from '@/components/DateRangePicker'
import { GradientBanner } from '@/components/GradientBanner'
import { SvgIcon } from '@/components/SvgIcon'
import { TopNav } from '@/components/TopNav'
import { ChartsSummary } from '@/modules/statistics/ChartsSummary'
import { cn } from 'cn'
import { useState } from 'react'

interface Props {
  className?: string
}

export const StatisticsPage: React.FC<Props> = ({ className }) => {
  const Icon = <SvgIcon name="back-arrow" className="size-[24px]" />
  const [selectedDate, setSelectedDate] = useState<DateTabRangeStr>('thisMonth')
  return (
    <div className={cn('container w-screen h-screen relative', className)}>
      <GradientBanner>
        <TopNav icon={Icon} title="统计图表" />
      </GradientBanner>

      <DateRangePicker selectedId={selectedDate} onSelect={setSelectedDate} />
      <main className="h-[calc(var(--main-vh,100vh)-112px)] border-3 b-solid b-red ">
        <ChartsSummary startDate={selectedDate} endDate={selectedDate} />
      </main>
    </div>
  )
}

@/modules/statistics/ChartsSummary.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
interface Props {
  className?: string
  startDate: string
  endDate: string
}

export const ChartsSummary: React.FC<Props> = ({ className, startDate, endDate }) => {
  console.log('ChartsSummary_______________________')
  console.log('%c⧭', 'color: #807160', endDate)
  console.log('%c⧭', 'color: #731d1d', startDate)
  console.log('_______________________ChartsSummary')
  return (
    <div className={className}>
      ChartsSummary
      {/* 类型选择器 */}
      {/* 柱状图 */}
      {/* 饼图 */}
      {/* 排名条 */}
    </div>
  )
}

安装 echarts

1
pnpm install echats@6.1.0

2. 封装折线图 ⇧

基本完成折线图结构样式 ⇧

添加简单的数据 @/modules/statistics/ChartsSummary.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { AmountProgress } from '@/modules/statistics/AmountProgress'
// import { AmountProportionChart } from '@/modules/statistics/AmountProportionChart'
// import { DateAmountChart } from '@/modules/statistics/DateAmountChart'
import { cn } from 'cn'

interface Props {
  className?: string
  startDate: string
  endDate: string
}

export const ChartsSummary: React.FC<Props> = ({ className, startDate, endDate }) => {
  console.log('ChartsSummary_______________________')
  console.log('%c⧭', 'color: #807160', endDate)
  console.log('%c⧭', 'color: #731d1d', startDate)
  console.log('_______________________ChartsSummary')

  const items = [
    { date: '2026-12-01', amount: 1200 },
    { date: '2026-12-02', amount: 2300 },
    { date: '2026-12-03', amount: 2300 },
    { date: '2026-12-04', amount: 2300 },
    { date: '2026-12-05', amount: 2300 },
    { date: '2026-12-06', amount: 2300 },
    { date: '2026-12-30', amount: 1800 },
  ].map((item) =>
    ({ x: item.date, y: item.amount / 100 }))
  return (
    <div className={className}>
      {/* 类型选择器 */}
      {/* 折线图 */}
      <DateAmountChart chartData={items} className={cn('h-150px')} />

      {/* 饼图 */}
      {/*<AmountProportionChart />*/}

      {/* 排名条 */}
      {/*<AmountProgress />*/}
    </div>
  )
}

@/modules/statistics/DateAmountChart.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { cn } from 'cn'
import * as echarts from 'echarts'
import { useEffect, useId, useRef } from 'react'
import type { EChartsOption } from 'echarts'

interface Props {
  className?: string
  chartData?: { x: number | string; y: number }[]
}

export const DateAmountChart: React.FC<Props> = ({ className, chartData }) => {
  const chartDomRef = useRef<HTMLDivElement>(null)
  const xItems = chartData?.map((item) => item.x)
  const yItems = chartData?.map((item) => item.y)

  useEffect(() => {
    if (!chartDomRef) {
      return
    }
    // 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    let chartInstance = echarts.getInstanceByDom(chartDomRef.current)
    // 2. 如果没有,则进行初始化
    if (!chartInstance) {
      chartInstance = echarts.init(chartDomRef.current)
    }

    const option: EChartsOption = {
      grid: { left: '5%', right: '5%', top: '20%', bottom: '20%' },
      xAxis: {
        type: 'category',
        data: xItems,
        axisLabel: {
          formatter: (label: string /* index: number */) => {
            const sliceSignIndex = label.indexOf('-')
            return label.slice(sliceSignIndex + 1)
          },
        },
      },
      yAxis: {
        type: 'value',
        axisLabel: {
          show: false,
        },
      },
      series: [
        {
          name: '销量',
          type: 'line',
          data: yItems,
          emphasis: {
            focus: 'series',
            scale: 2,
            blurScope: 'series',
            itemStyle: {
              borderWidth: 3,
            },
          },
        },
      ],
    }
    // 3. 渲染你的图表数据
    chartInstance.setOption(option)
    // 4. 组件卸载或重新执行 effect 前销毁实例
    return () => {
      chartInstance?.dispose()
    }
  }, [])

  return <div ref={chartDomRef} className={cn(className)} />
}
  • 外部数据参数 chartData?: { x: number | string; y: number }[]
    • x 轴数据 const xItems = chartData?.map((item) => item.x)
    • y 轴数据 const yItems = chartData?.map((item) => item.y)
  • 声明图表节点 const chartDomRef = useRef<HTMLDivElement>(null)
  • 检查该 DOM 是否已经初始化过 ECharts 实例 echarts.getInstanceByDom(chartDomRef.current)
  • 初始化 chartInstance = echarts.init(chartDomRef.current)
  • 渲染 chartInstance.setOption(option)
  • 组件卸载或重新执行 effect 前销毁实例 return chartInstance?.dispose

自定义 tooltip ⇧

@/modules/statistics/DateAmountChart.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// import...

interface Props {/* ... */}

export const DateAmountChart: React.FC<Props> = ({ className, chartData }) => {
  const chartDomRef = useRef<HTMLDivElement>(null)
  const xItems = chartData?.map((item) => item.x)
  const yItems = chartData?.map((item) => item.y)

  useEffect(() => {
    if (!chartDomRef) {
      return
    }
    // 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    let chartInstance = echarts.getInstanceByDom(chartDomRef.current)
    // 2. 如果没有,则进行初始化
    if (!chartInstance) {
      chartInstance = echarts.init(chartDomRef.current)
    }

    const option: EChartsOption = {
      /* ... */
      tooltip: {
        show: true,
        trigger: 'axis',
        formatter: (params: TooltipComponentFormatterCallbackParams) => {
          const { seriesName, marker, axisValue, data, } = params?.[0] ?? {}
          const partsDate = axisValue.split('-')
          const label = `${partsDate[0]}年${partsDate[1]}月${partsDate[2]}日`
          const dataValue = data === null ? '无数据' : `¥ ${data}元`
          return `
            <div>
              ${marker} ${seriesName}
            </div>
            <div>
              <span>${label}</span>
              <span>${dataValue}</span>
            </div>
          `
        },
      },
    }
    // 3. 渲染你的图表数据
    chartInstance.setOption(option)
    // 4. 组件卸载或重新执行 effect 前销毁实例
    return () => {
      chartInstance?.dispose()
    }
  }, [])

  return <div ref={chartDomRef} className={cn(className)} />
}
  • TODO: 使用 React.JSX 实现安全的自定义 tooltip
  • 区别于整体 option 中的 tooltip 和 series 项目中的 tooltip 解构的数据名称也不同
    • 整体 option 中的 tooltip 解构 const { seriesName, marker, axisValue, data, } = params?.[0] ?? {}

默认显示第一项数据的 tooltip ⇧

@/modules/statistics/DateAmountChart.tsx

  • 配置 series 项目中的 tooltip

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    
    // import...
    import type { EChartsOption, TooltipComponentFormatterCallbackParams } from 'echarts'
    
    interface Props {/* ... */}
    
    export const DateAmountChart: React.FC<Props> = ({ className, chartData }) => {
    const chartId = useId()
    const chartDomRef = useRef<HTMLDivElement>(null)
    const xItems = chartData?.map((item) => item.x)
    const yItems = chartData?.map((item) => item.y)
    
    useEffect(() => {
    if (!chartDomRef.current) {
      return
    }
    
    // 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    let chartInstance = echarts.getInstanceByDom(chartDomRef.current)
    // 2. 如果没有,则进行初始化
    if (!chartInstance) {
      chartInstance = echarts.init(chartDomRef.current)
    }
    
    const option: EChartsOption = {
      /* ... */
      tooltip: {
        show: true,
        // 如果针对 series 单独设置,通常用 'item'
        trigger: 'item',
        confine: true,
      },
      series: [
        {
          name: '销量',
          type: 'line',
          data: yItems,
          emphasis: {
            focus: 'series',
            scale: 2,
            blurScope: 'series',
            itemStyle: {
              borderWidth: 3,
            },
          },
          tooltip: {
            show: true,
            confine: true,
            trigger: 'item',
            formatter: (params: TooltipComponentFormatterCallbackParams) => {
              const { seriesName, marker, name, data} = params
              const partsDate = name.split('-')
              const label = `${partsDate[0]}年${partsDate[1]}月${partsDate[2]}日`
              const dataValue = data === null ? '无数据' : `¥ ${data}元`
              return `
                <div>
                  <div>
                    ${marker} ${seriesName}
                  </div>
                  <div>
                    <span>${label}</span>
                    <span>${dataValue}</span>
                  </div>
                </div>
              `
            },
          },
        },
      ],
    }
    // 如果组件已经卸载,则不执行下一步渲染,防止严格模式(Strict Mode) 触发组件双重渲染
    if (!chartInstance || chartInstance.isDisposed()) {
      return
    }
    // 3. 渲染你的图表数据
    chartInstance.setOption(option)
    
    // 记录定时器 ID,并在回调中再次检查实例状态
    const timer = setTimeout(() => {
      if (chartInstance.isDisposed() || xItems?.length === 0) {
        return
      }
      chartInstance?.dispatchAction({
        type: 'showTip',
        // 轴触发类型(trigger: 'axis')时使用:
        seriesIndex: 0, // 第几个 series(通常为 0)
        dataIndex: 0, // 显示第一项(索引从 0 开始)
      })
    }, 300)
    
    // 4. 组件卸载或重新执行 effect 前销毁实例
    return () => {
      clearTimeout(timer)
      chartInstance?.dispose()
    }
    }, [])
    
    return <div ref={chartDomRef} id={chartId} className={cn(className)} />
    }
    
  • series 项目中的 tooltip 解构 const { seriesName, marker, name, data} = params

  • 在全局 tooltip 中添加 confine: true,强制将 tooltip 框限制在图表容器(chartDom)的内部,防止溢出边界

  • 默认 tooltip 显示第一项(索引从 0 开始)

    • 使用 dispatchAction({type: 'showTip', ...}) 触发
    • TODO: 优化 dispatchAction 触发时机与位置
  • TODO: 使用 React.JSX 实现安全的自定义 tooltip

  • TODO: 将 初始化/销毁 与 数据更新 拆分为两个独立的 useEffect https://share.google/aimode/JMk45ObDFdiHgImAO

  • TODO: 循环显示每一项 tooltip,类似轮播效果 https://share.google/aimode/HLsTcUdIskpYI1oXH

参考


3. 封装折线图2:优化 ⇧

将 初始化/销毁 与 数据更新 拆分为两个独立的 useEffect ⇧

@/modules/statistics/DateAmountChart.tsx

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// import...

interface Props {
  className?: string
  chartData?: { x: number | string; y: number }[]
}

export const DateAmountChart: React.FC<Props> = ({ className, chartData }) => {
  const chartId = useId()
  const chartDomRef = useRef<HTMLDivElement>(null)
  const chartInstance = useRef<echarts.ECharts | null>(null)

  // 1. 仅负责在挂载时初始化,卸载时销毁
  useEffect(() => {
    if (!chartDomRef.current) {
      return
    }
    // 优先获取已存在的实例,避免重复初始化
    // 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    // 2. 如果没有,则进行初始化
    chartInstance.current = echarts.getInstanceByDom(chartDomRef.current) ??
      echarts.init(chartDomRef.current)

    // 组件卸载或重新执行 effect 前销毁实例
    return () => {
      chartInstance.current?.dispose()
      chartInstance.current = null
    }
  }, [])

  // 2. 负责监听 chartData 变化重新渲染图表
  useEffect(() => {
    const xItems = chartData?.map((item) => item.x)
    const yItems = chartData?.map((item) => item.y)
    // 如果组件已经卸载,则不执行下一步渲染,防止严格模式(Strict Mode) 触发组件双重渲染
    if (!chartInstance.current || chartInstance.current?.isDisposed()) {
      return
    }

    const option: EChartsOption = {
      grid: { left: 0, right: 0, top: '20%', bottom: '20%' },
      tooltip: {
        show: true,
        confine: true,
        // 改用 axis 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用
        trigger: 'axis',
        formatter: (params: TooltipComponentFormatterCallbackParams) => {
          if (!Array.isArray(params) || params.length === 0) {
            return ''
          }
          const { seriesName, marker, name, data } = params[0]
          const partsDate = name.split('-')
          const label = `${partsDate[0]}年${partsDate[1]}月${partsDate[2]}日`
          const dataValue = data === null ? '无数据' : `¥ ${data}元`
          return `
                <div>
                  <div>
                    ${marker} ${seriesName}
                  </div>
                  <div>
                    <span>${label}</span>
                    <span>${dataValue}</span>
                  </div>
                </div>
              `
        },
      },
      xAxis: {
        type: 'category',
        data: xItems,
        axisLabel: {
          formatter: (label: string /* index: number */) => {
            const sliceSignIndex = label.indexOf('-')
            return label.slice(sliceSignIndex + 1)
          },
        },
      },
      yAxis: {
        type: 'value',
        axisLabel: {
          show: false,
        },
      },
      series: [
        {
          name: '销量',
          type: 'line',
          data: yItems,
          emphasis: {
            focus: 'series',
            scale: 2,
            blurScope: 'series',
            itemStyle: {
              borderWidth: 3,
            },
          },
        },
      ],
    }

    // 3. 渲染图表数据
    chartInstance.current.setOption(option)

    // 记录定时器 ID,并在回调中再次检查实例状态
    const timer = setTimeout(() => {
      if (chartInstance.current?.isDisposed() || xItems?.length === 0) {
        return
      }
      chartInstance.current?.dispatchAction({
        type: 'showTip',
        // 轴触发类型(trigger: 'axis')时使用:
        seriesIndex: 0, // 第几个 series(通常为 0)
        dataIndex: 0, // 显示第一项(索引从 0 开始)
      })
    }, 800)

    return () => clearTimeout(timer)
  }, [chartData])

  return <div ref={chartDomRef} id={chartId} className={cn(className)} />
}
  • 第一个 useEffect 负责在挂载时初始化,卸载时销毁
    • 避免重复初始化
    • 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    • 2. 如果没有,则进行初始化
    • 组件卸载或重新执行 effect 前销毁实例
  • 第二个 useEffect 负责监听 chartData 变化重新渲染图表
    • 如果组件已经卸载,则不执行下一步渲染,防止严格模式(Strict Mode) 触发组件双重渲染
    • 构造 option
    • 注意 tooltip选项,顶层的 option.tooltip 才支持 trigger: 'axis' 和对应的 formatter
    • 当顶层设置为 axis 时,ECharts 会完全忽略 series 内部的 tooltip 配置
    • 渲染图表数据

添加 resize 监听窗口尺寸变化,重新渲染图表 ⇧

@/modules/statistics/DateAmountChart.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// import...

interface Props {
  className?: string
  chartData?: { x: number | string; y: number }[]
}

export const DateAmountChart: React.FC<Props> = ({ className, chartData }) => {
  const chartId = useId()
  const chartDomRef = useRef<HTMLDivElement>(null)
  const chartInstance = useRef<echarts.ECharts | null>(null)

  // 1. 仅负责在挂载时初始化,卸载时销毁
  useEffect(() => {
    if (!chartDomRef.current) {
      return
    }
    // 优先获取已存在的实例,避免重复初始化
    // 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    // 2. 如果没有,则进行初始化
    chartInstance.current = echarts.getInstanceByDom(chartDomRef.current) ??
      echarts.init(chartDomRef.current)

    const handleResize = () => {
      if (!chartInstance.current || !chartInstance.current?.isDisposed()) {
        chartInstance.current?.resize?.()
      }
    }
    window.addEventListener('resize', handleResize)

    // 组件卸载或重新执行 effect 前销毁实例
    return () => {
      window.removeEventListener('resize', handleResize)
      chartInstance.current?.dispose()
      chartInstance.current = null
    }
  }, [])

  // 2. 负责监听 chartData 变化重新渲染图表
  useEffect(() => {
    const xItems = chartData?.map((item) => item.x)
    const yItems = chartData?.map((item) => item.y)
    // 如果组件已经卸载,则不执行下一步渲染,防止严格模式(Strict Mode) 触发组件双重渲染
    if (!chartInstance.current || chartInstance.current?.isDisposed()) {
      return
    }

    const option: EChartsOption = {/* ... */}

    // 3. 渲染图表数据
    chartInstance.current.setOption(option)

    // 记录定时器 ID,并在回调中再次检查实例状态
    const timer = setTimeout(() => {
      if (chartInstance.current?.isDisposed() || xItems?.length === 0) {
        return
      }
      chartInstance.current?.dispatchAction({
        type: 'showTip',
        // 轴触发类型(trigger: 'axis')时使用:
        seriesIndex: 0, // 第几个 series(通常为 0)
        dataIndex: 0, // 显示第一项(索引从 0 开始)
      })
    }, 800)

    return () => clearTimeout(timer)
  }, [chartData])

  return <div ref={chartDomRef} id={chartId} className={cn(className)} />
}

轮播显示每一项 tooltip ⇧

封装 @/hooks/useChartCarousel.ts 轮播图表数据

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { useEffect, useRef } from 'react'
import type { ECharts } from 'echarts'

interface UseChartCarouselOptions {
  /** ECharts 实例的 Ref */
  chartInstance: React.MutableRefObject<ECharts | null>
  /** 图表容器 DOM 的 Ref(用于绑定移动端触摸事件) */
  chartDomRef: React.RefObject<HTMLDivElement | null>
  /** 数据总长度(数据更新或为 0 时自动重置轮播) */
  dataLength: number
  /** 轮播间隔时间(毫秒),默认 2000ms */
  interval?: number
  /** 初始化延迟触发时间(毫秒),默认 800ms(等待图表动画完成) */
  initDelay?: number
  /** 目标系列索引,默认 0 */
  seriesIndex?: number
  /** 是否开启自动轮播,默认 true */
  enabled?: boolean
}

export function useChartTooltipCarousel({
  chartInstance,
  chartDomRef,
  dataLength = 0,
  interval = 2000,
  initDelay = 800,
  seriesIndex = 0,
  enabled = true,
}: UseChartCarouselOptions) {
  const timerRef = useRef<ReturnType<typeof setInterval> | null>(null)
  const touchEndTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
  const currentCarouselIndexRef = useRef<number>(0)

  useEffect(() => {
    const chart = chartInstance.current
    const dom = chartDomRef.current

    // 防御性检查:实例未挂载、已销毁、未启用或无数据时不启动
    if (!enabled || !chart || chart.isDisposed() || !dom || dataLength <= 0) {
      return
    }

    // 1. 触发指定索引的 Tooltip 与高亮状态
    const showTipAt = (index: number) => {
      if (chart.isDisposed()) return
      chart.dispatchAction({
        type: 'showTip',
        seriesIndex,
        dataIndex: index,
      })
      chart.dispatchAction({ type: 'downplay', seriesIndex })
      chart.dispatchAction({
        type: 'highlight',
        seriesIndex,
        dataIndex: index,
      })
    }

    // 2. 启动与停止定时器
    const stopCarousel = () => {
      if (timerRef.current) {
        clearInterval(timerRef.current)
        timerRef.current = null
      }
      if (touchEndTimerRef.current) {
        clearTimeout(touchEndTimerRef.current)
        touchEndTimerRef.current = null
      }
    }

    const startCarousel = () => {
      stopCarousel()
      // 只有 1 条数据时展示第一项即可,无需开启循环定时器
      if (dataLength <= 1) return

      timerRef.current = setInterval(() => {
        // 轮播逻辑精髓 取余 实现循环
        currentCarouselIndexRef.current = (currentCarouselIndexRef.current + 1) % dataLength
        showTipAt(currentCarouselIndexRef.current)
      }, interval)
    }

    // 3. PC 端鼠标交互
    const handleMouseOver = (params: { dataIndex?: number }) => {
      stopCarousel()
      if (typeof params.dataIndex === 'number') {
        currentCarouselIndexRef.current = params.dataIndex
      }
    }
    const handleGlobalOut = () => {
      startCarousel()
    }

    chart.on('mouseover', handleMouseOver)
    chart.on('globalout', handleGlobalOut)

    // 4. 移动端触摸交互
    const handleTouchStart = () => {
      stopCarousel()
    }
    const handleTouchEnd = () => {
      // 延迟 500ms 恢复,避免手指离开瞬间的点击事件与轮播冲突
      touchEndTimerRef.current = setTimeout(() => {
        startCarousel()
      }, 500)
    }

    dom.addEventListener('touchstart', handleTouchStart, { passive: true })
    dom.addEventListener('touchend', handleTouchEnd)

    // 5. 页面切后台/锁屏时自动暂停,节省移动端性能
    const handleVisibilityChange = () => {
        document.hidden ? stopCarousel() : startCarousel();
    }
    document.addEventListener('visibilitychange', handleVisibilityChange)

    // 6. 首次延迟展示第一项并启动轮播
    const initTimer = setTimeout(() => {
      if (chart.isDisposed()) return
      currentCarouselIndexRef.current = 0
      showTipAt(0)
      startCarousel()
    }, initDelay)

    // 7. 清理所有副作用
    return () => {
      clearTimeout(initTimer)
      stopCarousel()
      document.removeEventListener('visibilitychange', handleVisibilityChange)
      dom.removeEventListener('touchstart', handleTouchStart)
      dom.removeEventListener('touchend', handleTouchEnd)
      if (!chart.isDisposed()) {
        chart.off('mouseover', handleMouseOver)
        chart.off('globalout', handleGlobalOut)
      }
    }
  }, [chartInstance, chartDomRef, dataLength, interval, initDelay, seriesIndex, enabled])
}

使用 @/modules/statistics/DateAmountChart.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// import...
import { useChartTooltipCarousel } from '@/hooks/useChartCarousel';

interface Props {
  className?: string
  chartData?: { x: number | string; y: number }[]
}

export const DateAmountChart: React.FC<Props> = ({ className, chartData }) => {
  const chartId = useId()
  const chartDomRef = useRef<HTMLDivElement>(null)
  const chartInstance = useRef<echarts.ECharts | null>(null)

  // 1. 仅负责在挂载时初始化,卸载时销毁
  useEffect(() => {/* ... */}, [])

  // 2. 负责监听 chartData 变化重新渲染图表
  useEffect(() => {
    const xItems = chartData?.map((item) => item.x)
    const yItems = chartData?.map((item) => item.y)
    // 如果组件已经卸载,则不执行下一步渲染,防止严格模式(Strict Mode) 触发组件双重渲染
    if (!chartInstance.current || chartInstance.current?.isDisposed()) {
      return
    }

    const option: EChartsOption = {/* ... */}

    // 3. 渲染图表数据
    chartInstance.current.setOption(option)

  }, [chartData])

  // 轮播 tooltip
  useChartTooltipCarousel({
    chartInstance,
    chartDomRef,
    dataLength: chartData?.length ?? 0,
    initDelay: 800,
    interval: 1800,
  })

  return <div ref={chartDomRef} id={chartId} className={cn(className)} />
}

参考


4. 封装饼图 ⇧

封装 useChartLifeCycle ⇧

  • 图表生命周期逻辑服用可封装为钩子函数

@/hooks/useChartLifeCycle.ts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as echarts from 'echarts'
import { useEffect, useId, useRef } from 'react'

export const useChartLifeCycle = () => {
  const chartId = useId()
  const chartDomRef = useRef<HTMLDivElement>(null)
  const chartInstanceRef = useRef<echarts.ECharts | null>(null)

  // 1. 仅负责在挂载时初始化,卸载时销毁
  useEffect(() => {
    if (!chartDomRef.current) {
      return
    }
    // 优先获取已存在的实例,避免重复初始化
    // 1. 检查该 DOM 是否已经初始化过 ECharts 实例
    // 2. 如果没有,则进行初始化
    chartInstanceRef.current =
      echarts.getInstanceByDom(chartDomRef.current) ?? echarts.init(chartDomRef.current)

    const handleResize = () => {
      if (chartInstanceRef.current && !chartInstanceRef.current?.isDisposed()) {
        chartInstanceRef.current?.resize?.()
      }
    }
    window.addEventListener('resize', handleResize)
    // 组件卸载或重新执行 effect 前销毁实例
    return () => {
      window.removeEventListener('resize', handleResize)
      chartInstanceRef.current?.dispose()
      chartInstanceRef.current = null
    }
  }, [])

  return {
    chartId,
    chartDomRef,
    chartInstanceRef,
  }
}

快速实现饼图 ⇧

提供模拟外部传参数据

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
export interface pieChartsItem {
  name: string
  value: number
}

const pieChartItems: pieChartsItem[] = [
    { amount: 10480, name: 'Search Engine' },
    { amount: 7350, name: 'Direct' },
    { amount: 5800, name: 'Email' },
    { amount: 4840, name: 'Union Ads' },
    { amount: 3000, name: 'Video Ads' },
  ].map((item) => ({ name: item.name, value: item.amount / 100 }))

return (
  {/* ... */}
  <AmountProportionChart chartData={pieChartItems} className={cn('h-240px px-.5em')} />
)

@/modules/statistics/AmountProportionChart.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { useChartTooltipCarousel } from '@/hooks/useChartCarousel'
import { useChartLifeCycle } from '@/hooks/useChartLifeCycle'
import type { EChartsOption } from 'echarts'
import type { OptionDataValue } from 'echarts/types/src/util/types.js'
import { useEffect } from 'react'

interface Props {
  className?: string
  chartData?: { name: string; value: number }[]
}

export const AmountProportionChart: React.FC<Props> = ({ className, chartData }) => {
  const { chartId, chartDomRef, chartInstanceRef } = useChartLifeCycle()

  useEffect(() => {
    if (!chartInstanceRef.current || chartInstanceRef.current?.isDisposed()) {
      return
    }

    const option: EChartsOption = {
      grid: { left: 0, right: 0, top: 0, bottom: 0 },
      tooltip: {
        trigger: 'item',
        valueFormatter: (value: OptionDataValue | OptionDataValue[]) => {
          return Array.isArray(value) ? '' : `¥ ${value}`
        },
      },
      series: [
        {
          type: 'pie',
          radius: '50%',
          data: chartData,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
            },
          },
        },
      ],
    }

    chartInstanceRef.current.setOption(option)
  }, [chartData, chartInstanceRef])

  // 轮播 tooltip
  useChartTooltipCarousel({
    chartInstance: chartInstanceRef,
    chartDomRef,
    dataLength: chartData?.length ?? 0,
    initDelay: 800,
    interval: 1800,
  })

  return <div ref={chartDomRef} id={chartId} className={className} />
}

5. 封装排名组件 ⇧

提供模拟外部传参数据

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
export interface RankChartItem {
  id: number
  tag: { sign: string; name: string; tag_id: number }
  amount: number
  percent: number
}

const rankChartItems: RankChartItem[] = [
  { id: 1, tag: { sign: '😄', name: '房租', tag_id: 1 }, amount: 3112, percent: 11 },
  { id: 2, tag: { sign: '💰', name: '工资', tag_id: 2 }, amount: 32112, percent: 56 },
  { id: 3, tag: { sign: '💵', name: '奖金', tag_id: 3 }, amount: 12323, percent: 33 },
]

return (
  {/* ... */}
  <TagAmountRank chartData={rankChartItems} className={cn('h-360px px-.5em')} />
)

@/modules/statistics/TagAmountRank.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { RankChartItem } from '@/modules/statistics/chartData'
import { cn } from 'cn'

interface Props {
  className?: string
  chartData: RankChartItem[]
}

export const TagAmountRank: React.FC<Props> = ({ className, chartData }) => {
  return (
    <div
      className={cn(
        'bar-progress mb-8em px-1.5em',
        '[&>.top-item]:[--sibling-idx:calc(1*sibling-index())]',
        className
      )}>
      {chartData.length === 0 ? (
        <div className="text-[var(--text-muted)]">暂无数据</div>
      ) : (
        <>
          {chartData.map(({ id, tag, amount, percent }) => (
            <div
              key={`${id}-${tag.tag_id}`}
              style={{ '--width-percent': `${percent}%` }}
              className={cn('top-item mb-1em flex items-center justify-between')}>
              {/* 图标 */}
              <div
                className={cn(
                  'sign size-3em rounded-[50%]',
                  'bg-[var(--tag-bg)] border-1 border-color-[oklch(70%_0.15_calc(var(--sibling-idx)*70))]',
                  'grow-0 shrink-0 flex items-center justify-center'
                )}>
                <span className="text-24px flip-360">{tag.sign}</span>
              </div>

              {/* 名称-占比-金额 */}
              <div className="bar-wrapper ml-1em grow-1 shrink-1">
                <div className="bar_text text-[var(--text-muted)] flex items-center justify-between">
                  <span>
                    {tag.name} - {percent}%
                  </span>
                  <span> ¥ {amount}</span>
                </div>

                {/* 进度条 */}
                <div className="bar h-.5em rounded-.25em bg-[var(--bar-bg)] relative overflow-clip mt-.25em">
                  <div
                    className={cn(
                      'bar_inner absolute top-0 left-0',
                      `w-[var(--width-percent)] h-full`,
                      `bg-[oklch(70%_0.15_calc(var(--sibling-idx)*70))]`
                    )}
                  />
                </div>
              </div>
            </div>
          ))}
        </>
      )}
    </div>
  )
}

6. 添加下拉选项 ⇧

扩展 FormItemTypeProps 类型,添加 FormItem 的类型 optionSelector ⇧

@/components/form/item/FormItemType.ts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
export type FormItemType = 'input' | 'emoji' | 'validateCodeSend' | 'optionSelector'
export type InputType = 'text' | 'password' | 'email' | 'number'
export interface SelectorOption<U = string> {
  label: string
  value: U
  disabled?: boolean
}

export type CommonFormItemTypeProps = {
  label?: string
  labelFor?: string
  ifUseLabelTag?: boolean
  hasLabelColon?: boolean
  placeholder?: string
  errorHint?: string
  hasErrorPlaceholder?: boolean
  value?: string
  onChange?: (value: string) => void
  onBlur?: () => void
  onFocus?: () => void
  maxWidth?: string
}

export type FormItemTypeProps<T extends FormItemType, U = string> = T extends 'input'
  ? CommonFormItemTypeProps & { type?: 'input'; inputType: InputType }
  : T extends 'emoji'
    ? Omit<CommonFormItemTypeProps, 'value' | 'onChange'> & {
        type?: 'emoji'
        value?: number
        onChange?: (sign_in: number, sign: string) => void
      }
    : T extends 'validateCodeSend'
      ? CommonFormItemTypeProps & { type?: 'validateCodeSend'; onClickSendCode?: () => void }
      : T extends 'optionSelector'
        ? Omit<CommonFormItemTypeProps, 'value' | 'onChange'> & {
            type?: 'optionSelector'
            ifOneLineLabel?: boolean
            value: U
            options: SelectorOption<U>[]
            onChange?: (value: U) => void
          }
        : never

// 兼容互斥类型,无泛型版
export type FormItemTypePropsXxx = CommonFormItemTypeProps &
  (
    | { type: 'input'; inputType: InputType }
    | { type: 'emoji'; value: number; onChange: (sign_in: number, sign: string) => void }
    | { type: 'validateCodeSend'; onClickSendCode?: () => void }
    | {
        type: 'optionSelector'
        ifOneLineLabel?: boolean
        value: string
        options: SelectorOption[]
        onChange: (value: string) => void
      }
  )
  • 引入第二个泛型参数 export type FormItemTypeProps<T extends FormItemType, U = string> = T extends 'input'
    • 并且给默认类型 ... = T extends 'input'

@/components/form/item/FormItem.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { FormItemType, FormItemTypeProps } from '@/components/form/item/FormItemType.ts'
import { InputEmoji } from '@/components/form/item/InputEmoji'
import { InputText } from '@/components/form/item/InputText'
import { InputValidateCodeSend } from '@/components/form/item/InputValidateCodeSend'
import { OptionSelector } from '@/components/form/item/OptionSelector'

interface Props<T extends FormItemType, U extends string | number = string> {
  className?: string
  formItemType: T
  formItemTypeProps: FormItemTypeProps<T, U>
}

export function FormItem<T extends FormItemType, U extends string | number = string>(
  props: Props<T, U>
) {
  const { className, formItemType, formItemTypeProps } = props
  const renderContent = () => {
    // TS 在 switch (formItemType) 中不会把泛型 T 缩窄为字面量
    // 因此 formItemTypeProps 仍为联合类型
    // 展开到各具体组件时 value 等属性类型不兼容
    // 在各分支断言为对应字面量类型的 props
    switch (formItemType) {
      case 'input':
        return (
          <InputText
            type={formItemType}
            {...(formItemTypeProps as FormItemTypeProps<'input'>)}
            className={className}
          />
        )
      case 'emoji':
        return (
          <InputEmoji
            type={formItemType}
            {...(formItemTypeProps as FormItemTypeProps<'emoji'>)}
            className={className}
          />
        )
      case 'validateCodeSend':
        return (
          <InputValidateCodeSend
            type={formItemType}
            {...(formItemTypeProps as FormItemTypeProps<'validateCodeSend'>)}
            className={className}
          />
        )
      case 'optionSelector':
        return (
          <OptionSelector<U>
            type={formItemType}
            {...(formItemTypeProps as FormItemTypeProps<'optionSelector', U>)}
            className={className}
          />
        )
      default:
        return null
    }
  }
  return <>{renderContent()}</>
}
  • 泛型可选参数需要给默认类型 interface Props<T extends FormItemType, U extends string | number = string>
  • 类型传参 formItemTypeProps: FormItemTypeProps<T, U>
  • case 'optionSelector': 收窄类型
    • <OptionSelector<U> type={formItemType} {...(formItemTypeProps as FormItemTypeProps<'optionSelector', U>)} .../>

实现 OptionSelector ⇧

@/components/form/item/OptionSelector.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import type { SelectorOption } from '@/components/form/item/FormItemType'
import { cn } from 'cn'

interface Props<T> {
  // 仅用作区分 FormItemType 类型
  type?: 'optionSelector'
  className?: string
  // for 属性,用于内部 input 标签 id 属性联动
  labelFor?: string
  label?: string
  hasLabelColon?: boolean
  ifOneLineLabel?: boolean
  errorHint?: string
  hasErrorPlaceholder?: boolean
  value?: T
  options?: SelectorOption<T>[]
  placeholder?: string
  onChange?: (value: T) => void
  onBlur?: () => void
  onFocus?: () => void
  maxWidth?: string
}

export const OptionSelector = <T extends string | number>({
  className,
  label,
  ifOneLineLabel = false,
  labelFor,
  hasLabelColon = true,
  errorHint,
  hasErrorPlaceholder = true,
  placeholder,
  value,
  options,
  onChange,
  onBlur,
  onFocus,
  maxWidth = '12em',
}: Props<T>) => {
  const labelForId = labelFor && `form-item-select-${labelFor}`
  const labelChildren = (
    <>
      {label}
      {hasLabelColon ? ':' : ''}
    </>
  )
  const labelTag = (
    <label {...(labelForId ? { htmlFor: labelForId } : {})} className="form-label-sc">
      {labelChildren}
    </label>
  )
  const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
    onChange?.(e.target.value as T)
  }
  return (
    <section style={{ maxWidth }} className={cn('form-item-sc', className)}>
      <div className={cn('form-item-content-sc', ifOneLineLabel ? 'flex-row' : 'flex-col')}>
        <span className="flex items-center">{label && labelTag}</span>
        <select
          id={labelForId}
          value={value}
          onChange={handleChange}
          onBlur={onBlur}
          onFocus={onFocus}
          className={cn(
            'where:(text-1em)',
            'grow-1 min-h-[var(--input-min-height)] p-x-.5em',
            'b-1 rounded-[var(--input-radius)] shadow-[inset_0_0_3px_var(--input-shadow)]',
            errorHint ? 'b-[var(--error-color)]' : 'b-[var(--input-border-color)]'
          )}
          placeholder={placeholder}>
          {options?.map((option) => (
            <option key={option.value} value={option.value}>
              {option.label}
            </option>
          ))}
        </select>
      </div>
      {(errorHint || hasErrorPlaceholder) && (
        <span className="form-item-error-sc w-fit buzz">{errorHint ?? <>&nbsp;</>}</span>
      )}
    </section>
  )
}

@/modules/statistics/ChartsSummary.tsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { TagAmountRank } from '@/modules/statistics/TagAmountRank'
import { AmountProportionChart } from '@/modules/statistics/AmountProportionChart'
import { DateAmountChart } from '@/modules/statistics/DateAmountChart'
import { cn } from 'cn'
import type { RankChartItem, lineChartsItem, pieChartsItem } from '@/modules/statistics/chartData'
import { FormItem } from '@/components/form/item/FormItem'
import { useState } from 'react'
import type { TabKind } from '@/global'

interface Props {
  className?: string
  startDate: string
  endDate: string
}

export const ChartsSummary: React.FC<Props> = ({ className, startDate, endDate }) => {
  console.log('ChartsSummary_______________________')
  console.log('%c⧭', 'color: #807160', endDate)
  console.log('%c⧭', 'color: #731d1d', startDate)
  console.log('_______________________ChartsSummary')

  const lineChartItems: lineChartsItem[] = [
    { date: '2026-12-01', amount: 1200 },
    { date: '2026-12-02', amount: 2300 },
    { date: '2026-12-03', amount: 2300 },
    { date: '2026-12-04', amount: 2300 },
    { date: '2026-12-05', amount: 2300 },
    { date: '2026-12-06', amount: 2300 },
    { date: '2026-12-30', amount: 1800 },
  ].map((item) => ({ x: item.date, y: item.amount / 100 }))

  const pieChartItems: pieChartsItem[] = [
    { amount: 10480, name: 'Search Engine' },
    { amount: 7350, name: 'Direct' },
    { amount: 5800, name: 'Email' },
    { amount: 4840, name: 'Union Ads' },
    { amount: 3000, name: 'Video Ads' },
  ].map((item) => ({ name: item.name, value: item.amount / 100 }))

  const rankChartItems: RankChartItem[] = [
    { id: 1, tag: { sign: '😄', name: '房租', tag_id: 1 }, amount: 3112, percent: 11 },
    { id: 2, tag: { sign: '💰', name: '工资', tag_id: 2 }, amount: 32112, percent: 56 },
    { id: 3, tag: { sign: '💵', name: '奖金', tag_id: 3 }, amount: 12323, percent: 33 },
  ]

  const [kind, setKind] = useState<TabKind>('expenses')

  return (
    <div className={className}>
      {/* 类型选择器 */}
      <div className={cn('form-sc w-full mt-1em px-1.5em')}>
        <FormItem
          formItemType="optionSelector"
          formItemTypeProps={{
            label: '类型',
            ifOneLineLabel: true,
            labelFor: 'kind',
            placeholder: '请选择类型',
            value: kind,
            onChange: (value: TabKind) => setKind(value),
            // onBlur: () => {},
            // onFocus: () => {},
            options: [
              { value: 'expenses', label: '支出' },
              { value: 'incomes', label: '收入' },
            ],
            hasErrorPlaceholder: false,
            maxWidth: '12em',
          }}
        />
      </div>

      {/* 折线图 */}
      <DateAmountChart chartData={lineChartItems} className={cn('h-160px px-1.5em')} />

      {/* 饼图 */}
      <AmountProportionChart chartData={pieChartItems} className={cn('h-320px px-.5em')} />

      {/* 排名条 */}
      <TagAmountRank chartData={rankChartItems} className={cn('h-360px px-.5em')} />
    </div>
  )
}

后续单独优化二次封装 echarts 准备实现 ⇧

  • 按需依赖引入 echarts 组件
  • 组件化封装复用,零侵入业务,业务图表(折线图、柱状图、饼图)全部基于基础图表组件
  • 统一支持自定义 loading 加载状态、空数据兜底样式
  • 挂载与销毁图表实例,防止内存泄漏
    • 使用ref代替id的dom(防止id重复性)挂载
  • 对比使用 监听 window 的 resize 事件 和 ResizeObserver 监听
    • 使用 reactuse 的 useElementSize
    • 使用 reactuse 的 useResizeObserver
    • 自动监听窗口变化、自适应重绘,自动调整图表大小
    • 重绘防抖;弹窗/隐藏容器展示图表延迟重绘
  • 对外抛出实例、配置,以供二次配置
    • 交互事件
  • 使用组件或钩子函数代替 tooltip 中 formatter 的 html 与富文本(此项目弃用)
    • 并使用安全的转义 DOMPurify 来处理 html
  • 皮肤主题动态切换
  • ECharts 图表导出 使用 toolbox.feature.saveAsImage 或通过 chart.getDataURL() 获取图表数据并导出

·未完待续·

参考文章

相关文章

  • 无

  • 作者: Joel
  • 文章链接:
  • 版权声明
  • 非自由转载-非商用-非衍生-保持署名