UNPKG

react-garden

Version:

React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.

166 lines (152 loc) 4.1 kB
// ** React Imports import { forwardRef, useState } from 'react' // ** MUI Imports import Card from '@mui/material/Card' import TextField from '@mui/material/TextField' import CardHeader from '@mui/material/CardHeader' import CardContent from '@mui/material/CardContent' import InputAdornment from '@mui/material/InputAdornment' // ** Third Party Imports import format from 'date-fns/format' import DatePicker from 'react-datepicker' // ** Icons Imports import BellOutline from 'mdi-material-ui/BellOutline' import ChevronDown from 'mdi-material-ui/ChevronDown' // ** Component Import import ReactApexcharts from '~/@core/components/react-apexcharts' const columnColors = { bg: '#f8d3ff', series1: '#826af9', series2: '#d2b0ff' } const ApexColumnChart = () => { // ** States const [endDate, setEndDate] = useState(null) const [startDate, setStartDate] = useState(new Date()) const options = { chart: { offsetX: -10, stacked: true, parentHeightOffset: 0, toolbar: { show: false } }, plotOptions: { bar: { columnWidth: '15%', colors: { backgroundBarRadius: 10, backgroundBarColors: [columnColors.bg, columnColors.bg, columnColors.bg, columnColors.bg, columnColors.bg] } } }, responsive: [ { breakpoint: 600, options: { plotOptions: { bar: { columnWidth: '35%' } } } } ], dataLabels: { enabled: false }, legend: { position: 'top', horizontalAlign: 'left' }, colors: [columnColors.series1, columnColors.series2], stroke: { show: true, colors: ['transparent'] }, grid: { xaxis: { lines: { show: true } } }, xaxis: { categories: ['7/12', '8/12', '9/12', '10/12', '11/12', '12/12', '13/12', '14/12', '15/12'] }, fill: { opacity: 1 } } const series = [ { name: 'Apple', data: [90, 120, 55, 100, 80, 125, 175, 70, 88] }, { name: 'Samsung', data: [85, 100, 30, 40, 95, 90, 30, 110, 62] } ] const CustomInput = forwardRef((props, ref) => { const startDate = format(props.start, 'MM/dd/yyyy') const endDate = props.end !== null ? ` - ${format(props.end, 'MM/dd/yyyy')}` : null const value = `${startDate}${endDate !== null ? endDate : ''}` return ( <TextField {...props} size='small' value={value} inputRef={ref} InputProps={{ startAdornment: ( <InputAdornment position='start'> <BellOutline /> </InputAdornment> ), endAdornment: ( <InputAdornment position='end'> <ChevronDown /> </InputAdornment> ) }} /> ) }) const handleOnChange = dates => { const [start, end] = dates setStartDate(start) setEndDate(end) } return ( <Card> <CardHeader title='Data Science' titleTypographyProps={{ variant: 'h6' }} sx={{ flexDirection: ['column', 'row'], alignItems: ['flex-start', 'center'], '& .MuiCardHeader-action': { mb: 0 }, '& .MuiCardHeader-content': { mb: [2, 0] } }} action={ <DatePicker selectsRange endDate={endDate} selected={startDate} id='apexchart-column' startDate={startDate} onChange={handleOnChange} placeholderText='Click to select a date' customInput={<CustomInput start={startDate} end={endDate} />} /> } /> <CardContent> <ReactApexcharts options={options} series={series} type='bar' height={400} /> </CardContent> </Card> ) } export default ApexColumnChart