永洪社区

标题: 如何点击自定义JS绘图中数据联动表格数据 [打印本页]

作者: yhdata_P8HODy1m    时间: 2024-7-6 18:05
标题: 如何点击自定义JS绘图中数据联动表格数据
请教如何通过点击自定义绘图中的图形数据来联动表格中的数据,点击表格中的数据可以把参数暴露出来让表格接收么,谢谢~

作者: 永洪tech_xh    时间: 2024-7-6 18:05
  1. // 为保证正常绘图,代码格式与所选格式需保持一致;
  2. // 请输入JS代码或前往官网复制示例代码;
  3. // 复制完代码后,请先将代码中的数据列替换为绑定的数据列,绑定的数据列从上至下依次为column1、column2......,option部分请添加options.data以引用绑定列,chart绘制的DOM id会自动替换为变量$container
  4. var weatherIcons = {
  5. 'Sunny': './data/asset/img/weather/sunny_128.png',
  6. 'Cloudy': './data/asset/img/weather/cloudy_128.png',
  7. 'Showers': './data/asset/img/weather/showers_128.png'
  8. };

  9. //跳转代码
  10. myChart.on('click', function (params) {
  11. console.log(params.name);
  12. window.location.replace('/bi/Viewer?proc=1&action=viewer&hback=true&db=公共/echarts/echarts!8d85!!94fe!!63a5!.db&platform=PC&browserType=chrome&wd=' + encodeURIComponent(params.name))
  13. // window.open('http://localhost:8080/bi/Viewer?proc=1&action=viewer&hback=true&db=echarts!8d85!!94fe!!63a5!.db&platform=PC&browserType=chrome&wd=' + encodeURIComponent(params.name));

  14. });


  15. option = {
  16. title: {
  17. text: '天气情况统计',
  18. subtext: '虚构数据',
  19. left: 'center'
  20. },
  21. tooltip : {
  22. trigger: 'item',
  23. formatter: "{a} <br/>{b} : {c} ({d}%)"
  24. },
  25. legend: {
  26. // orient: 'vertical',
  27. // top: 'middle',
  28. bottom: 10,
  29. left: 'center',
  30. data: ['西凉', '益州','兖州','荆州','幽州']
  31. },
  32. series : [
  33. {
  34. type: 'pie',
  35. radius : '65%',
  36. center: ['50%', '50%'],
  37. selectedMode: 'single',
  38. data:[
  39. {
  40. value:1548,
  41. name: '幽州',
  42. label: {
  43. normal: {
  44. formatter: [
  45. '{title|{b}}{abg|}',
  46. ' {weatherHead|天气}{valueHead|天数}{rateHead|占比}',
  47. '{hr|}',
  48. ' {Sunny|}{value|202}{rate|55.3%}',
  49. ' {Cloudy|}{value|142}{rate|38.9%}',
  50. ' {Showers|}{value|21}{rate|5.8%}'
  51. ].join('\n'),
  52. backgroundColor: '#eee',
  53. borderColor: '#777',
  54. borderWidth: 1,
  55. borderRadius: 4,
  56. rich: {
  57. title: {
  58. color: '#eee',
  59. align: 'center'
  60. },
  61. abg: {
  62. backgroundColor: '#333',
  63. width: '100%',
  64. align: 'right',
  65. height: 25,
  66. borderRadius: [4, 4, 0, 0]
  67. },
  68. Sunny: {
  69. height: 30,
  70. align: 'left',
  71. backgroundColor: {
  72. image: weatherIcons.Sunny
  73. }
  74. },
  75. Cloudy: {
  76. height: 30,
  77. align: 'left',
  78. backgroundColor: {
  79. image: weatherIcons.Cloudy
  80. }
  81. },
  82. Showers: {
  83. height: 30,
  84. align: 'left',
  85. backgroundColor: {
  86. image: weatherIcons.Showers
  87. }
  88. },
  89. weatherHead: {
  90. color: '#333',
  91. height: 24,
  92. align: 'left'
  93. },
  94. hr: {
  95. borderColor: '#777',
  96. width: '100%',
  97. borderWidth: 0.5,
  98. height: 0
  99. },
  100. value: {
  101. width: 20,
  102. padding: [0, 20, 0, 30],
  103. align: 'left'
  104. },
  105. valueHead: {
  106. color: '#333',
  107. width: 20,
  108. padding: [0, 20, 0, 30],
  109. align: 'center'
  110. },
  111. rate: {
  112. width: 40,
  113. align: 'right',
  114. padding: [0, 10, 0, 0]
  115. },
  116. rateHead: {
  117. color: '#333',
  118. width: 40,
  119. align: 'center',
  120. padding: [0, 10, 0, 0]
  121. }
  122. }
  123. }
  124. }
  125. },
  126. {value:535, name: '荆州'},
  127. {value:510, name: '兖州'},
  128. {value:634, name: '益州'},
  129. {value:735, name: '西凉'}
  130. ],
  131. itemStyle: {
  132. emphasis: {
  133. shadowBlur: 10,
  134. shadowOffsetX: 0,
  135. shadowColor: 'rgba(0, 0, 0, 0.5)'
  136. }
  137. }
  138. }
  139. ]
  140. };
复制代码
其中您需要修改部分window.location.replace('/bi/Viewer?proc=1&action=viewer&hback=true&db=公共/echarts/echarts!8d85!!94fe!!63a5!.db&platform=PC&browserType=chrome&wd=' + encodeURIComponent(params.name))为您对应的地址。

效果点击饼图,会将饼图所对应的地址通过wd参数传递给报告,进而您可以使用该参数对数据进行过滤。
(, 下载次数: 322)