sports.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. mui.init();
  2. var patient;
  3. //mui.plusReady(function(){
  4. // var self = plus.webview.currentWebview();
  5. // patient = self.patient;
  6. // getSportsInfo();
  7. drawPieChart();
  8. drawLineChart();
  9. //});
  10. function getSportsInfo(){
  11. }
  12. function drawPieChart(){
  13. var pieChart = echarts.init(document.getElementById('pieChart'));
  14. var option = {
  15. series: [
  16. {
  17. name:'今日步数',
  18. type:'pie',
  19. radius: ['90%', '100%'],
  20. startAngle: 270,
  21. legendHoverLink: false,
  22. hoverAnimation: false,
  23. avoidLabelOverlap: false,
  24. labelLine: {
  25. normal: {
  26. show: false
  27. }
  28. },
  29. data:[
  30. {
  31. value:3500,
  32. itemStyle:{
  33. normal:{
  34. color: '#17b3ec'
  35. }
  36. }
  37. },
  38. {
  39. value:6500,
  40. itemStyle:{
  41. normal:{
  42. color: '#e1e1e1'
  43. }
  44. }
  45. }
  46. ]
  47. }
  48. ]
  49. };
  50. pieChart.setOption(option);
  51. }
  52. function drawLineChart(){
  53. var now = new Date(),
  54. xData = [],
  55. yData = [],
  56. yData2 = [];
  57. for(var i=0; i<30; i++){
  58. var dat = new Date();
  59. dat.setDate(now.getDate() - i);
  60. xData.push(dat.format("yyyy-MM-dd"));
  61. yData.push(Math.random(0, 1) * 10000);
  62. yData2.push(10000);
  63. }
  64. var lastIndex = yData.length % 7;
  65. if(yData.length >7 ){
  66. var dataZoom_end = 100-(6/yData.length)*100;
  67. }else{
  68. var dataZoom_end = 0;
  69. }
  70. var lineCharts = echarts.init(document.getElementById('lineChart'));
  71. var options = {
  72. tooltip: {
  73. trigger: 'axis'
  74. },
  75. legend: {
  76. top: 'bottom',
  77. data:['运动步数', '目标值']
  78. },
  79. grid: {
  80. left: '10px',
  81. right: '10px',
  82. bottom: '30px',
  83. top: '10px',
  84. containLabel: true
  85. },
  86. xAxis: {
  87. type: 'category',
  88. boundaryGap: false,
  89. data: xData,
  90. axisLabel: {
  91. interval:0,//横轴信息全部显示
  92. formatter: function (value, index) {
  93. if(index == 0){
  94. $("#startValue").text(value);
  95. return value.substr(5,2)+"月"+value.substr(8,2);
  96. }else{
  97. if(index == 7){
  98. $("#endValue").text(value);
  99. }
  100. return value.substr(8,2);
  101. }
  102. }
  103. }
  104. },
  105. yAxis: {
  106. type: 'value',
  107. axisPointer: {
  108. snap: true
  109. }
  110. },
  111. dataZoom: [{//给x轴设置滚动条
  112. show: false,
  113. start: dataZoom_end,
  114. end: 100,
  115. type: 'slider',
  116. zoomLock: true,
  117. },{ //下面这个属性是内容区域配置
  118. start: dataZoom_end,
  119. end: 100,
  120. type: 'inside',
  121. zoomLock: true,
  122. }],
  123. series: [{
  124. name: '运动步数',
  125. type: 'line',
  126. smooth: true,
  127. data: yData,
  128. lineStyle:{
  129. normal: {
  130. color: '#17b3ec'
  131. }
  132. },
  133. itemStyle:{
  134. normal: {
  135. color: '#17b3ec'
  136. }
  137. }
  138. },{
  139. name: '目标量',
  140. type: 'line',
  141. smooth: true,
  142. data: yData2,
  143. lineStyle:{
  144. normal: {
  145. color: '#D0DD44'
  146. }
  147. },
  148. itemStyle:{
  149. normal: {
  150. color: '#D0DD44'
  151. }
  152. }
  153. }]
  154. };
  155. lineCharts.setOption(options);
  156. }