11import * as React from 'react' ;
2- import { Card , CardHeader , CardContent } from '@mui/material' ;
3- import * as echarts from 'echarts' ;
4- import { useTranslate } from 'react-admin' ;
2+ import * as echarts from 'echarts/core' ;
3+ // Import bar charts, all suffixed with Chart
4+ import { LineChart } from 'echarts/charts' ;
5+
6+ // Import the title, tooltip, rectangular coordinate system, dataset and transform components
7+ import {
8+ TitleComponent ,
9+ TooltipComponent ,
10+ GridComponent ,
11+ DatasetComponent ,
12+ TransformComponent ,
13+ } from 'echarts/components' ;
14+ // Features like Universal Transition and Label Layout
15+ import { LabelLayout , UniversalTransition } from 'echarts/features' ;
16+
17+ // Import the Canvas renderer
18+ // Note that including the CanvasRenderer or SVGRenderer is a required step
19+ import { SVGRenderer } from 'echarts/renderers' ;
20+
521import { format , subDays , addDays } from 'date-fns' ;
622
723import { Order } from '../types' ;
24+ import type {
25+ DatasetComponentOption ,
26+ GridComponentOption ,
27+ LineSeriesOption ,
28+ TitleComponentOption ,
29+ TooltipComponentOption ,
30+ } from 'echarts' ;
831
932const lastDay = new Date ( ) ;
1033const lastMonthDays = Array . from ( { length : 30 } , ( _ , i ) => subDays ( lastDay , i ) ) ;
1134const aMonthAgo = subDays ( new Date ( ) , 30 ) ;
1235
36+ // Create an Option type with only the required components and charts via ComposeOption
37+ type ECOption = echarts . ComposeOption <
38+ | LineSeriesOption
39+ | TitleComponentOption
40+ | TooltipComponentOption
41+ | GridComponentOption
42+ | DatasetComponentOption
43+ > ;
44+
45+ echarts . use ( [
46+ TitleComponent ,
47+ TooltipComponent ,
48+ GridComponent ,
49+ DatasetComponent ,
50+ TransformComponent ,
51+ LineChart ,
52+ LabelLayout ,
53+ UniversalTransition ,
54+ SVGRenderer ,
55+ ] ) ;
56+
1357const dateFormatter = ( date : number ) : string =>
1458 new Date ( date ) . toLocaleDateString ( ) ;
1559
@@ -38,7 +82,6 @@ const getRevenuePerDay = (orders: Order[]): TotalByDay[] => {
3882
3983const OrderChart = ( props : { orders ?: Order [ ] } ) => {
4084 const { orders } = props ;
41- const translate = useTranslate ( ) ;
4285 const chartRef = React . useRef < HTMLDivElement > ( null ) ;
4386 const chartInstance = React . useRef < echarts . ECharts | null > ( null ) ;
4487
@@ -53,7 +96,7 @@ const OrderChart = (props: { orders?: Order[] }) => {
5396 const revenueData = getRevenuePerDay ( orders ) ;
5497
5598 // Configure the chart
56- const option = {
99+ const option : ECOption = {
57100 xAxis : {
58101 type : 'time' ,
59102 min : addDays ( aMonthAgo , 1 ) . getTime ( ) ,
@@ -90,8 +133,7 @@ const OrderChart = (props: { orders?: Order[] }) => {
90133 axisPointer : {
91134 type : 'line' ,
92135 lineStyle : {
93- type : 'dashed' ,
94- dashArray : [ 3 , 3 ] ,
136+ type : [ 3 , 3 ] ,
95137 } ,
96138 } ,
97139 } ,
@@ -156,14 +198,7 @@ const OrderChart = (props: { orders?: Order[] }) => {
156198 } ;
157199 } , [ orders ] ) ;
158200
159- return (
160- < Card >
161- < CardHeader title = { translate ( 'pos.dashboard.month_history' ) } />
162- < CardContent >
163- < div ref = { chartRef } style = { { width : '100%' , height : 300 } } />
164- </ CardContent >
165- </ Card >
166- ) ;
201+ return < div ref = { chartRef } style = { { width : '100%' , height : 300 } } /> ;
167202} ;
168203
169204interface TotalByDay {
0 commit comments