dataQuery.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts type="line" :opts="opts" :chartData="chartData" :onzoom="true" :ontouch="true" />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. service: Array,
  10. serviceTime: Array
  11. },
  12. data() {
  13. return {
  14. chartData: {},
  15. //您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  16. opts: {
  17. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  18. "#ea7ccc"
  19. ],
  20. padding: [15, 10, 0, 15],
  21. enableScroll: true,
  22. legend: {},
  23. xAxis: {
  24. disableGrid: true,
  25. itemCount: 5,
  26. scrollShow: true,
  27. },
  28. yAxis: {
  29. gridType: "dash",
  30. dashLength: 2
  31. },
  32. extra: {
  33. line: {
  34. type: "curve",
  35. width: 2,
  36. activeType: "hollow"
  37. }
  38. }
  39. }
  40. };
  41. },
  42. mounted() {
  43. this.getServerData();
  44. },
  45. methods: {
  46. getServerData() {
  47. const time = this.serviceTime.map(item => {
  48. return item.substring(0, 4)
  49. })
  50. let res = {
  51. categories: time,
  52. series: this.service
  53. };
  54. // this.opts.xAxis.itemCount = this.service[0].data.length
  55. this.chartData = JSON.parse(JSON.stringify(res));
  56. },
  57. }
  58. };
  59. </script>
  60. <style scoped>
  61. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  62. .charts-box {
  63. width: 100%;
  64. height: 300px;
  65. }
  66. </style>