verColumnar.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div ref="chart" style="width: 100%; height: 400px;"></div>
  3. </template>
  4. <script>
  5. // import echarts from "echarts";
  6. export default {
  7. name: "BarChart",
  8. props: {
  9. verChartData: {
  10. type: Array,
  11. required: true
  12. },
  13. verCategories: {
  14. type: Array,
  15. required: true
  16. }
  17. },
  18. data() {
  19. return {
  20. bLeg: ["第一次评估", "第二次评估", "第三次评估"]
  21. };
  22. },
  23. mounted() {
  24. this.initializeChart();
  25. var _this = this;
  26. // window.addEventListener("resize", () => {
  27. // _this.renderChart();
  28. // // this.$forceUpdate();
  29. // });
  30. },
  31. methods: {
  32. initializeChart() {
  33. const chart = this.$echarts.init(this.$refs.chart);
  34. const options = {
  35. xAxis: {
  36. type: "value",
  37. max: 5
  38. },
  39. tooltip: {},
  40. legend: {
  41. data: this.bLeg,
  42. bottom: 0 // 将图例显示在底部
  43. },
  44. grid: {
  45. containLabel: true //设置自适应画布大小状态为开,也可通过设置left左移实现相同效果。
  46. },
  47. yAxis: {
  48. type: "category",
  49. data: this.verCategories
  50. },
  51. series: this.bLeg.map((legendItem, index) => ({
  52. name: legendItem,
  53. data: this.verChartData[index],
  54. type: "bar",
  55. barCategoryGap: "30%"
  56. }))
  57. // [
  58. // {
  59. // data: this.verChartData,
  60. // type: "bar",
  61. // barCategoryGap: "30%"
  62. // }
  63. // ]
  64. };
  65. chart.setOption(options);
  66. }
  67. }
  68. };
  69. </script>