MachineryStatus.jsx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React, { useEffect, useMemo, useRef } from 'react';
  2. import * as echarts from 'echarts/core';
  3. import BasicChart from './BasicChart';
  4. import deepCopy from '@/utils/deepCopy';
  5. import { hex2Rgb } from '@/utils/color';
  6. const colorList = ['#FB9900', '#23E8AE', '#E63404', '#51D4FF', '#B8B2A9', '#C579FF'].map((x) => {
  7. const rgb = hex2Rgb(x);
  8. return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  9. {
  10. offset: 0,
  11. color: x, // 0% 处的颜色
  12. },
  13. {
  14. offset: 0.5,
  15. color: x, // 50% 处的颜色
  16. },
  17. {
  18. offset: 1,
  19. color: `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, 0)`, // 100% 处的颜色
  20. },
  21. ]);
  22. });
  23. const defaultOpt = {
  24. tooltip: {},
  25. grid: {
  26. left: 10,
  27. containLabel: true,
  28. },
  29. xAxis: {
  30. type: 'category',
  31. splitLine: {
  32. show: false,
  33. },
  34. axisTick: {
  35. show: false,
  36. },
  37. axisLabel: {
  38. color: '#fff',
  39. },
  40. },
  41. yAxis: {
  42. type: 'value',
  43. splitLine: {
  44. lineStyle: {
  45. color: ['rgba(255, 255, 255, 0.1)'],
  46. type: 'dashed',
  47. },
  48. },
  49. axisTick: {
  50. show: false,
  51. },
  52. axisLabel: {
  53. color: '#fff',
  54. },
  55. },
  56. series: [
  57. {
  58. type: 'bar',
  59. },
  60. ],
  61. };
  62. export default (props) => {
  63. const option = useMemo(() => deepCopy(defaultOpt), []);
  64. option.xAxis.data = props.source.map((x) => x.name);
  65. option.series[0].data = props.source.map((x, i) => ({
  66. value: x.value,
  67. itemStyle: {
  68. color: colorList[i % 6],
  69. },
  70. }));
  71. return <BasicChart title="农机状态统计" option={option} />;
  72. };