left1.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // 初始化echart实例对象
  2. var left1Chart = echarts.init(document.getElementById('left1'), 'dark');
  3. // 指定图表的配置项和数据
  4. // ----------左1的配置项-------------------
  5. var option = {
  6. title: {
  7. text: "全国累计趋势",
  8. textStyle: {
  9. color: 'white',
  10. },
  11. left: 'left',
  12. },
  13. tooltip: {
  14. trigger: 'axis',
  15. //指示器
  16. axisPointer: {
  17. type: 'line',
  18. lineStyle: {
  19. color: '#7171C6'
  20. }
  21. },
  22. },
  23. //图例
  24. legend: {
  25. data: ['累计确诊', "累计治愈", "累计死亡"],
  26. left: "right"
  27. },
  28. //图形位置
  29. grid: {
  30. left: '4%',
  31. right: '6%',
  32. bottom: '4%',
  33. top: 50,
  34. containLabel: true
  35. },
  36. xAxis: [{
  37. type: 'category',
  38. data: [] //['03.20', '03.21', '03.22']
  39. }],
  40. yAxis: [{
  41. type: 'value',
  42. //y轴字体设置
  43. axisLabel: {
  44. show: true,
  45. color: 'white',
  46. fontSize: 12,
  47. formatter: function(value) {
  48. if (value >= 1000) {
  49. value = value / 1000 + 'k';
  50. }
  51. return value;
  52. }
  53. },
  54. //y轴线设置显示
  55. axisLine: {
  56. show: true
  57. },
  58. //与x轴平行的线样式
  59. splitLine: {
  60. show: true,
  61. lineStyle: {
  62. color: '#17273B',
  63. width: 1,
  64. type: 'solid',
  65. }
  66. }
  67. }],
  68. series: [{
  69. name: "累计确诊",
  70. type: 'line',
  71. smooth: true,
  72. data: [] //[260, 406, 529]
  73. }, {
  74. name: "累计治愈",
  75. type: 'line',
  76. smooth: true,
  77. data: [] //[25, 25, 25]
  78. }, {
  79. name: "累计死亡",
  80. type: 'line',
  81. smooth: true,
  82. data: [] //[6, 9, 17]
  83. }]
  84. };
  85. var chinaDayList = data.chinaDayList
  86. // 遍历每一天的数据
  87. for (var day of chinaDayList) {
  88. // 将每天的累计确诊病例数添加到配置项的data中
  89. option.xAxis[0].data.push(day.date)
  90. option.series[0].data.push(day.confirm)
  91. option.series[1].data.push(day.heal)
  92. option.series[2].data.push(day.dead)
  93. }
  94. // 使用刚指定的配置项和数据显示图表。
  95. left1Chart.setOption(option);