resolveChartOption.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. export default (config, silent) => {
  2. const { viewType, option } = config;
  3. let o;
  4. switch(viewType) {
  5. case 'bar': {
  6. o = barConfig(option, silent);
  7. break;
  8. }
  9. case 'pie': {
  10. o = pieConfig(option, silent);
  11. break;
  12. }
  13. case 'line': {
  14. o = lineConfig(option, silent);
  15. break;
  16. }
  17. case 'scatter': {
  18. o = scatterConfig(option, silent);
  19. break;
  20. }
  21. case 'aggregateTable': {
  22. o = tableConfig(option, silent);
  23. break;
  24. }case 'dataView' : {
  25. o = tableConfig(option, silent);
  26. break;
  27. }
  28. default:{
  29. o = {};
  30. break;
  31. }
  32. }
  33. return o;
  34. }
  35. function barConfig(option, silent) {
  36. const { xAxis, serieses, xTitle, yTitle } = option;
  37. let o = {
  38. animation: !silent,
  39. tooltip : {
  40. show: !silent,
  41. trigger: "axis",
  42. axisPointer: {
  43. type: "cross",
  44. label: {
  45. backgroundColor: "#6a7985"
  46. }
  47. }
  48. },
  49. legend: {
  50. show: !silent
  51. },
  52. grid: {
  53. left: silent ? 0 : '10%',
  54. right: silent ? 0 : '10%',
  55. top: silent ? 0 : 60,
  56. bottom: silent ? 0 : 60,
  57. containLabel: !silent
  58. },
  59. xAxis: [{
  60. show: !silent,
  61. type: 'category',
  62. data: xAxis,
  63. name: xTitle || '横轴',
  64. }],
  65. yAxis: [{
  66. show: !silent,
  67. name: yTitle || '纵轴',
  68. type: 'value'
  69. }],
  70. series: serieses.map(s => {
  71. return {
  72. name: s.name,
  73. type: 'bar',
  74. data: s.value,
  75. showSymbol: !silent,
  76. silent,
  77. }
  78. })
  79. }
  80. return o;
  81. }
  82. function pieConfig(option, silent) {
  83. const { xAxis, columnName, serieses } = option;
  84. let o = {
  85. animation: !silent,
  86. grid: {
  87. left: silent ? 0 : '10%',
  88. right: silent ? 0 : '10%',
  89. top: silent ? 0 : 60,
  90. bottom: silent ? 0 : 60,
  91. containLabel: !silent
  92. },
  93. tooltip : {
  94. show: !silent,
  95. trigger: 'item',
  96. formatter: "{a} <br/>{b} : {c} ({d}%)"
  97. },
  98. legend: {
  99. show: !silent,
  100. data: xAxis
  101. },
  102. series : [
  103. {
  104. name: columnName,
  105. type: 'pie',
  106. // radius : '55%',
  107. // center: ['50%', '60%'],
  108. data: serieses[0].value,
  109. label: { show: !silent },
  110. labelLine: { show: !silent },
  111. itemStyle: {
  112. emphasis: {
  113. shadowBlur: 10,
  114. shadowOffsetX: 0,
  115. shadowColor: 'rgba(0, 0, 0, 0.5)'
  116. }
  117. },
  118. silent
  119. }
  120. ]
  121. };
  122. return o;
  123. }
  124. function lineConfig(option, silent) {
  125. const { serieses, xTitle, yTitle } = option;
  126. let o = {
  127. animation: !silent,
  128. grid: {
  129. left: silent ? 0 : '10%',
  130. right: silent ? 0 : '10%',
  131. top: silent ? 0 : 60,
  132. bottom: silent ? 0 : 60,
  133. containLabel: !silent
  134. },
  135. tooltip: {
  136. show: !silent,
  137. trigger: 'axis',
  138. axisPointer: {
  139. type: 'cross'
  140. }
  141. },
  142. legend: {
  143. show: !silent
  144. },
  145. xAxis: {
  146. show: !silent,
  147. name: xTitle,
  148. type: 'time'
  149. },
  150. yAxis: {
  151. show: !silent,
  152. name: yTitle,
  153. type: 'value'
  154. },
  155. series: serieses.map(s => {
  156. return {
  157. name: s.name,
  158. type: 'line',
  159. data: s.mdata.map(m => {
  160. return [m.date, m.value]
  161. }),
  162. showSymbol: !silent,
  163. silent
  164. }
  165. })
  166. };
  167. return o;
  168. }
  169. function scatterConfig(option, silent) {
  170. const { serieses, xTitle, yTitle } = option;
  171. let o = {
  172. animation: !silent,
  173. grid: {
  174. left: silent ? 10 : '10%',
  175. right: silent ? 10 : '10%',
  176. top: silent ? 10 : 60,
  177. bottom: silent ? 10 : 60,
  178. containLabel: !silent
  179. },
  180. tooltip : {
  181. show: !silent,
  182. showDelay : 0,
  183. axisPointer:{
  184. show: true,
  185. type : 'cross',
  186. lineStyle: {
  187. type : 'dashed',
  188. width : 1
  189. }
  190. }
  191. },
  192. legend: {
  193. show: !silent
  194. },
  195. xAxis : [
  196. {
  197. show: !silent,
  198. type : 'value',
  199. name: xTitle,
  200. scale:true,
  201. splitLine: {
  202. show: false
  203. }
  204. }
  205. ],
  206. yAxis : [
  207. {
  208. show: !silent,
  209. type : 'value',
  210. name: yTitle,
  211. scale:true,
  212. splitLine: {
  213. show: false
  214. }
  215. }
  216. ],
  217. series : serieses.map(s => {
  218. return {
  219. name: s.name,
  220. type: 'scatter',
  221. data: s.mdata.map(m => {
  222. return [m.date, m.value]
  223. }),
  224. silent
  225. }
  226. })
  227. };
  228. return o;
  229. }
  230. function tableConfig(option, silent) {
  231. const { columns, data } = option;
  232. let o = {
  233. columns,
  234. data: data.map((d, i) => {
  235. return { ...d, key: i}
  236. })
  237. };
  238. return o;
  239. }