ProblemCharts.jsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React, { useState } from 'react';
  2. import { Card } from 'antd';
  3. import * as echarts from 'echarts/core';
  4. import Chart from '@/components/chart';
  5. import { getStatProblem } from "@/service/stat";
  6. export default (props) => {
  7. const [option, setOption] = useState({});
  8. React.useEffect(() => {
  9. getStatProblem().then((res) => {
  10. setOption({
  11. tooltip: {
  12. trigger: 'axis',
  13. axisPointer: {
  14. type: 'cross',
  15. label: {
  16. backgroundColor: '#FB9900'
  17. }
  18. }
  19. },
  20. grid: {
  21. left: '3%',
  22. bottom: '3%',
  23. height: '90%',
  24. width: '90%',
  25. containLabel: true
  26. },
  27. xAxis: [
  28. {
  29. type: 'category',
  30. data: res.map(x => x.name),
  31. // boundaryGap: true,
  32. axisTick: {
  33. alignWithLabel: true,
  34. },
  35. axisLabel: {
  36. interval: 0,
  37. }
  38. }
  39. ],
  40. yAxis: [
  41. {
  42. type: 'value',
  43. minInterval: 1
  44. }
  45. ],
  46. series: [
  47. {
  48. type: 'bar',
  49. barWidth: '20%',
  50. itemStyle: {
  51. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  52. { offset: 0, color: '#FB9900' },
  53. { offset: 1, color: '#FFD38F' }
  54. ]),
  55. // barBorderRadius: [8, 0, 0, 0]
  56. },
  57. data: res.map(x => x.value),
  58. }
  59. // {
  60. // type: 'bar',
  61. // barWidth: '4%',
  62. // itemStyle: {
  63. // normal: {
  64. // color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
  65. // offset: 0,
  66. // color: "#FCA319" // 0% 处的颜色
  67. // }, {
  68. // offset: 1,
  69. // color: "#ED8224" // 100% 处的颜色
  70. // }], false),
  71. // barBorderRadius: [0, 0, 100, 0]
  72. // }
  73. // },
  74. // barGap: 0,
  75. // data: res.map(x => x.value)
  76. // }, {
  77. // type: 'pictorialBar',
  78. // itemStyle: {
  79. // borderWidth: '20%',
  80. // color: '#FEC05F'
  81. // },
  82. // symbol: 'path://M 0,0 l 120,0 l -30,60 l -120,0 z',
  83. // symbolSize: ['34%', '8'],
  84. // symbolOffset: ['-1', '-1'], // 左右 ,上下
  85. // symbolRotate: 0,
  86. // symbolPosition: 'end',
  87. // data: res.map(x => x.value),
  88. // z: 3
  89. // }
  90. ]
  91. });
  92. }).catch(console.error);
  93. }, []);
  94. return (
  95. <Card title="问题分类">
  96. <Chart option={option} style={props.style}></Chart>
  97. </Card>
  98. )
  99. }