|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { Card, CardHeader, CardContent } from '@mui/material'; |
3 | | -import * as echarts from 'echarts'; |
| 3 | +import * as echarts from 'echarts/core'; |
| 4 | +// Import bar charts, all suffixed with Chart |
| 5 | +import { LineChart } from 'echarts/charts'; |
| 6 | + |
| 7 | +// Import the title, tooltip, rectangular coordinate system, dataset and transform components |
| 8 | +import { |
| 9 | + TitleComponent, |
| 10 | + TooltipComponent, |
| 11 | + GridComponent, |
| 12 | + DatasetComponent, |
| 13 | + TransformComponent, |
| 14 | +} from 'echarts/components'; |
4 | 15 | import { useTranslate } from 'react-admin'; |
| 16 | +// Features like Universal Transition and Label Layout |
| 17 | +import { LabelLayout, UniversalTransition } from 'echarts/features'; |
| 18 | + |
| 19 | +// Import the Canvas renderer |
| 20 | +// Note that including the CanvasRenderer or SVGRenderer is a required step |
| 21 | +import { SVGRenderer } from 'echarts/renderers'; |
| 22 | + |
5 | 23 | import { format, subDays, addDays } from 'date-fns'; |
6 | 24 |
|
7 | 25 | import { Order } from '../types'; |
| 26 | +import type { |
| 27 | + DatasetComponentOption, |
| 28 | + GridComponentOption, |
| 29 | + LineSeriesOption, |
| 30 | + TitleComponentOption, |
| 31 | + TooltipComponentOption, |
| 32 | +} from 'echarts'; |
8 | 33 |
|
9 | 34 | const lastDay = new Date(); |
10 | 35 | const lastMonthDays = Array.from({ length: 30 }, (_, i) => subDays(lastDay, i)); |
11 | 36 | const aMonthAgo = subDays(new Date(), 30); |
12 | 37 |
|
| 38 | +// Create an Option type with only the required components and charts via ComposeOption |
| 39 | +type ECOption = echarts.ComposeOption< |
| 40 | + | LineSeriesOption |
| 41 | + | TitleComponentOption |
| 42 | + | TooltipComponentOption |
| 43 | + | GridComponentOption |
| 44 | + | DatasetComponentOption |
| 45 | +>; |
| 46 | + |
| 47 | +echarts.use([ |
| 48 | + TitleComponent, |
| 49 | + TooltipComponent, |
| 50 | + GridComponent, |
| 51 | + DatasetComponent, |
| 52 | + TransformComponent, |
| 53 | + LineChart, |
| 54 | + LabelLayout, |
| 55 | + UniversalTransition, |
| 56 | + SVGRenderer, |
| 57 | +]); |
| 58 | + |
13 | 59 | const dateFormatter = (date: number): string => |
14 | 60 | new Date(date).toLocaleDateString(); |
15 | 61 |
|
@@ -53,7 +99,7 @@ const OrderChart = (props: { orders?: Order[] }) => { |
53 | 99 | const revenueData = getRevenuePerDay(orders); |
54 | 100 |
|
55 | 101 | // Configure the chart |
56 | | - const option = { |
| 102 | + const option: ECOption = { |
57 | 103 | xAxis: { |
58 | 104 | type: 'time', |
59 | 105 | min: addDays(aMonthAgo, 1).getTime(), |
@@ -90,8 +136,7 @@ const OrderChart = (props: { orders?: Order[] }) => { |
90 | 136 | axisPointer: { |
91 | 137 | type: 'line', |
92 | 138 | lineStyle: { |
93 | | - type: 'dashed', |
94 | | - dashArray: [3, 3], |
| 139 | + type: [3, 3], |
95 | 140 | }, |
96 | 141 | }, |
97 | 142 | }, |
|
0 commit comments