瀏覽代碼

Merge branch 'master' of http://git.ycjcjy.com/nanyang/machinery-admin

李志伟 3 年之前
父節點
當前提交
2c2d6ee564
共有 3 個檔案被更改,包括 70 行新增0 行删除
  1. 1
    0
      package.json
  2. 64
    0
      src/components/ECharts/index.jsx
  3. 5
    0
      src/components/ECharts/style.less

+ 1
- 0
package.json 查看文件

@@ -59,6 +59,7 @@
59 59
     "ali-oss": "^6.17.1",
60 60
     "antd": "^4.17.0",
61 61
     "classnames": "^2.3.0",
62
+    "echarts": "^5.3.1",
62 63
     "lodash": "^4.17.0",
63 64
     "md5": "^2.3.0",
64 65
     "moment": "^2.29.1",

+ 64
- 0
src/components/ECharts/index.jsx 查看文件

@@ -0,0 +1,64 @@
1
+import React, { useEffect, useRef } from 'react';
2
+import classNames from 'classnames';
3
+// 按需导入模块
4
+// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
5
+import * as echarts from 'echarts/core';
6
+// 引入图表,图表后缀都为 Chart
7
+import { LineChart } from 'echarts/charts';
8
+// 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
9
+import {
10
+  TitleComponent,
11
+  TooltipComponent,
12
+  GridComponent,
13
+  DatasetComponent,
14
+  TransformComponent,
15
+} from 'echarts/components';
16
+// 标签自动布局,全局过渡动画等特性
17
+import { LabelLayout, UniversalTransition } from 'echarts/features';
18
+// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
19
+import { CanvasRenderer } from 'echarts/renderers';
20
+
21
+// 注册必须的组件
22
+echarts.use([
23
+  TitleComponent,
24
+  TooltipComponent,
25
+  GridComponent,
26
+  DatasetComponent,
27
+  TransformComponent,
28
+  LineChart,
29
+  LabelLayout,
30
+  UniversalTransition,
31
+  CanvasRenderer,
32
+]);
33
+
34
+import Styles from './style.less';
35
+
36
+export default (props) => {
37
+  const domRef = useRef();
38
+  const echartsRef = useRef();
39
+
40
+  useEffect(() => {
41
+    echartsRef.current = echarts.init(domRef.current);
42
+    echartsRef.current.setOption(props.option);
43
+  }, []);
44
+
45
+  useEffect(() => {
46
+    if (echartsRef.current) {
47
+      echartsRef.current.setOption(props.option);
48
+    }
49
+  }, [props.option]);
50
+
51
+  useEffect(() => {
52
+    if (echartsRef.current) {
53
+      if (props.loading) {
54
+        echartsRef.current.showLoading();
55
+      } else {
56
+        echartsRef.current.hideLoading();
57
+      }
58
+    }
59
+  }, [props.loading]);
60
+
61
+  const classList = classNames(Styles.echarts, props.className);
62
+
63
+  return <div className={classList} ref={domRef} />;
64
+};

+ 5
- 0
src/components/ECharts/style.less 查看文件

@@ -0,0 +1,5 @@
1
+.echart {
2
+  width: 100%;
3
+  height: 100%;
4
+  min-height: 400px;
5
+}