广州矛调粤政易端
xusd
7 days ago d27794814b69d18aeb8ee96a46cae91d5613570c
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
/*
 * @Company: hugeInfo
 * @Author: lwh
 * @Date: 2023-04-01 14:42:46
 * @LastEditTime: 2023-04-01 16:43:21
 * @LastEditors: lwh
 * @Version: 1.0.0
 * @Description: 
 */
import React, { useEffect, useMemo, useState, useRef } from 'react';
import { useHistory } from 'react-router-dom';
import { Space, Swiper, Toast } from 'dingtalk-design-mobile';
import { AnnouncementOutlined, RightArrow2Outlined } from 'dd-icons';
import { Canvas, Chart, Interval } from '@antv/f2';
 
 
 
// 统计图表
const ChartDom = ({ data }) => {
  const newdata = [{ name: '0-6岁', color: '#A3DDFF', value: 13, center: '1', percent: 0.2 },
  { name: '7-15岁', color: '#52B4FF', value: 13, center: '1', percent: 0.1 },
  { name: '16-59岁', color: '#007FFF', value: 13, center: '1', percent: 0.1 },
  { name: '60-79岁', color: '#004DB3', value: 13, center: '1', percent: 0.1 },
  { name: '80岁+', color: '#002566', value: 13, center: '1', percent: 0.5 }]
 
  // const countActive = useMemo(() => {
  //   let color = ['#6665FF', '#F57F20', '#77DA82'];
  //   let obj = data.countData ? data.countData[tabActive.count].data : {};
  //   let num = 0;
  //   let count = 0;
  //   obj.annular?.forEach((x) => (count += x.value));
  //   obj.annular?.forEach((x, t) => {
  //     let percent = Number((x.value / count).toFixed(2));
  //     x.color = color[t];
  //     x.center = '1';
  //     x.percent = t === obj.annular.length - 1 ? 1 - num : percent;
  //     num = num + percent;
  //   });
  //   return obj;
  // });
 
  useEffect(() => {
    const context = document.getElementById('myChart').getContext('2d');
    const { props } = (
      <Canvas context={context} pixelRatio={window.devicePixelRatio}>
        <Chart data={newdata} coord={{ radius: 1, innerRadius: 0.7, transposed: true, type: 'polar' }}>
          <Interval
            x="center"
            y="percent"
            adjust="stack"
            color={{
              field: 'color',
              callback: (value) => value,
            }}
            selection={{
              selectedStyle: (record) => {
                const { yMax, yMin } = record;
                return { r: (yMax - yMin) * 1.1 };
              },
            }}
          />
        </Chart>
      </Canvas>
    );
    const chart = new Canvas(props);
    chart.render();
  }, [data]);
 
  return <canvas id="myChart" width="200" height="200"></canvas>;
};
 
export default ChartDom;