BaseChartInfo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <a-modal
  3. title="历史曲线"
  4. :visible="visible"
  5. :confirm-loading="confirmLoading"
  6. :footer="null"
  7. :width="800"
  8. @cancel="handleCancel"
  9. >
  10. <div class="chart">
  11. <a-row type="flex" justify="space-between">
  12. <a-col :span="24">
  13. <a-form :form="form">
  14. <a-row type="flex" justify="end">
  15. <a-col :span="10">
  16. <a-form-item label="开始时间" :labelCol="BaseTool.Constant.labelCol" :wrapperCol="BaseTool.Constant.wrapperCol">
  17. <a-date-picker
  18. :format="BaseTool.Date.PICKER_NORM_DATETIME_PATTERN"
  19. v-model="queryParam.searchStartTime" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="10">
  23. <a-form-item label="结束时间" :labelCol="BaseTool.Constant.labelCol" :wrapperCol="BaseTool.Constant.wrapperCol">
  24. <a-date-picker
  25. :format="BaseTool.Date.PICKER_NORM_DATETIME_PATTERN"
  26. v-model="queryParam.searchEndTime" />
  27. </a-form-item>
  28. </a-col>
  29. <a-col :span="3">
  30. <a-form-item >
  31. <a-button type="primary" @click="getInfo">查询</a-button>
  32. </a-form-item>
  33. </a-col>
  34. </a-row>
  35. </a-form>
  36. </a-col>
  37. </a-row>
  38. <div>
  39. <div id="chart"></div>
  40. </div>
  41. </div>
  42. </a-modal>
  43. </template>
  44. <script>
  45. import { Chart } from '@antv/g2'
  46. export default {
  47. data () {
  48. return {
  49. form: this.$form.createForm(this),
  50. visible: false,
  51. confirmLoading: false,
  52. queryParam: {},
  53. chart1: null,
  54. dataList1: [],
  55. dataList: [
  56. { time: '2009/7/20 0:00', value: 32, type: 'aa' },
  57. { time: '2009/7/20 1:00', value: 8, type: 'bb' },
  58. { time: '2009/7/20 2:00', value: 28, type: 'aa' },
  59. { time: '2009/7/20 2:00', value: 6, type: 'bb' },
  60. { time: '2009/7/20 4:00', value: 5, type: 'aa' },
  61. { time: '2009/7/20 4:00', value: 13, type: 'bb' },
  62. { time: '2009/7/20 6:00', value: 12, type: 'aa' },
  63. { time: '2009/7/20 6:00', value: 31, type: 'bb' },
  64. { time: '2009/7/20 8:00', value: 1, type: 'aa' },
  65. { time: '2009/7/20 8:00', value: 16, type: 'bb' }
  66. ]
  67. }
  68. },
  69. created () {
  70. },
  71. mounted () {
  72. },
  73. methods: {
  74. base () {
  75. this.visible = true
  76. this.$nextTick(() => {
  77. this.createChart(this.dataList)
  78. })
  79. },
  80. getInfo () {
  81. },
  82. createChart (data) {
  83. this.chart1 && this.chart1.destroy()
  84. this.chart1 = new Chart({
  85. container: 'chart',
  86. autoFit: true,
  87. height: 440,
  88. padding: [16, 50, 64]
  89. })
  90. this.chart1.data(data)
  91. this.chart1.scale({
  92. time: {
  93. type: 'time',
  94. tickCount: 8,
  95. mask: 'M/DD HH:mm'
  96. },
  97. value: {
  98. min: 0
  99. }
  100. })
  101. this.chart1.legend({
  102. position: 'top',
  103. offsetY: 4
  104. })
  105. this.chart1.tooltip({
  106. showCrosshairs: true,
  107. shared: true
  108. })
  109. this.chart1.option('slider', {
  110. start: 0.001,
  111. end: 1,
  112. trendCfg: {
  113. isArea: false
  114. }
  115. })
  116. this.chart1
  117. .line()
  118. .position('time*value')
  119. .color('type')
  120. this.chart1.interaction('element-visible-filter')
  121. this.chart1
  122. .point()
  123. .color('type')
  124. .position('time*value')
  125. this.chart1.render()
  126. },
  127. handleCancel (e) {
  128. console.log('Clicked cancel button')
  129. this.visible = false
  130. }
  131. }
  132. }
  133. </script>
  134. <style>
  135. </style>