defaultEchartsConfig.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * @description: 此处是业务组件的代码案例
  3. * @Date: 2023-06-06 15:45:07
  4. */
  5. // vue 组件片段
  6. export const defaultEchartsVueContent = `
  7. <!-- 这是一个代码案例 -->
  8. <template>
  9. <div
  10. :id="chatId"
  11. style="width: 100%;height: 100%"
  12. />
  13. </template>
  14. <script>
  15. export default {
  16. name: 'TestA',
  17. components: {
  18. },
  19. // 业务组件提供的props
  20. props: {
  21. config: {
  22. type: Object,
  23. default: () => ({})
  24. }
  25. },
  26. data () {
  27. return {
  28. chart: null,
  29. }
  30. },
  31. // 计算属性
  32. computed: {
  33. chatId(){
  34. return 'echarts' + this.config.code
  35. }
  36. },
  37. methods: {
  38. //响应式变化组件大小方法,无需改动
  39. onResize () {
  40. this.chart.resize({
  41. animation: {
  42. duration: 300,
  43. easing: 'linear'
  44. // delay: 500,
  45. }
  46. })
  47. },
  48. // 初始化图表
  49. newChart (config) {
  50. let option = config.option
  51. const xList=config.option.data.map(item=> item[config.option.xField])
  52. const yList=config.option.data.map(item=> item[config.option.yField])
  53. option.xAxis.data=xList
  54. option.series[0].data=yList
  55. const dom = document.getElementById(this.chatId)
  56. this.chart = config.echarts.init(dom)
  57. this.chart.setOption(option,true)
  58. },
  59. },
  60. mounted(){
  61. this.newChart(this.config)
  62. //响应式变化组件大小,无需改动
  63. const dragSelect = document.querySelector("#"+this.chatId)
  64. let pre = Date.now()
  65. const wait = 300
  66. const resizeObserver = new ResizeObserver(entries => {
  67. const now = Date.now()
  68. if (now - pre >= wait) {
  69. setTimeout(() => {
  70. this.onResize()
  71. }, wait)
  72. pre = Date.now()
  73. }
  74. })
  75. resizeObserver.observe(dragSelect)
  76. },
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. // 此处书写样式,支持scss
  81. </style>
  82. `
  83. // 配置 片段
  84. export const defaultEchartsSettingContent = `
  85. // 这是一个配置案例
  86. // 组件备注名称
  87. const title = 'echarts案例'
  88. // 右侧配置项
  89. const setting = [
  90. {
  91. label: '维度',
  92. // 设置组件类型, select / input / colorPicker
  93. type: 'select',
  94. // 字段
  95. field: 'xField',
  96. optionField: 'xField', // 对应options中的字段
  97. // 是否多选
  98. multiple: false,
  99. // 绑定的值
  100. value: '',
  101. // tab页。 data: 数据, custom: 自定义
  102. tabName: 'data'
  103. },
  104. {
  105. label: '指标',
  106. // 设置组件类型
  107. type: 'select',
  108. // 字段
  109. field: 'yField',
  110. // 对应options中的字段
  111. optionField: 'yField',
  112. // 是否多选
  113. multiple: false,
  114. value: '',
  115. tabName: 'data'
  116. },
  117. {
  118. label: 'x轴类型',
  119. type: 'input',
  120. field: 'xAxis_type',
  121. optionField: 'xAxis.type',
  122. value: 'category',
  123. tabName: 'custom',
  124. groupName: 'xAxis'
  125. },
  126. {
  127. label: 'y轴类型',
  128. type: 'input',
  129. field: 'yAxis_type',
  130. optionField: 'yAxis.type',
  131. value: 'value',
  132. tabName: 'custom',
  133. groupName: 'yAxis'
  134. }
  135. ]
  136. // 模拟数据
  137. const data = [
  138. { Date: '2010-01', scales: 1998 },
  139. { Date: '2010-02', scales: 1850 },
  140. { Date: '2010-03', scales: 1720 },
  141. { Date: '2010-04', scales: 1818 },
  142. { Date: '2010-05', scales: 1920 },
  143. { Date: '2010-06', scales: 1802 },
  144. { Date: '2010-07', scales: 1945 },
  145. { Date: '2010-08', scales: 1856 },
  146. { Date: '2010-09', scales: 2107 },
  147. { Date: '2010-10', scales: 2140 }
  148. ]
  149. const option = {
  150. // 数据将要放入到哪个字段中
  151. dataKey: 'data',
  152. data,
  153. color: '',
  154. appendPadding: [16, 16, 16, 16], // 设置图标的边距
  155. xField: 'Date',
  156. yField: 'scales',
  157. smooth: true,
  158. xAxis: {
  159. type:'category',
  160. data: []
  161. },
  162. yAxis: {
  163. type: 'value'
  164. },
  165. series:[
  166. {
  167. data: [],
  168. type:'line'
  169. }
  170. ]
  171. }
  172. export default {
  173. title,
  174. option,
  175. setting
  176. }
  177. `