您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

122 行
2.7 KiB

  1. import PropTypes from 'prop-types';
  2. import { useState, useEffect } from 'react';
  3. // material-ui
  4. import { useTheme } from '@mui/material/styles';
  5. // third-party
  6. import ReactApexChart from 'react-apexcharts';
  7. // chart options
  8. const areaChartOptions = {
  9. chart: {
  10. height: 450,
  11. type: 'area',
  12. toolbar: {
  13. show: false
  14. }
  15. },
  16. dataLabels: {
  17. enabled: false
  18. },
  19. stroke: {
  20. curve: 'smooth',
  21. width: 2
  22. },
  23. grid: {
  24. strokeDashArray: 0
  25. }
  26. };
  27. // ==============================|| INCOME AREA CHART ||============================== //
  28. const IncomeAreaChart = ({ slot }) => {
  29. const theme = useTheme();
  30. const { primary, secondary } = theme.palette.text;
  31. const line = theme.palette.divider;
  32. const [options, setOptions] = useState(areaChartOptions);
  33. useEffect(() => {
  34. setOptions((prevState) => ({
  35. ...prevState,
  36. colors: [theme.palette.primary.main, theme.palette.primary[700]],
  37. xaxis: {
  38. categories:
  39. slot === 'month'
  40. ? ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  41. : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  42. labels: {
  43. style: {
  44. colors: [
  45. secondary,
  46. secondary,
  47. secondary,
  48. secondary,
  49. secondary,
  50. secondary,
  51. secondary,
  52. secondary,
  53. secondary,
  54. secondary,
  55. secondary,
  56. secondary
  57. ]
  58. }
  59. },
  60. axisBorder: {
  61. show: true,
  62. color: line
  63. },
  64. tickAmount: slot === 'month' ? 11 : 7
  65. },
  66. yaxis: {
  67. labels: {
  68. style: {
  69. colors: [secondary]
  70. }
  71. }
  72. },
  73. grid: {
  74. borderColor: line
  75. },
  76. tooltip: {
  77. theme: 'light'
  78. }
  79. }));
  80. }, [primary, secondary, line, theme, slot]);
  81. const [series, setSeries] = useState([
  82. {
  83. name: 'Page Views',
  84. data: [0, 86, 28, 115, 48, 210, 136]
  85. },
  86. {
  87. name: 'Sessions',
  88. data: [0, 43, 14, 56, 24, 105, 68]
  89. }
  90. ]);
  91. useEffect(() => {
  92. setSeries([
  93. {
  94. name: 'Page Views',
  95. data: slot === 'month' ? [76, 85, 101, 98, 87, 105, 91, 114, 94, 86, 115, 35] : [31, 40, 28, 51, 42, 109, 100]
  96. },
  97. {
  98. name: 'Sessions',
  99. data: slot === 'month' ? [110, 60, 150, 35, 60, 36, 26, 45, 65, 52, 53, 41] : [11, 32, 45, 32, 34, 52, 41]
  100. }
  101. ]);
  102. }, [slot]);
  103. return <ReactApexChart options={options} series={series} type="area" height={450} />;
  104. };
  105. IncomeAreaChart.propTypes = {
  106. slot: PropTypes.string
  107. };
  108. export default IncomeAreaChart;