draw-charts.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. function drawPie(el, seriesData, seriesName, colors){
  2. var myCharts = echarts.init(document.getElementById(el));
  3. var options = {
  4. tooltip : {
  5. trigger: 'item',
  6. formatter: "{a} <br/>{b} : {c} ({d}%)"
  7. },
  8. color: colors,
  9. series : [
  10. {
  11. name: seriesName,
  12. type: 'pie',
  13. radius: '55%',
  14. center: ['50%', '60%'],
  15. label: {
  16. formatter: '{b}: {c} ({d}%)'
  17. },
  18. data: seriesData,
  19. hoverAnimation: false
  20. }
  21. ]
  22. };
  23. document.getElementById(el).removeAttribute("_echarts_instance_");
  24. myCharts.setOption(options);
  25. }
  26. function drawLine(el, xData, yDatas, color, legend){
  27. var myCharts = echarts.init(document.getElementById(el));
  28. var options = {
  29. tooltip: {
  30. trigger: 'axis'
  31. },
  32. color: color,
  33. grid: {
  34. left: '10px',
  35. right: '25px',
  36. bottom: '10px',
  37. top: '10px',
  38. containLabel: true
  39. },
  40. xAxis: {
  41. type: 'category',
  42. data: xData,
  43. boundaryGap: false,
  44. splitLine:{show: false}
  45. },
  46. yAxis: {
  47. type: 'value',
  48. splitLine:{show: false}
  49. },
  50. };
  51. var series = [];
  52. for(i=0; i<yDatas.length; i++){
  53. var data = yDatas[i];
  54. series.push({
  55. name: data.name,
  56. data: data.data,
  57. type: 'line'
  58. })
  59. }
  60. options.series = series;
  61. if(legend){
  62. options.legend = legend;
  63. options.grid.top = '30px';
  64. }
  65. document.getElementById(el).removeAttribute("_echarts_instance_");
  66. myCharts.setOption(options);
  67. }
  68. function drawBar(el, xData, yData, name, color, formatter){
  69. var myCharts = echarts.init(document.getElementById(el));
  70. var options = {
  71. color: color,
  72. tooltip : {
  73. trigger: 'axis',
  74. },
  75. grid: {
  76. left: '3%',
  77. right: '4%',
  78. bottom: '3%',
  79. top: '8%',
  80. containLabel: true
  81. },
  82. xAxis : [
  83. {
  84. type : 'category',
  85. data : xData,
  86. splitLine:{show: false},
  87. axisTick: {
  88. alignWithLabel: true
  89. }
  90. }
  91. ],
  92. yAxis : [{
  93. type : 'value',
  94. splitLine:{show: false}
  95. }],
  96. series : [{
  97. name: name,
  98. type:'bar',
  99. barWidth: '30%',
  100. data: yData,
  101. label: {
  102. normal: {
  103. show: true,
  104. position: 'top',
  105. formatter: formatter ? formatter : "",
  106. textStyle: {
  107. color: 'black',
  108. }
  109. }
  110. }
  111. }]
  112. };
  113. document.getElementById(el).removeAttribute("_echarts_instance_");
  114. myCharts.setOption(options);
  115. myCharts.on('click',function(a){
  116. var name = a.name;
  117. console.log(name);
  118. switch(name){
  119. case "咨询":
  120. openWebview('tuanduizixunxiangqing.html', {
  121. teamCode: teamCode,
  122. type: dateType
  123. })
  124. break;
  125. case "随访":
  126. openWebview('tuanduisuifangxiangqing.html', {
  127. teamCode: teamCode,
  128. type: dateType
  129. })
  130. break;
  131. case "代预约":
  132. openWebview('tuanduidaiyuyuexiangqing.html', {
  133. teamCode: teamCode,
  134. type: dateType
  135. })
  136. break;
  137. case "指导":
  138. openWebview('tuanduizhidaoxiangqing.html', {
  139. teamCode: teamCode,
  140. type: dateType
  141. })
  142. break;
  143. case "教育":
  144. openWebview('tuanduijiaoyuxiangqing.html', {
  145. teamCode: teamCode,
  146. type: dateType
  147. })
  148. break;
  149. default:
  150. break;
  151. }
  152. });
  153. }