defaultG2Config.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*
  2. * @description: 此处是业务组件的代码案例
  3. * @Date: 2023-06-06 15:45:07
  4. */
  5. // vue 组件片段
  6. export const defaultG2VueContent = `
  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 'g2' + this.config.code
  35. }
  36. },
  37. methods: {
  38. // 联动需要调用次接口
  39. newChart (config) {
  40. this.chart = new config.g2Plots['Line'](this.chatId, {
  41. renderer: 'svg',
  42. // 仪表盘缩放状态下,点击准确
  43. supportCSSTransform: true,
  44. ...config.option
  45. })
  46. this.chart.render()
  47. },
  48. },
  49. mounted(){
  50. this.newChart(this.config)
  51. },
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. // 此处书写样式,支持scss
  56. </style>
  57. `
  58. // 配置 片段
  59. export const defaultG2SettingContent = `
  60. // 这是一个配置案例
  61. // 组件备注名称
  62. const title = 'g2案例'
  63. // 右侧配置项
  64. const setting = [
  65. {
  66. label: '维度',
  67. // 设置组件类型, select / input / colorPicker
  68. type: 'select',
  69. // 字段
  70. field: 'xField',
  71. optionField: 'xField', // 对应options中的字段
  72. // 是否多选
  73. multiple: false,
  74. // 绑定的值
  75. value: '',
  76. // tab页。 data: 数据, custom: 自定义
  77. tabName: 'data'
  78. },
  79. {
  80. label: '指标',
  81. // 设置组件类型
  82. type: 'select',
  83. // 字段
  84. field: 'yField',
  85. // 对应options中的字段
  86. optionField: 'yField',
  87. // 是否多选
  88. multiple: false,
  89. value: '',
  90. tabName: 'data'
  91. },
  92. /** 样式配置 **/
  93. // 图表 graph
  94. {
  95. label: '曲线宽度',
  96. type: 'inputNumber',
  97. field: 'lineStyle_lineWidth',
  98. optionField: 'lineStyle.lineWidth',
  99. value: 2,
  100. tabName: 'custom',
  101. groupName: 'graph'
  102. },
  103. {
  104. label: '曲线颜色',
  105. type: 'gradual',
  106. field: 'lineStyle_stroke',
  107. optionField: 'lineStyle.stroke',
  108. value: 'l(0) 0:#5F92F9 1:#62FF00',
  109. tabName: 'custom',
  110. groupName: 'graph'
  111. },
  112. // 网格线 grid
  113. {
  114. label: '虚线',
  115. type: 'switch',
  116. field: 'yAxis_grid_line_style_lineDash',
  117. optionField: 'yAxis.grid.line.style.lineDash',
  118. value: 0,
  119. active: 5,
  120. inactive: 0,
  121. tabName: 'custom',
  122. groupName: 'grid'
  123. },
  124. {
  125. label: '宽度',
  126. type: 'inputNumber',
  127. field: 'yAxis_grid_line_style_lineWidth',
  128. optionField: 'yAxis.grid.line.style.lineWidth',
  129. value: 1,
  130. tabName: 'custom',
  131. groupName: 'grid'
  132. },
  133. {
  134. label: '颜色',
  135. type: 'colorPicker',
  136. field: 'yAxis_grid_line_style_stroke',
  137. optionField: 'yAxis.grid.line.style.stroke',
  138. value: '#d0d0d0',
  139. tabName: 'custom',
  140. groupName: 'grid'
  141. },
  142. // 图例 legend
  143. // X轴 xAxis
  144. {
  145. label: '标题',
  146. type: 'input',
  147. field: 'xAxis_title_text',
  148. optionField: 'xAxis.title.text',
  149. value: '',
  150. tabName: 'custom',
  151. groupName: 'xAxis'
  152. },
  153. {
  154. label: '标题位置',
  155. type: 'select',
  156. field: 'xAxis_title_position',
  157. optionField: 'xAxis.title.position',
  158. value: 'end',
  159. tabName: 'custom',
  160. options: [
  161. {
  162. label: '左',
  163. value: 'start'
  164. },
  165. {
  166. label: '中',
  167. value: 'center'
  168. },
  169. {
  170. label: '右',
  171. value: 'end'
  172. }],
  173. groupName: 'xAxis'
  174. },
  175. {
  176. label: '标题字体大小',
  177. type: 'inputNumber',
  178. field: 'xAxis_title_style_fontSize',
  179. optionField: 'xAxis.title.style.fontSize',
  180. value: 12,
  181. tabName: 'custom',
  182. groupName: 'xAxis'
  183. },
  184. {
  185. label: '标题颜色',
  186. type: 'colorPicker',
  187. field: 'xAxis_title_style_fill',
  188. optionField: 'xAxis.title.style.fill',
  189. // 是否多选
  190. multiple: false,
  191. value: '#8C8C8C',
  192. tabName: 'custom',
  193. groupName: 'xAxis'
  194. },
  195. {
  196. label: '标签大小',
  197. type: 'inputNumber',
  198. field: 'xAxis_label_style_fontSize',
  199. optionField: 'xAxis.label.style.fontSize',
  200. value: 12,
  201. tabName: 'custom',
  202. groupName: 'xAxis'
  203. },
  204. {
  205. label: '标签颜色',
  206. type: 'colorPicker',
  207. field: 'xAxis_label_style_fill',
  208. optionField: 'xAxis.label.style.fill',
  209. // 是否多选
  210. multiple: false,
  211. value: '#8C8C8C',
  212. tabName: 'custom',
  213. groupName: 'xAxis'
  214. },
  215. {
  216. label: '轴线宽度',
  217. type: 'inputNumber',
  218. field: 'xAxis_line_style_lineWidth',
  219. optionField: 'xAxis.line.style.lineWidth',
  220. value: 1,
  221. tabName: 'custom',
  222. groupName: 'xAxis'
  223. },
  224. {
  225. label: '轴线颜色',
  226. type: 'colorPicker',
  227. field: 'xAxis_line_style_stroke',
  228. optionField: 'xAxis.line.style.stroke',
  229. // 是否多选
  230. multiple: false,
  231. value: '#d0d0d0',
  232. tabName: 'custom',
  233. groupName: 'xAxis'
  234. },
  235. {
  236. label: '刻度线宽度',
  237. type: 'inputNumber',
  238. field: 'xAxis_tickLine_style_lineWidth',
  239. optionField: 'xAxis.tickLine.style.lineWidth',
  240. value: 1,
  241. tabName: 'custom',
  242. groupName: 'xAxis'
  243. },
  244. {
  245. label: '刻度线颜色',
  246. type: 'colorPicker',
  247. field: 'xAxis_tickLine_style_stroke',
  248. optionField: 'xAxis.tickLine.style.stroke',
  249. // 是否多选
  250. multiple: false,
  251. value: '#d0d0d0',
  252. tabName: 'custom',
  253. groupName: 'xAxis'
  254. },
  255. {
  256. label: '标签过多时旋转',
  257. type: 'switch',
  258. field: 'xAxis_label_autoRotate',
  259. optionField: 'xAxis.label.autoRotate',
  260. value: false,
  261. active: true,
  262. inactive: false,
  263. tabName: 'custom',
  264. groupName: 'xAxis'
  265. },
  266. {
  267. label: '标签过多时隐藏',
  268. type: 'switch',
  269. field: 'xAxis_label_autoHide',
  270. optionField: 'xAxis.label.autoHide',
  271. value: false,
  272. active: true,
  273. inactive: false,
  274. tabName: 'custom',
  275. groupName: 'xAxis'
  276. },
  277. {
  278. label: '标签过长时省略',
  279. type: 'switch',
  280. field: 'xAxis_label_autoEllipsis',
  281. optionField: 'xAxis.label.autoEllipsis',
  282. value: false,
  283. active: true,
  284. inactive: false,
  285. tabName: 'custom',
  286. groupName: 'xAxis'
  287. },
  288. // Y轴 yAxis
  289. {
  290. label: '标题',
  291. type: 'input',
  292. field: 'yAxis_title_text',
  293. optionField: 'yAxis.title.text',
  294. value: '',
  295. tabName: 'custom',
  296. groupName: 'yAxis'
  297. },
  298. {
  299. label: '标题位置',
  300. type: 'select',
  301. field: 'yAxis_title_position',
  302. optionField: 'yAxis.title.position',
  303. value: 'end',
  304. tabName: 'custom',
  305. options: [
  306. {
  307. label: '上',
  308. value: 'end'
  309. },
  310. {
  311. label: '中',
  312. value: 'center'
  313. },
  314. {
  315. label: '下',
  316. value: 'start'
  317. }],
  318. groupName: 'yAxis'
  319. },
  320. {
  321. label: '标题字体大小',
  322. type: 'inputNumber',
  323. field: 'yAxis_title_style_fontSize',
  324. optionField: 'yAxis.title.style.fontSize',
  325. value: 12,
  326. tabName: 'custom',
  327. groupName: 'yAxis'
  328. },
  329. {
  330. label: '标题颜色',
  331. type: 'colorPicker',
  332. field: 'yAxis_title_style_fill',
  333. optionField: 'yAxis.title.style.fill',
  334. // 是否多选
  335. multiple: false,
  336. value: '#8C8C8C',
  337. tabName: 'custom',
  338. groupName: 'yAxis'
  339. },
  340. {
  341. label: '显示标签',
  342. type: 'switch',
  343. field: 'yAxis_label_style_opacity',
  344. optionField: 'yAxis.label.style.opacity',
  345. value: 1,
  346. active: 1,
  347. inactive: 0,
  348. tabName: 'custom',
  349. groupName: 'yAxis'
  350. },
  351. {
  352. label: '标签字体大小',
  353. type: 'inputNumber',
  354. field: 'yAxis_label_style_fontSize',
  355. optionField: 'yAxis.label.style.fontSize',
  356. value: 12,
  357. tabName: 'custom',
  358. groupName: 'yAxis'
  359. },
  360. {
  361. label: '标签字体颜色',
  362. type: 'colorPicker',
  363. field: 'yAxis_label_style_fill',
  364. optionField: 'yAxis.label.style.fill',
  365. // 是否多选
  366. multiple: false,
  367. value: '#8C8C8C',
  368. tabName: 'custom',
  369. groupName: 'yAxis'
  370. },
  371. {
  372. label: '轴线宽度',
  373. type: 'inputNumber',
  374. field: 'yAxis_line_lineWidth',
  375. optionField: 'yAxis.line.style.lineWidth',
  376. value: 0,
  377. tabName: 'custom',
  378. groupName: 'yAxis'
  379. },
  380. {
  381. label: '轴线颜色',
  382. type: 'colorPicker',
  383. field: 'yAxis_line_stroke',
  384. optionField: 'yAxis.line.style.stroke',
  385. // 是否多选
  386. multiple: false,
  387. value: '#d0d0d0',
  388. tabName: 'custom',
  389. groupName: 'yAxis'
  390. },
  391. // 边距 padding
  392. {
  393. label: '图表边距',
  394. type: 'padding',
  395. field: 'appendPadding',
  396. optionField: 'appendPadding',
  397. value: [16, 16, 16, 16],
  398. tabName: 'custom',
  399. groupName: 'padding'
  400. }
  401. ]
  402. // 模拟数据
  403. const data = [
  404. { Date: '2010-01', scales: 1998 },
  405. { Date: '2010-02', scales: 1850 },
  406. { Date: '2010-03', scales: 1720 },
  407. { Date: '2010-04', scales: 1818 },
  408. { Date: '2010-05', scales: 1920 },
  409. { Date: '2010-06', scales: 1802 },
  410. { Date: '2010-07', scales: 1945 },
  411. { Date: '2010-08', scales: 1856 },
  412. { Date: '2010-09', scales: 2107 },
  413. { Date: '2010-10', scales: 2140 }
  414. ]
  415. const option = {
  416. // 数据将要放入到哪个字段中
  417. dataKey: 'data',
  418. data,
  419. color: '',
  420. appendPadding: [16, 16, 16, 16], // 设置图标的边距
  421. xField: 'Date',
  422. yField: 'scales',
  423. smooth: true,
  424. lineStyle: {
  425. lineWidth: 2,
  426. stroke: 'l(0) 0:#5F92F9 1:#62FF00'
  427. },
  428. xAxis: {
  429. title: {
  430. text: '',
  431. position: 'end',
  432. style: {
  433. fill: '#8C8C8C',
  434. fontSize: 12
  435. }
  436. },
  437. label: {
  438. autoRotate: false,
  439. autoHide: false,
  440. autoEllipsis: true,
  441. style: {
  442. fill: '#8C8C8C',
  443. fontSize: 12
  444. }
  445. },
  446. line: {
  447. style: {
  448. stroke: '#d0d0d0',
  449. lineWidth: 1
  450. }
  451. },
  452. tickLine: {
  453. style: {
  454. stroke: '#d0d0d0',
  455. lineWidth: 1
  456. }
  457. }
  458. },
  459. yAxis: {
  460. title: {
  461. text: '',
  462. position: 'end',
  463. autoRotate: false,
  464. // rotation: Math.PI / 2,
  465. style: {
  466. fill: '#8C8C8C',
  467. fontSize: 12
  468. }
  469. },
  470. grid: {
  471. line: {
  472. style: {
  473. stroke: '#d0d0d0',
  474. lineWidth: 1,
  475. lineDash: [4, 5],
  476. strokeOpacity: 0.7
  477. }
  478. }
  479. },
  480. label: {
  481. style: {
  482. fill: '#8C8C8C',
  483. fontSize: 12,
  484. opacity: 1
  485. }
  486. },
  487. line: {
  488. style: {
  489. stroke: '#d0d0d0',
  490. lineWidth: 0
  491. }
  492. }
  493. }
  494. }
  495. export default {
  496. title,
  497. option,
  498. setting
  499. }
  500. `