defaultEchartsConfig.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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: '柱形颜色',
  119. type: 'colorPicker',
  120. field: 'color',
  121. optionField: 'color',
  122. value: '#007aff',
  123. tabName: 'custom',
  124. groupName: 'graph'
  125. },
  126. {
  127. label: 'x轴类型',
  128. type: 'input',
  129. field: 'xAxis_type',
  130. optionField: 'xAxis.type',
  131. value: 'category',
  132. tabName: 'custom',
  133. groupName: 'xAxis'
  134. },
  135. {
  136. label: '是否显示标签',
  137. type: 'switch',
  138. field: 'xAxis_axisLabel_show',
  139. optionField: 'xAxis.axisLabel.show',
  140. value: true,
  141. tabName: 'custom',
  142. groupName: 'xAxis'
  143. },
  144. {
  145. label: '标签旋转角度',
  146. type: 'inputNumber',
  147. field: 'xAxis_axisLabel_rotate',
  148. optionField: 'xAxis.axisLabel.rotate',
  149. value: 0,
  150. tabName: 'custom',
  151. groupName: 'xAxis'
  152. },
  153. {
  154. label: '标签颜色',
  155. type: 'colorPicker',
  156. field: 'xAxis_axisLabel_color',
  157. optionField: 'xAxis.axisLabel.color',
  158. value: '#fff',
  159. tabName: 'custom',
  160. groupName: 'xAxis'
  161. },
  162. {
  163. label: 'y轴类型',
  164. type: 'input',
  165. field: 'yAxis_type',
  166. optionField: 'yAxis.type',
  167. value: 'value',
  168. tabName: 'custom',
  169. groupName: 'yAxis'
  170. }
  171. ]
  172. // 模拟数据
  173. const data = [
  174. { Date: '2010-01', scales: 1998 },
  175. { Date: '2010-02', scales: 1850 },
  176. { Date: '2010-03', scales: 1720 },
  177. { Date: '2010-04', scales: 1818 },
  178. { Date: '2010-05', scales: 1920 },
  179. { Date: '2010-06', scales: 1802 },
  180. { Date: '2010-07', scales: 1945 },
  181. { Date: '2010-08', scales: 1856 },
  182. { Date: '2010-09', scales: 2107 },
  183. { Date: '2010-10', scales: 2140 }
  184. ]
  185. const option = {
  186. // 数据将要放入到哪个字段中
  187. dataKey: 'data',
  188. // 图表内边距
  189. appendPadding: [0, 0, 0, 0],
  190. data,
  191. //柱状图颜色
  192. color: '#007aff',
  193. appendPadding: [16, 16, 16, 16], // 设置图标的边距
  194. xField: 'Date',
  195. yField: 'scales',
  196. xAxis: {
  197. type:'category',
  198. data: [],
  199. axisLabel:{
  200. show:true,
  201. color:'#fff',
  202. rotate:0
  203. }
  204. },
  205. yAxis: {
  206. type: 'value'
  207. },
  208. series:[
  209. {
  210. data: [],
  211. type: 'bar',
  212. backgroundStyle: {
  213. color: '#fff'
  214. }
  215. }
  216. ]
  217. }
  218. export default {
  219. title,
  220. option,
  221. setting
  222. }
  223. `