echarts-block1.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. function loadBlock1() {
  2. const block1 = echarts.init(document.getElementById("block1"), "shine");
  3. const block1Opt = {
  4. tooltip: {
  5. trigger: "axis",
  6. formatter: function (params) {
  7. const param = params[0];
  8. const marker = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#e6b600;"></span>';
  9. return param.name + "<br />" +
  10. marker + "案件数量:" + param.value + " 件";
  11. }
  12. },
  13. grid: {
  14. top: '35%',
  15. left: '10%',
  16. containLabel: true,
  17. width: "80%",
  18. height: "60%"
  19. },
  20. xAxis: [{
  21. type: 'category',
  22. boundaryGap: false,
  23. axisLine: { //坐标轴轴线相关设置。数学上的x轴
  24. show: true,
  25. lineStyle: {
  26. color: '#233e64'
  27. },
  28. },
  29. axisLabel: { //坐标轴刻度标签的相关设置
  30. textStyle: {
  31. color: '#6a9cd5',
  32. margin: 15,
  33. },
  34. },
  35. axisTick: {
  36. show: false,
  37. }
  38. }],
  39. yAxis: [{
  40. type: 'value',
  41. splitNumber: 2,
  42. splitLine: {
  43. show: true,
  44. lineStyle: {
  45. color: '#233e64'
  46. }
  47. },
  48. axisLine: {
  49. show: false,
  50. },
  51. axisLabel: {
  52. margin: 5,
  53. textStyle: {
  54. color: '#6a9cd5',
  55. },
  56. },
  57. axisTick: {
  58. show: false,
  59. }
  60. }],
  61. series: [{
  62. name: '案件数量',
  63. type: 'line',
  64. smooth: true, //是否平滑曲线显示
  65. // symbol:'circle', // 默认是空心圆(中间是白色的),改成实心圆
  66. symbolSize: 0,
  67. lineStyle: {
  68. normal: {
  69. color: "#3deaff" // 线条颜色
  70. }
  71. },
  72. areaStyle: { //区域填充样式
  73. normal: {
  74. //线性渐变,前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’,则该四个值是绝对像素位置。
  75. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  76. offset: 0,
  77. color: 'rgba(61,234,255, 0.9)'
  78. },
  79. {
  80. offset: 1,
  81. color: 'rgba(61,234,255, 0)'
  82. }
  83. ], false),
  84. shadowColor: 'rgba(53,142,215, 0.9)', //阴影颜色
  85. shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
  86. }
  87. },
  88. }]
  89. };
  90. block1.setOption(block1Opt);
  91. $.ajax({
  92. url: ajaxBaseUrl + "data/case.json",
  93. dataType: "json"
  94. }).done(function () {
  95. $("#block1").addClass("chart-done");
  96. }).done(function (data) {
  97. const xData = [];
  98. const yData = [];
  99. for (let i in data) {
  100. xData.push(data[i].date);
  101. yData.push(data[i].total);
  102. }
  103. block1.setOption({
  104. xAxis: {
  105. data: xData
  106. },
  107. series: [{
  108. name: "案件数量",
  109. data: yData
  110. }]
  111. });
  112. }).fail(function (jqXHR) {
  113. console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
  114. });
  115. }