sports.js 4.3 KB

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