BA_index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /**
  2. * 发送阿贾克斯请求 获取数据库信息,放到 arrX和 arrY中
  3. * @param {String} val 输入year 或者 score 即抓取年份还是值还是
  4. * @param {Array} arr 输入arrX 或者 arrY
  5. * @param {String} address 请求地址
  6. */
  7. function findData(val, arr, address) {
  8. $.ajax({
  9. type: "post",
  10. async: false,
  11. url: address,
  12. data: {},
  13. dataType: "json", //返回数据形式为json,这里是N个 {name:'xxx',num:x}
  14. success: function (result) {
  15. console.log('result', result);
  16. if (result) {
  17. for (var i = 0; i < result.length; i++) {
  18. // console.log('temp', result);
  19. arr.push(result[i][val]); //把每一项的名字或者值存起来
  20. }
  21. }
  22. },
  23. error: function (errorMsg) {
  24. alert("不好意思,大爷,图表请求数据失败啦!");
  25. myChart.hideLoading();
  26. }
  27. });
  28. }
  29. /**
  30. * 切换
  31. */
  32. switcher();
  33. function switcher() {
  34. //先阻止默认事件
  35. $('#banner a').click(function (e) {
  36. e.preventDefault();
  37. });
  38. //工具箱的切换
  39. //样式选项卡切换
  40. $('#banner li').on('click', function () {
  41. $(this).siblings('li').css({
  42. 'background-color': '',
  43. 'border-radius': '0px',
  44. 'box-shadow': '0 0 0 0',
  45. });
  46. $(this).siblings('li').children('a').css('color', 'white');
  47. $(this).css({
  48. 'background-color': '#6a19c1',
  49. 'border-radius': '7px',
  50. 'box-shadow': '0 0 10px 0 #6a19c1',
  51. });
  52. $(this).children('a').css('color', '#008c8c');
  53. });
  54. $('#banner li:eq(0)').on('click', function () {
  55. $('#pie').hide();
  56. $('#line').css('visibility', 'hidden');
  57. // $('#line div').remove();
  58. $('#bar').css('visibility', 'visible');
  59. barGraph();
  60. console.log('柱状图');
  61. //导航栏控制内容的切换
  62. $('.tools .pieList').hide();
  63. $('.tools .lineList').show();
  64. $('.tools .lineList').children('input[placeholder="请输入名字"]').val('詹皇');
  65. console.log('工具箱big');
  66. });
  67. $('#banner li:eq(1)').on('click', function () {
  68. $('#pie').hide();
  69. $('#line').css('visibility', 'visible');
  70. // $('#line div').remove();
  71. $('#bar').css('visibility', 'hidden');
  72. lineGraph();
  73. console.log('折线图');
  74. $('.tools .pieList').hide();
  75. $('.tools .lineList').show();
  76. $('.tools .lineList').children('input[placeholder="请输入名字"]').val('');
  77. console.log('工具箱big');
  78. });
  79. $('#banner li:eq(2)').on('click', function () {
  80. $('#pie').show();
  81. $('#line').css('visibility', 'hidden');
  82. // $('#line div').remove();
  83. $('#bar').css('visibility', 'hidden');
  84. // $('#bar div').remove();
  85. pieGraph();
  86. console.log('饼图');
  87. $('.tools .lineList').hide();
  88. $('.tools .pieList').show();
  89. $('.tools .lineList').children('input[placeholder="请输入名字"]').val('');
  90. console.log('工具箱mini');
  91. });
  92. }
  93. /**
  94. * 工具箱_控制(增删改)
  95. */
  96. controlGraph();
  97. function controlGraph() {
  98. //内容显示
  99. $(".tools").on('mouseover', function () {
  100. $(this).children().css({
  101. 'visibility': 'visible',
  102. });
  103. $(this).find('button').css({
  104. 'transition': '1s',
  105. })
  106. }).on('mouseleave', function () {
  107. $(this).children().css({
  108. 'visibility': 'hidden',
  109. });
  110. $(this).find('button').css({
  111. 'transition': '0s',
  112. });
  113. $(this).children('.iconfont').css('visibility', 'visible');
  114. });
  115. //添加
  116. $('.tools button:eq(0)').on('click', function () {
  117. var keyX = $(this).prev().prev().prev().val(), //抓取输入的名字
  118. keyY = $(this).prev().prev().val(), //抓取输入的年份
  119. keyZ = $(this).prev().val(); //抓取输入的得分
  120. console.log(keyX, keyY, keyZ);
  121. if (keyX != '') {
  122. if (keyY == '') { //如果没设置值
  123. keyY = 0;
  124. }
  125. $.ajax({
  126. type: 'post',
  127. url: 'Add',
  128. data: {
  129. "setName": keyX,
  130. "setYear": keyY,
  131. "setScore": keyZ,
  132. }
  133. })
  134. .done(function () {
  135. alert('添加成功');
  136. barGraph();
  137. })
  138. .fail(function () {
  139. alert('添加失败');
  140. });
  141. }
  142. var key = $('#bar').css('visibility');
  143. if (key == 'visible') { //如果目前看的是柱状图
  144. /* if (keyX != '詹皇' || keyX != '詹姆斯') {
  145. alert('提示一下:你目前看的是詹皇的数据,所以你刚刚输入的名字不能在图中显示');
  146. } */
  147. barGraph();
  148. } else {
  149. lineGraph();
  150. }
  151. console.log('添加成功');
  152. });
  153. //修改
  154. $('.tools button:eq(2)').on('click', function () {
  155. var keyX = $(this).prev().prev().prev().val(), //抓取输入的名字
  156. keyY = $(this).prev().prev().val(), //抓取输入的年份
  157. keyZ = $(this).prev().val(); //抓取输入的得分
  158. // console.log(name, value);
  159. $.ajax({
  160. type: 'post',
  161. url: 'changePerform',
  162. data: {
  163. "changeName": keyX,
  164. "changeYear": keyY,
  165. "changeScore": keyZ,
  166. }
  167. })
  168. .done(function () {
  169. alert('修改成功');
  170. barGraph();
  171. })
  172. .fail(function () {
  173. alert('修改失败');
  174. })
  175. var key = $('#bar').css('visibility');
  176. if (key == 'visible') {
  177. barGraph();
  178. } else {
  179. lineGraph();
  180. }
  181. console.log('修改成功');
  182. });
  183. //删除
  184. $('.tools button:eq(1)').on('click', function () {
  185. var name = $(this).prev().prev().val(),
  186. year = $(this).prev().val();
  187. // console.log(name);
  188. $.ajax({
  189. type: 'post',
  190. url: 'Delete',
  191. data: {
  192. delName: name,
  193. delYear: year,
  194. }
  195. })
  196. .done(function () {
  197. barGraph();
  198. alert('删除成功!');
  199. })
  200. .fail(function () {
  201. alert('删除失败');
  202. });
  203. var key = $('#bar').css('visibility');
  204. if (key == 'visible') {
  205. barGraph();
  206. } else {
  207. lineGraph();
  208. }
  209. console.log('删除成功');
  210. });
  211. //饼图的修改
  212. $('.tools .changePie').on('click', function () {
  213. var keyX = $(this).prev().prev().val(), //抓取输入的名字
  214. keyY = $(this).prev().val(); //抓取输入的值
  215. /* var name = $(this).prev().prev().val(),
  216. value = $(this).prev().val(); */
  217. // console.log(name, value);
  218. $.ajax({
  219. type: 'post',
  220. url: 'pieChange',
  221. data: {
  222. "changeName": keyX,
  223. "changeScore": keyY,
  224. }
  225. })
  226. .done(function () {
  227. alert('修改成功');
  228. barGraph();
  229. })
  230. .fail(function () {
  231. alert('修改失败');
  232. });
  233. pieGraph();
  234. console.log('修改成功!');
  235. })
  236. }
  237. /**
  238. * 柱状图
  239. */
  240. // barGraph();
  241. function barGraph() {
  242. var arrX = [], //用来保存键(名字)
  243. arrY = []; //用来保存值(数量)
  244. //获取数据库信息
  245. findData('year', arrX, "bar.do"); //获取名字
  246. findData('score', arrY, "bar.do"); //获取值
  247. //初始化
  248. var myChart = echarts.init(document.getElementById('bar'));
  249. var option = {
  250. color: ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', '#f15c80', '#e4d354', '#8085e8',
  251. '#8d4653', '#91e8e1'
  252. ],
  253. title: {
  254. text: '詹皇2016以来的场均得分',
  255. x: 'center'
  256. },
  257. tooltip: {},
  258. xAxis3D: {
  259. type: 'category',
  260. data: arrX,
  261. axisLine: {
  262. lineStyle: {
  263. color: 'purple',
  264. width: 2
  265. }
  266. },
  267. // xAxis.axisTick.interval:{},
  268. axisLabel: {
  269. interval: 0 //强制显示所有标签
  270. }
  271. },
  272. yAxis3D: {
  273. type: 'category',
  274. data: [''],
  275. axisLine: {
  276. lineStyle: {
  277. color: 'purple',
  278. width: 2
  279. }
  280. },
  281. },
  282. zAxis3D: {
  283. type: 'value',
  284. axisLine: {
  285. lineStyle: {
  286. color: 'purple',
  287. width: 2
  288. }
  289. },
  290. },
  291. grid3D: {
  292. boxWidth: 200,
  293. boxDepth: 30,
  294. axisPointer: {
  295. show: false
  296. },
  297. light: {
  298. main: {
  299. intensity: 1.2
  300. },
  301. ambient: {
  302. intensity: 0.3
  303. }
  304. },
  305. viewControl: {
  306. alpha: 10, //控制场景平移旋转
  307. beta: 20,
  308. minAlpha: 10,
  309. maxAlpha: 10,
  310. minBeta: 20,
  311. maxBeta: 20
  312. }
  313. },
  314. series: [{
  315. type: 'bar3D',
  316. name: '1',
  317. barSize: 10,
  318. data: (function () {
  319. var tempRecordY = []; //临时记录 arrY 中的每一项
  320. arrY.forEach(function (item, i, self) { //将arrY中每一项拿出来
  321. if (i % 2 == 0) {
  322. tempRecordY.push([i, 0, item]);
  323. }
  324. });
  325. return tempRecordY; //将他返回给data
  326. }()),
  327. stack: 'stack',
  328. shading: 'lambert',
  329. emphasis: {
  330. label: {
  331. show: true
  332. }
  333. }
  334. }, {
  335. type: 'bar3D',
  336. name: '2',
  337. barSize: 10,
  338. data: (function () {
  339. var tempRecordY = [];
  340. arrY.forEach(function (item, i, self) {
  341. if (i % 2 !== 0) {
  342. tempRecordY.push([i, 0, item]);
  343. }
  344. });
  345. return tempRecordY;
  346. }()),
  347. // stack: 'stack', 第二个不设置,不然会飞起来对不齐
  348. shading: 'lambert',
  349. emphasis: {
  350. label: {
  351. show: true
  352. }
  353. }
  354. }]
  355. };
  356. // 使用刚指定的配置项和数据显示图表。
  357. myChart.setOption(option);
  358. console.log(arrX);
  359. }
  360. /**
  361. * 饼图
  362. */
  363. // pieGraph();
  364. function pieGraph() {
  365. //根据json数据生成饼状图,并将饼状图显示到div中
  366. var arrX = [],
  367. arrY = [];
  368. findData('name', arrX, "pie.do");
  369. findData('score', arrY, "pie.do");
  370. // 转为 [{},{},{},{}] 格式
  371. var j = 0,
  372. lenY = arrY.length;
  373. var jsonPerform = [];
  374. for (var i = 0, lenX = arrX.length; i < lenX; i++) {
  375. for (; j < lenY;) {
  376. jsonPerform.push({
  377. 'name': arrX[i],
  378. 'value': arrY[j],
  379. });
  380. j++;
  381. break;
  382. }
  383. }
  384. // console.log('new',arrX,arrY);
  385. // console.log('newLast', jsonPerform);
  386. MakeChart(jsonPerform);
  387. function MakeChart(json) {
  388. chartData = eval(json);
  389. //饼状图
  390. chart = new AmCharts.AmPieChart();
  391. chart.dataProvider = chartData;
  392. //标题数据
  393. chart.titleField = "name";
  394. //值数据
  395. chart.valueField = "value";
  396. //边框线颜色
  397. chart.outlineColor = "#fff";
  398. //边框线的透明度
  399. chart.outlineAlpha = .8;
  400. //边框线的狂宽度
  401. chart.outlineThickness = 1;
  402. chart.depth3D = 20;
  403. chart.angle = 30;
  404. chart.write("pie");
  405. }
  406. }
  407. /**
  408. * 折线图
  409. */
  410. lineGraph();
  411. function lineGraph() {
  412. var arrX = [],
  413. arrY1 = [],
  414. arrY2 = [];
  415. //获取数据库信息
  416. findData('year', arrX, "line.do"); //获取年份
  417. findData('score', arrY1, "line.do"); //获取詹皇分数
  418. findData('score2', arrY2, "line2.do"); //获取戴维斯分数
  419. console.log('詹皇', arrY1);
  420. console.log('年份', arrX);
  421. console.log('戴维斯', arrY2);
  422. /**
  423. * 画双折线图
  424. * @param container 容器
  425. * @param titleName 标题
  426. * @param xData x轴数据
  427. * @param seriesNameOne 第一条折线图表名称
  428. * @param seriesDataOne 第一条折线图表数据
  429. * @param seriesNameTwo 第二条折线图表名称
  430. * @param seriesDataTwo 第二条折线图表数据
  431. */
  432. drawDoubleLine('doubleLine', '年份', arrX, '詹皇', arrY1, '戴维斯', arrY2);
  433. function drawDoubleLine(container, titleName, xData, seriesNameOne, seriesDataOne, seriesNameTwo, seriesDataTwo) {
  434. var doubleLine = echarts.init(document.getElementById('line'));
  435. doubleLineOption = {
  436. tooltip: {
  437. trigger: 'axis',
  438. //指示器
  439. axisPointer: {
  440. type: 'line',
  441. lineStyle: {
  442. color: '#7171C6'
  443. }
  444. }
  445. },
  446. //标题样式
  447. title: {
  448. text: titleName,
  449. textStyle: {
  450. color: 'white',
  451. },
  452. left: 'center'
  453. },
  454. //图形位置
  455. grid: {
  456. left: '4%',
  457. right: '6%',
  458. bottom: '4%',
  459. top: 50,
  460. containLabel: true
  461. },
  462. xAxis: [{
  463. type: 'category',
  464. //x轴坐标点开始与结束点位置都不在最边缘
  465. boundaryGap: true,
  466. axisLine: {
  467. show: true,
  468. //x轴线样式
  469. lineStyle: {
  470. color: '#17273B',
  471. width: 1,
  472. type: 'solid'
  473. }
  474. },
  475. //x轴字体设置
  476. axisLabel: {
  477. show: true,
  478. fontSize: 12,
  479. color: 'white'
  480. },
  481. data: xData
  482. }],
  483. yAxis: [{
  484. type: 'value',
  485. //y轴字体设置
  486. axisLabel: {
  487. show: true,
  488. color: 'white',
  489. fontSize: 12,
  490. formatter: function (value) {
  491. if (value >= 1000) {
  492. value = value / 1000 + 'k';
  493. }
  494. return value;
  495. }
  496. },
  497. //y轴线设置显示
  498. axisLine: {
  499. show: true
  500. },
  501. //与x轴平行的线样式
  502. splitLine: {
  503. show: true,
  504. lineStyle: {
  505. color: '#17273B',
  506. width: 1,
  507. type: 'solid',
  508. }
  509. }
  510. }],
  511. series: [{
  512. name: seriesNameOne,
  513. type: 'line',
  514. smooth: true,
  515. lineStyle: {
  516. color: {
  517. type: 'linear',
  518. x: 0,
  519. y: 0,
  520. x2: 0,
  521. y2: 1,
  522. colorStops: [{
  523. offset: 0,
  524. color: '#00F2B1' // 0% 处的颜色
  525. }, {
  526. offset: 1,
  527. color: '#00F2B1' // 100% 处的颜色
  528. }],
  529. globalCoord: false
  530. },
  531. width: 2,
  532. type: 'solid',
  533. },
  534. //折线连接点样式
  535. itemStyle: {
  536. color: '#00E5DE'
  537. },
  538. //折线堆积区域样式
  539. areaStyle: {
  540. color: '#004c5E'
  541. },
  542. data: seriesDataOne
  543. }, {
  544. name: seriesNameTwo,
  545. type: 'line',
  546. smooth: true,
  547. lineStyle: {
  548. color: {
  549. type: 'linear',
  550. x: 0,
  551. y: 0,
  552. x2: 0,
  553. y2: 1,
  554. colorStops: [{
  555. offset: 0,
  556. color: '#0AB2F9' // 0% 处的颜色
  557. }, {
  558. offset: 1,
  559. color: '#0AB2F9' // 100% 处的颜色
  560. }],
  561. globalCoord: false
  562. },
  563. width: 2,
  564. type: 'solid',
  565. },
  566. //折线连接点样式
  567. itemStyle: {
  568. color: '#00E5DE'
  569. },
  570. //折线堆积区域样式
  571. areaStyle: {
  572. color: '#004c5E'
  573. },
  574. data: seriesDataTwo
  575. }]
  576. };
  577. doubleLine.setOption(doubleLineOption);
  578. }
  579. }
  580. /**
  581. * 交互图
  582. */
  583. rect();
  584. function rect() {
  585. var arrX = [],
  586. arrY1 = [],
  587. arrY2 = [];
  588. //获取数据库信息
  589. findData('year', arrX, "line.do"); //获取年份
  590. findData('score', arrY1, "line.do"); //获取詹皇分数
  591. findData('score2', arrY2, "line2.do"); //获取戴维斯分数
  592. // 路径配置
  593. require.config({
  594. paths: {
  595. echarts: 'http://echarts.baidu.com/build/dist'
  596. }
  597. });
  598. // 使用
  599. require(['echarts', 'echarts/chart/bar', 'echarts/chart/line' // 使用柱状图就加载bar模块,按需加载
  600. ],
  601. drewEcharts
  602. );
  603. function drewEcharts(ec) {
  604. // 基于准备好的dom,初始化echarts图表
  605. var myChart = ec.init(document.getElementById('rect'));
  606. var option = {
  607. title: {
  608. text: '湖人队主力',
  609. // subtext: '纯属虚构'
  610. },
  611. tooltip: {
  612. trigger: 'axis'
  613. },
  614. legend: {
  615. data: ['詹皇', '戴维斯']
  616. },
  617. toolbox: {
  618. show: true,
  619. feature: {
  620. dataView: {
  621. show: true,
  622. readOnly: false
  623. },
  624. magicType: {
  625. show: true,
  626. type: ['line', 'bar']
  627. },
  628. restore: {
  629. show: true
  630. },
  631. saveAsImage: {
  632. show: true
  633. }
  634. }
  635. },
  636. calculable: true,
  637. xAxis: [{
  638. type: 'category',
  639. data: arrX,
  640. }],
  641. yAxis: [{
  642. type: 'value'
  643. }],
  644. series: [{
  645. "name": "詹皇",
  646. "type": "bar",
  647. "data": arrY1,
  648. markPoint: {
  649. data: [{
  650. type: 'max',
  651. name: '最大值'
  652. },
  653. {
  654. type: 'min',
  655. name: '最小值'
  656. }
  657. ]
  658. },
  659. markLine: {
  660. data: [{
  661. type: 'average',
  662. name: '平均值'
  663. }]
  664. }
  665. },
  666. {
  667. name: '戴维斯',
  668. type: 'bar',
  669. "data": arrY2,
  670. markPoint: {
  671. data: [{
  672. type: 'max',
  673. name: '最大值'
  674. },
  675. {
  676. type: 'min',
  677. name: '最小值'
  678. }
  679. ]
  680. },
  681. markLine: {
  682. data: [{
  683. type: 'average',
  684. name: '平均值'
  685. }]
  686. }
  687. }
  688. ]
  689. };
  690. // 为echarts对象加载数据
  691. myChart.setOption(option);
  692. }
  693. }
  694. /**
  695. * 浮现效果
  696. */
  697. document.addEventListener("DOMContentLoaded", function () {
  698. appear();
  699. })
  700. function appear() {
  701. //先把内容全部隐藏
  702. $('.info .James').children().hide();
  703. //鼠标移入头像
  704. $('header img').on('mouseover', function () {
  705. $('.info .James').animate({
  706. 'height': 200,
  707. }, function () {
  708. var height = $('.info .James').height();
  709. if (height == 200) {
  710. $('.info .James').children().show();
  711. }
  712. });
  713. });
  714. //鼠标移出头像
  715. $('header img').on('mouseleave', function () {
  716. $('.info .James').stop();
  717. $('.info .James').children().hide();
  718. $('.info .James').animate({
  719. 'height': '0',
  720. });
  721. });
  722. //鼠标移入more
  723. /* $('.more').children().hide();
  724. $('.more').find('.iconfont').show();
  725. $('.more').on('mouseover', function () {
  726. $('.more .more_list').animate({
  727. 'height': '250px',
  728. }, function () {
  729. $('.more').children().show();
  730. });
  731. });
  732. //鼠标移出more
  733. $('.more').on('mouseleave', function () {
  734. $(this).children().hide();
  735. $('.more .more_list').animate({
  736. 'height': '0',
  737. });
  738. $(this).find('.iconfont').show();
  739. }); */
  740. }
  741. /**数字数据 */
  742. numDigi();
  743. function numDigi() {
  744. var arrY1 = [], //记录詹皇的分
  745. arrY2 = []; //记录戴维斯的分
  746. //获取数据库信息
  747. findData('score', arrY1, "line.do"); //获取名字
  748. findData('score2', arrY2, "line2.do"); //获取名字
  749. console.log('分数k', arrY1);
  750. console.log('分数d', arrY2);
  751. /* for (var i = 0, len = arrY2.length; i < len; i++) {
  752. arrY2[i].toFixed(2);
  753. console.log('arrY2',arrY2)
  754. } */
  755. $('.digital tr:eq(1) td:eq(1)').text(arrY1[0]);
  756. $('.digital tr:eq(1) td:eq(2)').text(arrY2[0]);
  757. $('.digital tr:eq(2) td:eq(1)').text(arrY1[1]);
  758. $('.digital tr:eq(2) td:eq(2)').text(arrY2[1]);
  759. $('.digital tr:eq(3) td:eq(1)').text(arrY1[2]);
  760. $('.digital tr:eq(3) td:eq(2)').text(arrY2[2]);
  761. $('.digital tr:eq(4) td:eq(1)').text(arrY1[3]);
  762. $('.digital tr:eq(4) td:eq(2)').text(arrY2[3]);
  763. }