index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. // 柱状图1模块
  2. (function() {
  3. // 实例化对象
  4. var myChart = echarts.init(document.querySelector(".bar .chart"));
  5. // 指定配置和数据
  6. var option = {
  7. color: ["#2f89cf"],
  8. tooltip: {
  9. trigger: "axis",
  10. axisPointer: {
  11. // 坐标轴指示器,坐标轴触发有效
  12. type: "shadow" // 默认为直线,可选为:'line' | 'shadow'
  13. }
  14. },
  15. grid: {
  16. left: "0%",
  17. top: "10px",
  18. right: "0%",
  19. bottom: "4%",
  20. containLabel: true
  21. },
  22. xAxis: [
  23. {
  24. type: "category",
  25. data: [
  26. "旅游行业",
  27. "教育培训",
  28. "游戏行业",
  29. "医疗行业",
  30. "电商行业",
  31. "社交行业",
  32. "金融行业"
  33. ],
  34. axisTick: {
  35. alignWithLabel: true
  36. },
  37. axisLabel: {
  38. textStyle: {
  39. color: "rgba(255,255,255,.6)",
  40. fontSize: "12"
  41. }
  42. },
  43. axisLine: {
  44. show: false
  45. }
  46. }
  47. ],
  48. yAxis: [
  49. {
  50. type: "value",
  51. axisLabel: {
  52. textStyle: {
  53. color: "rgba(255,255,255,.6)",
  54. fontSize: "12"
  55. }
  56. },
  57. axisLine: {
  58. lineStyle: {
  59. color: "rgba(255,255,255,.1)"
  60. // width: 1,
  61. // type: "solid"
  62. }
  63. },
  64. splitLine: {
  65. lineStyle: {
  66. color: "rgba(255,255,255,.1)"
  67. }
  68. }
  69. }
  70. ],
  71. series: [
  72. {
  73. name: "直接访问",
  74. type: "bar",
  75. barWidth: "35%",
  76. data: [200, 300, 300, 900, 1500, 1200, 600],
  77. itemStyle: {
  78. barBorderRadius: 5
  79. }
  80. }
  81. ]
  82. };
  83. // 把配置给实例对象
  84. myChart.setOption(option);
  85. window.addEventListener("resize", function() {
  86. myChart.resize();
  87. });
  88. // 数据变化
  89. var dataAll = [
  90. { year: "2019", data: [200, 300, 300, 900, 1500, 1200, 600] },
  91. { year: "2020", data: [300, 400, 350, 800, 1800, 1400, 700] }
  92. ];
  93. $(".bar h2 ").on("click", "a", function() {
  94. option.series[0].data = dataAll[$(this).index()].data;
  95. myChart.setOption(option);
  96. });
  97. })();
  98. // 折线图定制
  99. (function() {
  100. // 基于准备好的dom,初始化echarts实例
  101. var myChart = echarts.init(document.querySelector(".line .chart"));
  102. // (1)准备数据
  103. var data = {
  104. year: [
  105. [24, 40, 101, 134, 90, 230, 210, 230, 120, 230, 210, 120],
  106. [40, 64, 191, 324, 290, 330, 310, 213, 180, 200, 180, 79]
  107. ]
  108. };
  109. // 2. 指定配置和数据
  110. var option = {
  111. color: ["#00f2f1", "#ed3f35"],
  112. tooltip: {
  113. // 通过坐标轴来触发
  114. trigger: "axis"
  115. },
  116. legend: {
  117. // 距离容器10%
  118. right: "10%",
  119. // 修饰图例文字的颜色
  120. textStyle: {
  121. color: "#4c9bfd"
  122. }
  123. // 如果series 里面设置了name,此时图例组件的data可以省略
  124. // data: ["邮件营销", "联盟广告"]
  125. },
  126. grid: {
  127. top: "20%",
  128. left: "3%",
  129. right: "4%",
  130. bottom: "3%",
  131. show: true,
  132. borderColor: "#012f4a",
  133. containLabel: true
  134. },
  135. xAxis: {
  136. type: "category",
  137. boundaryGap: false,
  138. data: [
  139. "1月",
  140. "2月",
  141. "3月",
  142. "4月",
  143. "5月",
  144. "6月",
  145. "7月",
  146. "8月",
  147. "9月",
  148. "10月",
  149. "11月",
  150. "12月"
  151. ],
  152. // 去除刻度
  153. axisTick: {
  154. show: false
  155. },
  156. // 修饰刻度标签的颜色
  157. axisLabel: {
  158. color: "rgba(255,255,255,.7)"
  159. },
  160. // 去除x坐标轴的颜色
  161. axisLine: {
  162. show: false
  163. }
  164. },
  165. yAxis: {
  166. type: "value",
  167. // 去除刻度
  168. axisTick: {
  169. show: false
  170. },
  171. // 修饰刻度标签的颜色
  172. axisLabel: {
  173. color: "rgba(255,255,255,.7)"
  174. },
  175. // 修改y轴分割线的颜色
  176. splitLine: {
  177. lineStyle: {
  178. color: "#012f4a"
  179. }
  180. }
  181. },
  182. series: [
  183. {
  184. name: "新增粉丝",
  185. type: "line",
  186. stack: "总量",
  187. // 是否让线条圆滑显示
  188. smooth: true,
  189. data: data.year[0]
  190. },
  191. {
  192. name: "新增游客",
  193. type: "line",
  194. stack: "总量",
  195. smooth: true,
  196. data: data.year[1]
  197. }
  198. ]
  199. };
  200. // 3. 把配置和数据给实例对象
  201. myChart.setOption(option);
  202. // 重新把配置好的新数据给实例对象
  203. myChart.setOption(option);
  204. window.addEventListener("resize", function() {
  205. myChart.resize();
  206. });
  207. })();
  208. // 饼形图定制
  209. // 折线图定制
  210. (function() {
  211. // 基于准备好的dom,初始化echarts实例
  212. var myChart = echarts.init(document.querySelector(".pie .chart"));
  213. option = {
  214. tooltip: {
  215. trigger: "item",
  216. formatter: "{a} <br/>{b}: {c} ({d}%)",
  217. position: function(p) {
  218. //其中p为当前鼠标的位置
  219. return [p[0] + 10, p[1] - 10];
  220. }
  221. },
  222. legend: {
  223. top: "90%",
  224. itemWidth: 10,
  225. itemHeight: 10,
  226. data: ["0岁以下", "20-29岁", "30-39岁", "40-49岁", "50岁以上"],
  227. textStyle: {
  228. color: "rgba(255,255,255,.5)",
  229. fontSize: "12"
  230. }
  231. },
  232. series: [
  233. {
  234. name: "年龄分布",
  235. type: "pie",
  236. center: ["50%", "42%"],
  237. radius: ["40%", "60%"],
  238. color: [
  239. "#065aab",
  240. "#066eab",
  241. "#0682ab",
  242. "#0696ab",
  243. "#06a0ab",
  244. "#06b4ab",
  245. "#06c8ab",
  246. "#06dcab",
  247. "#06f0ab"
  248. ],
  249. label: { show: false },
  250. labelLine: { show: false },
  251. data: [
  252. { value: 1, name: "0岁以下" },
  253. { value: 4, name: "20-29岁" },
  254. { value: 2, name: "30-39岁" },
  255. { value: 2, name: "40-49岁" },
  256. { value: 1, name: "50岁以上" }
  257. ]
  258. }
  259. ]
  260. };
  261. // 使用刚指定的配置项和数据显示图表。
  262. myChart.setOption(option);
  263. window.addEventListener("resize", function() {
  264. myChart.resize();
  265. });
  266. })();
  267. // 学习进度柱状图模块
  268. (function() {
  269. // 基于准备好的dom,初始化echarts实例
  270. var myChart = echarts.init(document.querySelector(".bar1 .chart"));
  271. var data = [70, 34, 60, 78, 69];
  272. var titlename = ["HTML5", "CSS3", "javascript", "VUE", "NODE"];
  273. var valdata = [702, 350, 610, 793, 664];
  274. var myColor = ["#1089E7", "#F57474", "#56D0E3", "#F8B448", "#8B78F6"];
  275. option = {
  276. //图标位置
  277. grid: {
  278. top: "10%",
  279. left: "22%",
  280. bottom: "10%"
  281. },
  282. xAxis: {
  283. show: false
  284. },
  285. yAxis: [
  286. {
  287. show: true,
  288. data: titlename,
  289. inverse: true,
  290. axisLine: {
  291. show: false
  292. },
  293. splitLine: {
  294. show: false
  295. },
  296. axisTick: {
  297. show: false
  298. },
  299. axisLabel: {
  300. color: "#fff",
  301. rich: {
  302. lg: {
  303. backgroundColor: "#339911",
  304. color: "#fff",
  305. borderRadius: 15,
  306. // padding: 5,
  307. align: "center",
  308. width: 15,
  309. height: 15
  310. }
  311. }
  312. }
  313. },
  314. {
  315. show: true,
  316. inverse: true,
  317. data: valdata,
  318. axisLabel: {
  319. textStyle: {
  320. fontSize: 12,
  321. color: "#fff"
  322. }
  323. }
  324. }
  325. ],
  326. series: [
  327. {
  328. name: "条",
  329. type: "bar",
  330. yAxisIndex: 0,
  331. data: data,
  332. barCategoryGap: 50,
  333. barWidth: 10,
  334. itemStyle: {
  335. normal: {
  336. barBorderRadius: 20,
  337. color: function(params) {
  338. var num = myColor.length;
  339. return myColor[params.dataIndex % num];
  340. }
  341. }
  342. },
  343. label: {
  344. normal: {
  345. show: true,
  346. position: "inside",
  347. formatter: "{c}%"
  348. }
  349. }
  350. },
  351. {
  352. name: "框",
  353. type: "bar",
  354. yAxisIndex: 1,
  355. barCategoryGap: 50,
  356. data: [100, 100, 100, 100, 100],
  357. barWidth: 15,
  358. itemStyle: {
  359. normal: {
  360. color: "none",
  361. borderColor: "#00c1de",
  362. borderWidth: 3,
  363. barBorderRadius: 15
  364. }
  365. }
  366. }
  367. ]
  368. };
  369. // 使用刚指定的配置项和数据显示图表。
  370. myChart.setOption(option);
  371. window.addEventListener("resize", function() {
  372. myChart.resize();
  373. });
  374. })();
  375. // 折线图 优秀作品
  376. (function() {
  377. // 基于准备好的dom,初始化echarts实例
  378. var myChart = echarts.init(document.querySelector(".line1 .chart"));
  379. option = {
  380. tooltip: {
  381. trigger: "axis",
  382. axisPointer: {
  383. lineStyle: {
  384. color: "#dddc6b"
  385. }
  386. }
  387. },
  388. legend: {
  389. top: "0%",
  390. textStyle: {
  391. color: "rgba(255,255,255,.5)",
  392. fontSize: "12"
  393. }
  394. },
  395. grid: {
  396. left: "10",
  397. top: "30",
  398. right: "10",
  399. bottom: "10",
  400. containLabel: true
  401. },
  402. xAxis: [
  403. {
  404. type: "category",
  405. boundaryGap: false,
  406. axisLabel: {
  407. textStyle: {
  408. color: "rgba(255,255,255,.6)",
  409. fontSize: 12
  410. }
  411. },
  412. axisLine: {
  413. lineStyle: {
  414. color: "rgba(255,255,255,.2)"
  415. }
  416. },
  417. data: [
  418. "01",
  419. "02",
  420. "03",
  421. "04",
  422. "05",
  423. "06",
  424. "07",
  425. "08",
  426. "09",
  427. "11",
  428. "12",
  429. "13",
  430. "14",
  431. "15",
  432. "16",
  433. "17",
  434. "18",
  435. "19",
  436. "20",
  437. "21",
  438. "22",
  439. "23",
  440. "24",
  441. "25",
  442. "26",
  443. "27",
  444. "28",
  445. "29",
  446. "30"
  447. ]
  448. },
  449. {
  450. axisPointer: { show: false },
  451. axisLine: { show: false },
  452. position: "bottom",
  453. offset: 20
  454. }
  455. ],
  456. yAxis: [
  457. {
  458. type: "value",
  459. axisTick: { show: false },
  460. axisLine: {
  461. lineStyle: {
  462. color: "rgba(255,255,255,.1)"
  463. }
  464. },
  465. axisLabel: {
  466. textStyle: {
  467. color: "rgba(255,255,255,.6)",
  468. fontSize: 12
  469. }
  470. },
  471. splitLine: {
  472. lineStyle: {
  473. color: "rgba(255,255,255,.1)"
  474. }
  475. }
  476. }
  477. ],
  478. series: [
  479. {
  480. name: "播放量",
  481. type: "line",
  482. smooth: true,
  483. symbol: "circle",
  484. symbolSize: 5,
  485. showSymbol: false,
  486. lineStyle: {
  487. normal: {
  488. color: "#0184d5",
  489. width: 2
  490. }
  491. },
  492. areaStyle: {
  493. normal: {
  494. color: new echarts.graphic.LinearGradient(
  495. 0,
  496. 0,
  497. 0,
  498. 1,
  499. [
  500. {
  501. offset: 0,
  502. color: "rgba(1, 132, 213, 0.4)"
  503. },
  504. {
  505. offset: 0.8,
  506. color: "rgba(1, 132, 213, 0.1)"
  507. }
  508. ],
  509. false
  510. ),
  511. shadowColor: "rgba(0, 0, 0, 0.1)"
  512. }
  513. },
  514. itemStyle: {
  515. normal: {
  516. color: "#0184d5",
  517. borderColor: "rgba(221, 220, 107, .1)",
  518. borderWidth: 12
  519. }
  520. },
  521. data: [
  522. 30,
  523. 40,
  524. 30,
  525. 40,
  526. 30,
  527. 40,
  528. 30,
  529. 60,
  530. 20,
  531. 40,
  532. 20,
  533. 40,
  534. 30,
  535. 40,
  536. 30,
  537. 40,
  538. 30,
  539. 40,
  540. 30,
  541. 60,
  542. 20,
  543. 40,
  544. 20,
  545. 40,
  546. 30,
  547. 60,
  548. 20,
  549. 40,
  550. 20,
  551. 40
  552. ]
  553. },
  554. {
  555. name: "转发量",
  556. type: "line",
  557. smooth: true,
  558. symbol: "circle",
  559. symbolSize: 5,
  560. showSymbol: false,
  561. lineStyle: {
  562. normal: {
  563. color: "#00d887",
  564. width: 2
  565. }
  566. },
  567. areaStyle: {
  568. normal: {
  569. color: new echarts.graphic.LinearGradient(
  570. 0,
  571. 0,
  572. 0,
  573. 1,
  574. [
  575. {
  576. offset: 0,
  577. color: "rgba(0, 216, 135, 0.4)"
  578. },
  579. {
  580. offset: 0.8,
  581. color: "rgba(0, 216, 135, 0.1)"
  582. }
  583. ],
  584. false
  585. ),
  586. shadowColor: "rgba(0, 0, 0, 0.1)"
  587. }
  588. },
  589. itemStyle: {
  590. normal: {
  591. color: "#00d887",
  592. borderColor: "rgba(221, 220, 107, .1)",
  593. borderWidth: 12
  594. }
  595. },
  596. data: [
  597. 50,
  598. 30,
  599. 50,
  600. 60,
  601. 10,
  602. 50,
  603. 30,
  604. 50,
  605. 60,
  606. 40,
  607. 60,
  608. 40,
  609. 80,
  610. 30,
  611. 50,
  612. 60,
  613. 10,
  614. 50,
  615. 30,
  616. 70,
  617. 20,
  618. 50,
  619. 10,
  620. 40,
  621. 50,
  622. 30,
  623. 70,
  624. 20,
  625. 50,
  626. 10,
  627. 40
  628. ]
  629. }
  630. ]
  631. };
  632. // 使用刚指定的配置项和数据显示图表。
  633. myChart.setOption(option);
  634. window.addEventListener("resize", function() {
  635. myChart.resize();
  636. });
  637. })();
  638. // 点位分布统计模块
  639. (function() {
  640. // 1. 实例化对象
  641. var myChart = echarts.init(document.querySelector(".pie1 .chart"));
  642. // 2. 指定配置项和数据
  643. var option = {
  644. legend: {
  645. top: "90%",
  646. itemWidth: 10,
  647. itemHeight: 10,
  648. textStyle: {
  649. color: "rgba(255,255,255,.5)",
  650. fontSize: "12"
  651. }
  652. },
  653. tooltip: {
  654. trigger: "item",
  655. formatter: "{a} <br/>{b} : {c} ({d}%)"
  656. },
  657. // 注意颜色写的位置
  658. color: [
  659. "#006cff",
  660. "#60cda0",
  661. "#ed8884",
  662. "#ff9f7f",
  663. "#0096ff",
  664. "#9fe6b8",
  665. "#32c5e9",
  666. "#1d9dff"
  667. ],
  668. series: [
  669. {
  670. name: "点位统计",
  671. type: "pie",
  672. // 如果radius是百分比则必须加引号
  673. radius: ["10%", "70%"],
  674. center: ["50%", "42%"],
  675. roseType: "radius",
  676. data: [
  677. { value: 20, name: "云南" },
  678. { value: 26, name: "北京" },
  679. { value: 24, name: "山东" },
  680. { value: 25, name: "河北" },
  681. { value: 20, name: "江苏" },
  682. { value: 25, name: "浙江" },
  683. { value: 30, name: "深圳" },
  684. { value: 42, name: "广东" }
  685. ],
  686. // 修饰饼形图文字相关的样式 label对象
  687. label: {
  688. fontSize: 10
  689. },
  690. // 修饰引导线样式
  691. labelLine: {
  692. // 连接到图形的线长度
  693. length: 10,
  694. // 连接到文字的线长度
  695. length2: 10
  696. }
  697. }
  698. ]
  699. };
  700. // 3. 配置项和数据给我们的实例化对象
  701. myChart.setOption(option);
  702. // 4. 当我们浏览器缩放的时候,图表也等比例缩放
  703. window.addEventListener("resize", function() {
  704. // 让我们的图表调用 resize这个方法
  705. myChart.resize();
  706. });
  707. })();