0e3907dd58f87a3e35d8b75e1803e158e3a555f4.svn-base 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!-- 格式
  2. allData: {
  3. title: "下载名称",
  4. legend: [],
  5. xAxis: {},
  6. yAxis: {},
  7. series: []
  8. }
  9. -->
  10. <template>
  11. <v-chart @click="clickEvent" :options="chartData" />
  12. </template>
  13. <script>
  14. import ECharts from 'vue-echarts'
  15. // import "echarts/lib/chart/line"; // 折线图
  16. // import "echarts/lib/component/legend"; // 图例
  17. // import "echarts/lib/component/tooltip"; // 浮层显示
  18. // import "echarts/lib/component/toolbox"; // 下载工具等
  19. export default {
  20. props: ["allData"],
  21. components: {
  22. "v-chart": ECharts
  23. },
  24. data() {
  25. return {
  26. color: [
  27. "#1890ff",
  28. "#2fc25b",
  29. "#facc14",
  30. "#223273",
  31. "#8543e0",
  32. "#13c2c2",
  33. "#3436c7",
  34. "#f04864",
  35. "#4212af",
  36. "#ffda00",
  37. "#ff1e00",
  38. "#00bf32",
  39. "#ffe340",
  40. "#ffeb73",
  41. "#ff5640",
  42. "#ff8373",
  43. "#248f40",
  44. "#007c21",
  45. "#462b83",
  46. "#270672",
  47. "#bfaa30",
  48. "#a68e00",
  49. "#bf4030",
  50. "#a61300",
  51. "#38df64",
  52. "#64df85",
  53. "#7247d7",
  54. "#8d6dd7"
  55. ]
  56. };
  57. },
  58. computed: {
  59. chartData() {
  60. let data = {
  61. color: this.color,
  62. tooltip: {
  63. trigger: "axis",
  64. formatter: this.allData.formatter ? this.allData.formatter : {}
  65. },
  66. xAxis: this.allData.xAxis,
  67. yAxis: this.allData.yAxis,
  68. series: this.allData.series
  69. };
  70. if (this.allData.legend) {
  71. data.legend = this.allData.legend;
  72. }
  73. if (this.allData.grid) {
  74. data.grid = this.allData.grid;
  75. }
  76. if (this.allData.dataZoom) {
  77. data.dataZoom = this.allData.dataZoom;
  78. }
  79. if (this.allData.toolbox || this.allData.toolbox != false) {
  80. data.toolbox = this.allData.toolbox
  81. ? this.allData.toolbox
  82. : {
  83. show: true,
  84. right: 20,
  85. top: 5,
  86. feature: {
  87. saveAsImage: {
  88. name: this.allData.title
  89. ? this.allData.title
  90. : this.getNowFormatDate()
  91. }
  92. }
  93. };
  94. }
  95. if(this.allData.tooltip) {
  96. data.tooltip = this.allData.tooltip;
  97. }
  98. return data;
  99. }
  100. },
  101. methods: {
  102. clickEvent(data) {
  103. this.$emit("showInfo", data);
  104. },
  105. getNowFormatDate() {
  106. var date = new Date();
  107. var seperator1 = "-";
  108. var year = date.getFullYear();
  109. var month = date.getMonth() + 1;
  110. var strDate = date.getDate();
  111. if (month >= 1 && month <= 9) {
  112. month = "0" + month;
  113. }
  114. if (strDate >= 0 && strDate <= 9) {
  115. strDate = "0" + strDate;
  116. }
  117. if (this.allData.backgroundColor) {
  118. data.backgroundColor = this.allData.backgroundColor;
  119. }
  120. var currentdate = year + seperator1 + month + seperator1 + strDate;
  121. return currentdate;
  122. }
  123. }
  124. };
  125. </script>