BaseScatter.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div id="myScatter"></div>
  3. </template>
  4. <script>
  5. import scatterList from '@/static/scatter.json'
  6. export default {
  7. name: "hello",
  8. data() {
  9. return {
  10. originArr:[],
  11. dataArr:[]
  12. };
  13. },
  14. created() {
  15. this.originArr = scatterList;
  16. this.originArr.forEach(item => {
  17. let arr = [];
  18. arr.push(item.x);
  19. arr.push(item.y);
  20. arr.push(item.name);
  21. this.dataArr.push(arr);
  22. })
  23. //let list = scatterList.sort(function (a, b) { return Number(b.score) - Number(a.score) });
  24. scatterList.forEach((item,index) => {
  25. //item.rank = list.indexOf(item) + 1;
  26. //item.areaName = this.areaName(item.x, item.y);
  27. })
  28. //console.log(JSON.stringify(scatterList));
  29. },
  30. mounted() {
  31. this.drawLine();
  32. },
  33. methods: {
  34. randomNum(minNum,maxNum){
  35. switch(arguments.length){
  36. case 1:
  37. return parseInt(Math.random()*minNum+1,10);
  38. break;
  39. case 2:
  40. return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
  41. break;
  42. default:
  43. return 0;
  44. break;
  45. }
  46. },
  47. areaName(x, y) {
  48. if (x <= 0.5 && y <= 50) {
  49. return 'C';
  50. } else if (x <= 1 && x > 0.5 && y <= 50) {
  51. return 'C-'
  52. } else if (x <= 0.5 && y > 50 && y <= 75) {
  53. return 'B'
  54. } else if (x <= 1 && x > 0.5 && y > 50 && y <= 75) {
  55. return 'B-'
  56. } else if (x <= 0.5 && y > 75 && y <= 100) {
  57. return 'A'
  58. } else if(x <= 1 && x > 0.5 && y > 75 && y <= 100){
  59. return 'A-'
  60. }
  61. },
  62. random() {
  63. var r = Math.floor(Math.random() * 100 );
  64. return r;
  65. },
  66. randomDataArray() {
  67. var d = [];
  68. var len = 60;
  69. while (len--) {
  70. d.push([Number((Math.random() * 0.99).toFixed(3)), this.random(), "张三"]);
  71. }
  72. console.log(d);
  73. return d;
  74. },
  75. drawLine() {
  76. // 基于准备好的dom,初始化echarts实例
  77. let myScatter = this.$echarts.init(document.getElementById("myScatter"),'chalk');
  78. // 指定图表的配置项和数据
  79. var option = {
  80. tooltip: {
  81. trigger: "item",
  82. showDelay: 0,
  83. axisPointer: {
  84. show: true,
  85. lineStyle: {
  86. type: "dashed",
  87. width: 1
  88. }
  89. },
  90. textStyle: {
  91. height:'160px'
  92. },
  93. formatter: function (params) {
  94. const item = params;
  95. return `信息<br/>
  96. 姓名:${item.data[2]}
  97. <br/>通过率:${item.data[1]}%
  98. <br/>稳定度:${item.data[0]}
  99. `;
  100. }
  101. },
  102. legend: {
  103. data: ["学生"]
  104. },
  105. toolbox: {
  106. show: true,
  107. right:'70px',
  108. feature: {
  109. mark: { show: true },
  110. dataZoom: { show: true },
  111. restore: { show: true },
  112. saveAsImage: { show: true }
  113. }
  114. },
  115. //grid: {
  116. // show: true,
  117. // backgroundColor:"rgba(90,90,90,.2)"
  118. //},
  119. xAxis: [
  120. {
  121. type: "value",
  122. splitNumber: 2,
  123. name: "稳定度",
  124. nameTextStyle: {
  125. color:"#e4eadb"
  126. },
  127. scale: true,
  128. //max: 1,
  129. //min:0,
  130. splitLine:{
  131. show: true,
  132. lineStyle: {
  133. color:'#595959'
  134. }
  135.    }
  136. }
  137. ],
  138. yAxis: [
  139. {
  140. type: "value",
  141. name: "通过率",
  142. nameTextStyle: {
  143. color:"#e4eadb"
  144. },
  145. max: 100,
  146. min: 0,
  147. splitLine:{
  148. show: false,
  149. lineStyle: {
  150. color:'#595959'
  151. }
  152. },
  153. interval:25,
  154. axisLabel: {
  155. show: true,
  156. formatter: function (value) {
  157. let val = [];
  158. if (value != 25) {
  159. val.push(value + '%')
  160. }
  161. return val;
  162. }
  163. },
  164. spiltArea: {
  165. show:true
  166. }
  167. }
  168. ],
  169. series: [
  170. {
  171. name: "学生",
  172. type: "scatter",
  173. data: this.dataArr,
  174. itemStyle: {
  175. color:"#79c8e8"
  176. },
  177. markLine: {
  178. silent: true,
  179. animation:false,
  180. data: [
  181. { yAxis: 75 }, { yAxis: 50 }, { yAxis: 100 }
  182. ],
  183. label: {
  184. color:"#e4eadb",
  185. formatter: '{c}%'
  186. },
  187. lineStyle: {
  188. color: "#595959",
  189. type:"solid"
  190. }
  191. },
  192. markArea: {
  193. silent:true,
  194. data: [
  195. [{
  196. xAxis: '0.5',
  197. yAxis: '100',
  198. itemStyle:{
  199. color:'rgba(90,90,90,.2)'
  200. },
  201. label: {
  202. show: true,
  203. position: ['90%', '10%'],
  204. color: '#66ff33',
  205. fontSize: 20,
  206. formatter: "A"
  207. }
  208. }, {
  209. xAxis: '0',
  210. yAxis: '75',
  211. itemStyle:{
  212. color:''
  213. }
  214. }],
  215. [{
  216. xAxis: '1',
  217. yAxis: '100',
  218. itemStyle:{
  219. color:'rgba(128,128,128,0)'
  220. },
  221. label: {
  222. show: true,
  223. position: ['5%', '10%'],
  224. color: '#66ff33',
  225. fontSize: 20,
  226. formatter: "A-"
  227. }
  228. }, {
  229. xAxis: '0.5',
  230. yAxis: '75',
  231. }],
  232. [{
  233. xAxis: '0.5',
  234. yAxis: '75',
  235. itemStyle:{
  236. color:'rgba(128,128,128,0)'
  237. },
  238. label: {
  239. show: true,
  240. position: ['90%', '10%'],
  241. color: '#66ff33',
  242. fontSize: 20,
  243. formatter: "B"
  244. }
  245. }, {
  246. xAxis: '0',
  247. yAxis: '50',
  248. }],
  249. [{
  250. xAxis: '1',
  251. yAxis: '75',
  252. itemStyle:{
  253. color:'rgba(90,90,90,.2)'
  254. },
  255. label: {
  256. show: true,
  257. position: ['5%', '10%'],
  258. color: '#66ff33',
  259. fontSize: 20,
  260. formatter: "B-"
  261. }
  262. }, {
  263. xAxis: '0.5',
  264. yAxis: '50',
  265. }],
  266. [{
  267. xAxis: '0.5',
  268. yAxis: '50',
  269. itemStyle:{
  270. color:'rgba(90,90,90,.2)'
  271. },
  272. label: {
  273. show: true,
  274. position: ['90%', '10%'],
  275. color: '#66ff33',
  276. fontSize: 20,
  277. formatter: "C"
  278. }
  279. }, {
  280. xAxis: '0',
  281. yAxis: '0',
  282. }],
  283. [{
  284. xAxis: '1',
  285. yAxis: '50',
  286. itemStyle:{
  287. color:'rgba(128,128,128,0)'
  288. },
  289. label: {
  290. show: true,
  291. position: ['5%', '10%'],
  292. color: '#66ff33',
  293. fontSize: 20,
  294. formatter: "C-"
  295. }
  296. }, {
  297. xAxis: '0.5',
  298. yAxis: '0',
  299. }]
  300. ],
  301. }
  302. }
  303. ]
  304. };
  305. // 绘制图表
  306. myScatter.setOption(option);
  307. window.addEventListener("resize", function () {
  308. myScatter.resize();
  309. });
  310. let that = this;
  311. myScatter.on('click', function (item) {
  312. that.$emit('handleItemClick', item);
  313. })
  314. }
  315. }
  316. };
  317. </script>
  318. <!-- Add "scoped" attribute to limit CSS to this component only -->
  319. <style scoped>
  320. #myScatter {
  321. width: 100%;
  322. height: 500px;
  323. margin: 0 auto;
  324. display: block;
  325. }
  326. </style>