説明なし

trafficData.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. getworkOrder()
  2. var telCountData
  3. $('.btn_time').click(function(e) {
  4. if(e.target.tagName == 'SPAN') {
  5. if($(e.target).attr('data-state') == '1') {
  6. $(".hwsjtj").hide()
  7. $('.daySeat').css('display', 'none')
  8. $('.timeTraffic').css('display', 'inline-block')
  9. $('#traffic').css('display', 'none')
  10. $('#timeTraffic').css('display', 'block')
  11. $(this).siblings(".act").children("label").attr("indexTitle", "日话务数据统计1")
  12. $('.call_situation h2').text('话务数据统计')
  13. getworkOrder()
  14. trafficState = 0
  15. }
  16. }
  17. e.stopPropagation();
  18. })
  19. function getworkOrder() {
  20. let workOrderData = [];
  21. let workOrderName = []
  22. new doAjax({
  23. url: huayi.config.callcenter_url + "/InfoNew/GetTelCountByNow",
  24. data: {
  25. timetype: telCountByNowType
  26. },
  27. callBack: function(res) {
  28. var data = res.data.hw[0]
  29. telCountData = data
  30. trafficDataChart(data)
  31. }
  32. });
  33. }
  34. function getLabelOption(positionObj, numberType) {
  35. var labelOption = {
  36. show: true,
  37. rotate: 0,
  38. align: 'left',
  39. color: '#fff',
  40. verticalAlign: 'middle',
  41. position: positionObj,
  42. formatter: function(params) {
  43. if(params.value > 0) {
  44. dataValue = params.seriesName + ': ' + params.value
  45. if(params.seriesName === "回拨") {
  46. dataValue = dataValue + '(' + telCountData.hbbili + '%)'
  47. } else if(params.seriesName === "自助") {
  48. dataValue = dataValue + '(' + telCountData.zzbili + '%)'
  49. } else if(params.seriesName === "人工") {
  50. dataValue = dataValue + '(' + telCountData.jtbili + '%)'
  51. }
  52. return dataValue;
  53. } else {
  54. return ' ';
  55. }
  56. },
  57. fontSize: 12,
  58. };
  59. return labelOption
  60. }
  61. function trafficDataChart(getdata) {
  62. getOption(getdata)
  63. }
  64. function getOption(getdata) {
  65. let canvas = document.querySelector('#timeTrafficLeft')
  66. canvas.width= 500
  67. canvas.height= 500
  68. let ctx = canvas.getContext('2d')
  69. // 绘制 x 轴,y 轴
  70. ctx.beginPath()
  71. // 线条开始坐标
  72. ctx.moveTo(50,100)
  73. // 线条结束坐标
  74. ctx.lineTo(50,450)
  75. ctx.lineTo(450,450)
  76. ctx.stroke()
  77. // 绘制数字 x,y
  78. let context = canvas.getContext('2d')
  79. // context.beginPath()
  80. context.font= "15px arial"
  81. context.fillText("y",40,85)
  82. context.fillText("x",455,460)
  83. // context.closePath()
  84. // 绘制 x ,y 轴箭头
  85. ctx.beginPath()
  86. ctx.moveTo(45,105)
  87. ctx.lineTo(50,100)
  88. ctx.lineTo(55,105)
  89. ctx.stroke()
  90. ctx.closePath()
  91. ctx.beginPath()
  92. ctx.moveTo(445,445)
  93. ctx.lineTo(450,450)
  94. ctx.lineTo(445,455)
  95. ctx.stroke()
  96. ctx.closePath()
  97. let colorArr = []
  98. for (let i = 0; i < 8; i++) {
  99. // 使用随机数生成每条柱子的颜色,使用16进制格式
  100. let color = '#'+parseInt(Math.random()*0xffffff).toString(16)
  101. colorArr.push(color)
  102. }
  103. // console.log(colorArr);
  104. // 绘制x轴坐标,在对应坐标位置绘制对应的矩形
  105. for(let i = 0; i < 8; i++) {
  106. let xStart = 80 + i * 50
  107. ctx.beginPath()
  108. ctx.moveTo(xStart,450)
  109. ctx.lineTo(xStart,460)
  110. ctx.stroke()
  111. ctx.closePath()
  112. ctx.beginPath()
  113. ctx.fillStyle = colorArr[i]
  114. let height = Math.random()*350
  115. ctx.fillRect(xStart-10,450-height,20,height)
  116. context.font = "20px Arial"
  117. context.textAlign = "center"
  118. context.fillStyle = 'white'
  119. context.fillText((xStart-80)/50,xStart,475)
  120. ctx.closePath()
  121. }
  122. // 绘制y轴坐标和坐标值
  123. for(let i = 430; i > 100; i-=50) {
  124. ctx.beginPath()
  125. ctx.moveTo(45,i)
  126. ctx.lineTo(50,i)
  127. ctx.stroke()
  128. context.font = "20px Arial"
  129. // 字体的水平对齐设置
  130. context.textAlign = "right"
  131. context.fillStyle = 'white'
  132. context.fillText(Math.abs(i-430),40,i)
  133. ctx.closePath()
  134. }
  135. for (let i = 0; i < 8; i++) {
  136. let x = 100 + i * 40
  137. let y = 30
  138. ctx.fillStyle = colorArr[i]
  139. ctx.fillRect(x,y,25,20)
  140. }
  141. }