line.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts :type="type" :opts="opts" :legend="false" :errorShow="true" errorMessage="暂无数据" :chartData="chartData" v-if="chartData.categories.length > 0 && chartData.series.length > 0" />
  4. <u-empty v-else mode="data" />
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. // :chartData="chartData"
  10. // :errorShow="chartData.categories.length === 0 || chartData.series.length === 0"
  11. props: {
  12. //图表数据
  13. chartData: {
  14. type: Object,
  15. default: () => {
  16. return {
  17. categories: ["1月", "2月", "3月", "4月", "5月", "6月"],
  18. series: [{
  19. name: "无",
  20. data: []
  21. },
  22. {
  23. name: "无",
  24. data: []
  25. },
  26. {
  27. name: "无",
  28. data: []
  29. }
  30. ]
  31. };
  32. }
  33. },
  34. //图表类型
  35. type: {
  36. type: String,
  37. default: "line"
  38. }
  39. },
  40. watch: {
  41. chartData(newVal, oldVal) {
  42. console.log('newVal', newVal);
  43. }
  44. },
  45. data() {
  46. return {
  47. // chartData: {},
  48. //您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  49. opts: {
  50. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
  51. padding: [15, 10, 0, 15],
  52. enableScroll: false,
  53. legend: {
  54. show: false
  55. },
  56. dataLabel: false,
  57. dataPointShape: false,
  58. xAxis: {
  59. disableGrid: true
  60. },
  61. yAxis: {
  62. gridType: "dash",
  63. dashLength: 2
  64. },
  65. extra: {
  66. line: {
  67. type: "straight",
  68. width: 2,
  69. activeType: "hollow"
  70. }
  71. }
  72. }
  73. };
  74. },
  75. mounted() {
  76. this.getServerData();
  77. },
  78. methods: {
  79. getServerData() {
  80. //模拟从服务器获取数据时的延时
  81. setTimeout(() => {
  82. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  83. let res = {
  84. categories: ["1月", "2月", "3月", "4月", "5月", "6月"],
  85. series: [{
  86. name: "成交量A",
  87. data: [35, 8, 25, 37, 4, 20]
  88. },
  89. {
  90. name: "成交量B",
  91. data: [70, 40, 65, 100, 44, 68]
  92. },
  93. {
  94. name: "成交量C",
  95. data: [100, 80, 95, 150, 112, 132]
  96. }
  97. ]
  98. };
  99. // this.chartData = JSON.parse(JSON.stringify(res));
  100. }, 0);
  101. },
  102. }
  103. };
  104. </script>
  105. <style scoped>
  106. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  107. .charts-box {
  108. width: 100%;
  109. height: 300px;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. }
  114. </style>