11import dateFormat from 'date-fns/format' ;
2- // import echarts from 'echarts';
3- // import ReactEcharts from 'echarts-for-react ';
2+ import ReactEcharts from 'echarts-for-react ' ;
3+ import * as echarts from 'echarts' ;
44import React from 'react' ;
55
66import { groupBy } from '@/utils' ;
@@ -22,74 +22,73 @@ export const ViewChart: React.FC<IProps> = ({ data: propsData = [] }) => {
2222 return a ;
2323 } , [ ] ) ;
2424
25- // const option = {
26- // grid: {
27- // top: '3%',
28- // left: '3%',
29- // right: '4%',
30- // bottom: '3%',
31- // containLabel: true,
32- // },
33- // tooltip: {
34- // trigger: 'axis',
35- // formatter(d) {
36- // const target = d && d[0] && data[d[0].dataIndex];
25+ const option = {
26+ grid : {
27+ top : '3%' ,
28+ left : '3%' ,
29+ right : '4%' ,
30+ bottom : '3%' ,
31+ containLabel : true ,
32+ } ,
33+ tooltip : {
34+ trigger : 'axis' ,
35+ formatter ( d ) {
36+ const target = d && d [ 0 ] && data [ d [ 0 ] . dataIndex ] ;
3737
38- // return `日期:${target.updateAt}<br />访问量:${target.count}`;
39- // },
40- // },
41- // xAxis: {
42- // type: 'category',
43- // boundaryGap: false,
44- // data: data.map((d) => d.updateAt),
45- // },
46- // yAxis: {
47- // type: 'value',
48- // boundaryGap: [0, '100%'],
49- // },
50- // dataZoom: [
51- // {
52- // type: 'inside',
53- // },
54- // {
55- // handleIcon:
56- // 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
57- // handleSize: '80%',
58- // handleStyle: {
59- // color: 'var(--bg)',
60- // shadowBlur: 3,
61- // shadowColor: 'rgba(0, 0, 0, 0.6)',
62- // shadowOffsetX: 2,
63- // shadowOffsetY: 2,
64- // },
65- // },
66- // ],
67- // series: [
68- // {
69- // type: 'line',
70- // smooth: true,
71- // symbol: 'none',
72- // sampling: 'average',
73- // itemStyle: {
74- // color: 'rgb(255, 70, 131)',
75- // },
76- // areaStyle: {
77- // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
78- // {
79- // offset: 0,
80- // color: 'rgb(255, 158, 68)',
81- // },
82- // {
83- // offset: 1,
84- // color: 'rgb(255, 70, 131)',
85- // },
86- // ]),
87- // },
88- // data: data.map((d) => d.count),
89- // },
90- // ],
91- // };
92- // TOOD: replace echarts with antd-charts
93- // return <ReactEcharts option={option} />;
94- return null ;
38+ return `日期:${ target . updateAt } <br />访问量:${ target . count } ` ;
39+ } ,
40+ } ,
41+ xAxis : {
42+ type : 'category' ,
43+ boundaryGap : false ,
44+ data : data . map ( ( d ) => d . updateAt ) ,
45+ } ,
46+ yAxis : {
47+ type : 'value' ,
48+ boundaryGap : [ 0 , '100%' ] ,
49+ } ,
50+ dataZoom : [
51+ {
52+ type : 'inside' ,
53+ } ,
54+ {
55+ handleIcon :
56+ 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z' ,
57+ handleSize : '80%' ,
58+ handleStyle : {
59+ color : 'var(--bg)' ,
60+ shadowBlur : 3 ,
61+ shadowColor : 'rgba(0, 0, 0, 0.6)' ,
62+ shadowOffsetX : 2 ,
63+ shadowOffsetY : 2 ,
64+ } ,
65+ } ,
66+ ] ,
67+ series : [
68+ {
69+ type : 'line' ,
70+ smooth : true ,
71+ symbol : 'none' ,
72+ sampling : 'average' ,
73+ itemStyle : {
74+ color : 'rgb(255, 70, 131)' ,
75+ } ,
76+ areaStyle : {
77+ color : new echarts . graphic . LinearGradient ( 0 , 0 , 0 , 1 , [
78+ {
79+ offset : 0 ,
80+ color : 'rgb(255, 158, 68)' ,
81+ } ,
82+ {
83+ offset : 1 ,
84+ color : 'rgb(255, 70, 131)' ,
85+ } ,
86+ ] ) ,
87+ } ,
88+ data : data . map ( ( d ) => d . count ) ,
89+ } ,
90+ ] ,
91+ } ;
92+
93+ return < ReactEcharts key = { JSON . stringify ( option ) } option = { option } /> ;
9594} ;
0 commit comments