health-chart.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. /* 查询健康指标图表
  3. * @param {Object} type 健康指标类型(1血糖,2血压,3体重,4腰围)
  4. * @param {Object} begin 记录开始时间
  5. * @param {Object} end 记录结束时间
  6. * @param {Object} gi_type 就餐时间段(0:无)
  7. */
  8. function queryChatByTypePromise(charType,begin, end, gi_type) {
  9. //拼请求内容
  10. var params = {};
  11. params.type = charType;
  12. params.begin = begin+" 00:00:00";
  13. params.end = end+" 23:59:59";
  14. params.gi_type = gi_type;
  15. d.show();
  16. return new Promise(function(resolve, reject) {
  17. //发送ajax请求
  18. sendPost("patient/health_index/chart", params, "json", "post", function() {
  19. queryChartFailed()
  20. }, function(res) {
  21. d.close();
  22. if (res.status == 200) {
  23. resolve(res)
  24. } else {
  25. //非200则为失败
  26. queryChartFailed(res);
  27. }
  28. });
  29. })
  30. }
  31. /**
  32. * 健康指标图表查询失败处理方法
  33. */
  34. function queryChartFailed(res) {
  35. d.close();
  36. if (res && res.msg) {
  37. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  38. } else {
  39. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  40. }
  41. }
  42. function buildData(value, max, min) {
  43. if (!!!value) {
  44. return;
  45. }
  46. if(value < min) {
  47. return {
  48. value: value,
  49. itemStyle: {
  50. normal: {
  51. color: '#47a8ef'
  52. }
  53. }
  54. }
  55. } else if(value > max) {
  56. return {
  57. value: value,
  58. itemStyle: {
  59. normal: {
  60. color: '#ff6a56'
  61. }
  62. }
  63. }
  64. } else {
  65. return {
  66. value: value,
  67. itemStyle: {
  68. normal: {
  69. color: '#323232'
  70. }
  71. }
  72. }
  73. }
  74. }
  75. function getChartOptions(type,yAxisName,xAxisData,seriesData) {
  76. var options = {
  77. tooltip: {
  78. trigger: 'axis'
  79. },
  80. grid:{x:40,y:20,x2:25,y2:20},
  81. toolbox:{show:false},
  82. calculable:false,
  83. xAxis:[{
  84. type:"category",
  85. boundaryGap:false,
  86. data:xAxisData,
  87. axisLabel:{margin:6}
  88. }],
  89. yAxis:[{name:yAxisName,type:"value"}],
  90. series:[{
  91. name: type == 1 ? '血糖' : type == 3 ? '体重' : '腰围',
  92. type:"line",
  93. symbol:"emptyCircle",
  94. itemStyle: {
  95. normal: {
  96. borderWidth: 8,
  97. color: '#0ad800',
  98. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  99. borderWidth: 2,
  100. color: "#5dd1d2",
  101. width: 4
  102. },
  103. nodeStyle: {
  104. borderWidth: 2,
  105. color: '#93DB70',
  106. borderColor: '#93DB70'
  107. }
  108. },
  109. emphasis: {
  110. label: {
  111. show: true
  112. }
  113. }
  114. },
  115. data: seriesData
  116. }]
  117. }
  118. return options;
  119. }
  120. function getChartOptions1(type,yAxisName,xAxisData,seriesData) {
  121. var options = {
  122. tooltip: {
  123. trigger: 'axis'
  124. },
  125. grid: {
  126. x: 30,
  127. y: 20,
  128. x2: 25,
  129. y2: 20
  130. },
  131. legend: {
  132. show: false,
  133. data: ['收缩压','舒张压']
  134. },
  135. toolbox: {
  136. show: false
  137. },
  138. calculable: false,
  139. xAxis: [{
  140. type: 'category',
  141. boundaryGap: false,
  142. data: xAxisData,
  143. axisLabel: {
  144. margin: 6
  145. }
  146. }],
  147. yAxis: [{
  148. name : yAxisName,
  149. type: 'value'
  150. }],
  151. series:seriesData
  152. }
  153. return options;
  154. }
  155. // type 健康指标类型(1血糖,2血压,3体重,4腰围)
  156. function createChartPromise(el,type,yAxisName,xAxisData,seriesData) {
  157. return new Promise(function(resolve, reject) {
  158. // 路径配置
  159. require.config({
  160. paths: {
  161. echarts: 'http://echarts.baidu.com/build/dist'
  162. }
  163. });
  164. require(['echarts',
  165. 'echarts/chart/line'] // 使用柱状图就加载bar模块,按需加载]
  166. ,function(echarts) {
  167. var myChart = echarts.init(el);
  168. // 为echarts对象加载数据
  169. if (type == 1 || type == 3 || type == 4) {
  170. myChart.setOption(getChartOptions(type,yAxisName,xAxisData,seriesData));
  171. resolve(myChart);
  172. }
  173. if (type == 2) {
  174. myChart.setOption(getChartOptions1(type,yAxisName,xAxisData,seriesData));
  175. resolve(myChart);
  176. }
  177. });
  178. })
  179. }