visualMap-opacity.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <link rel="stylesheet" href="reset.css">
  7. <script src="lib/jquery.min.js"></script>
  8. </head>
  9. <body>
  10. <style>
  11. .main {
  12. height: 400px;
  13. margin: 10px 0 80px 0;
  14. }
  15. .label {
  16. background: #ddd;
  17. line-height: 30px;
  18. font-weight: bold;
  19. text-align: center;
  20. }
  21. </style>
  22. <div class="label">Color Alpha in scatter (using outOfRange as 'selected')</div>
  23. <div class="main" id="main1"></div>
  24. <div class="label">Opacity in bar (label color specified)</div>
  25. <div class="main" id="main2"></div>
  26. <div class="label">Opacity in scatter (label color specified)</div>
  27. <div class="main" id="main3"></div>
  28. <div class="label">Opacity in graph (label color specified)</div>
  29. <div class="main" id="main4"></div>
  30. <div class="label">Opacity in heatmap (inactive color default using opacity)</div>
  31. <div class="main" id="main5"></div>
  32. <div class="label">Opacity in pie (label color and label line color specified)</div>
  33. <div class="main" id="main6"></div>
  34. <!-- ALPHA SCATTER -->
  35. <script type="text/javascript">
  36. require([
  37. 'echarts',
  38. 'echarts/chart/scatter',
  39. 'echarts/component/legend',
  40. 'echarts/component/grid',
  41. 'echarts/component/visualMapPiecewise'
  42. ], function (echarts) {
  43. var main = document.getElementById('main1');
  44. if (!main) {
  45. return;
  46. }
  47. var chart = echarts.init(main);
  48. var data1 = [];
  49. var data2 = [];
  50. var data3 = [];
  51. var symbolCount = 6;
  52. for (var i = 0; i < 100; i++) {
  53. data1.push([
  54. Math.random() * 5,
  55. Math.random() * 4,
  56. Math.random() * 20,
  57. Math.round(Math.random() * (symbolCount - 1))
  58. ]);
  59. data2.push([
  60. Math.random() * 10,
  61. Math.random() * 5,
  62. Math.random() * 20,
  63. Math.round(Math.random() * (symbolCount - 1))
  64. ]);
  65. data3.push([
  66. Math.random() * 15,
  67. Math.random() * 10,
  68. Math.random() * 20,
  69. Math.round(Math.random() * (symbolCount - 1))
  70. ]);
  71. }
  72. chart.on('click', function (params) {
  73. console.log(params);
  74. });
  75. chart.setOption({
  76. color: ['#bcd3bb', '#928ea8', '#edc1a5'],
  77. legend: {
  78. data: ['scatter', 'scatter2', 'scatter3']
  79. },
  80. grid: {
  81. top: 50,
  82. bottom: 30
  83. },
  84. xAxis: {
  85. type: 'value',
  86. splitLine: {
  87. show: false
  88. }
  89. },
  90. yAxis: {
  91. type: 'value',
  92. splitLine: {
  93. show: false
  94. }
  95. },
  96. visualMap: [
  97. {
  98. type: 'piecewise',
  99. splitNumber: 6,
  100. left: 'right',
  101. bottom: 30,
  102. // selectedMode: 'single',
  103. selectedMode: 'multiple',
  104. selected: {
  105. 0: false, 1: false, 2: false, 3: false, 4: false, 5: false
  106. },
  107. dimension: 'z',
  108. min: 0,
  109. max: 24,
  110. precision: 0,
  111. inRange: { // visual for short cut
  112. color: ['rgb(20,1,0)'],
  113. symbolSize: [40, 5]
  114. },
  115. outOfRange: {
  116. colorAlpha: [0.3, 1],
  117. symbolSize: [40, 5]
  118. }
  119. }
  120. ],
  121. series: [
  122. {
  123. name: 'scatter',
  124. type: 'scatter',
  125. itemStyle: {
  126. normal: {
  127. opacity: 0.8,
  128. shadowBlur: 10,
  129. shadowOffsetX: 0,
  130. shadowOffsetY: 0,
  131. shadowColor: 'rgba(0, 0, 0, 0.5)'
  132. }
  133. },
  134. data: data1
  135. },
  136. {
  137. name: 'scatter2',
  138. type: 'scatter',
  139. itemStyle: {
  140. normal: {
  141. opacity: 0.8,
  142. shadowBlur: 10,
  143. shadowOffsetX: 0,
  144. shadowOffsetY: 0,
  145. shadowColor: 'rgba(0, 0, 0, 0.5)'
  146. }
  147. },
  148. data: data2
  149. },
  150. {
  151. name: 'scatter3',
  152. type: 'scatter',
  153. itemStyle: {
  154. normal: {
  155. opacity: 0.8,
  156. shadowBlur: 10,
  157. shadowOffsetX: 0,
  158. shadowOffsetY: 0,
  159. shadowColor: 'rgba(0, 0, 0, 0.5)'
  160. }
  161. },
  162. data: data3
  163. }
  164. ]
  165. });
  166. window.addEventListener('resize', function () {
  167. chart.resize();
  168. });
  169. });
  170. </script>
  171. <!-- OPACITY BAR -->
  172. <script>
  173. require([
  174. 'echarts',
  175. 'echarts/chart/bar',
  176. 'echarts/chart/line',
  177. 'echarts/component/legend',
  178. 'echarts/component/grid',
  179. 'echarts/component/tooltip',
  180. 'echarts/component/toolbox',
  181. 'echarts/component/visualMap',
  182. 'zrender/vml/vml'
  183. ], function (echarts) {
  184. var main = document.getElementById('main2');
  185. if (!main) {
  186. return;
  187. }
  188. var chart = echarts.init(main);
  189. var xAxisData = [];
  190. var data1 = [];
  191. var data2 = [];
  192. var data3 = [];
  193. var data4 = [];
  194. var DATA_MAX = 5.5;
  195. for (var i = 0; i < 10; i++) {
  196. xAxisData.push('类目' + i);
  197. data1.push((Math.random() * DATA_MAX).toFixed(2));
  198. data2.push(-Math.random().toFixed(2));
  199. data3.push((Math.random() + 0.5).toFixed(2));
  200. data4.push((Math.random() + 0.3).toFixed(2));
  201. }
  202. var labelStyle = {
  203. normal: {
  204. show: true,
  205. position: 'outside',
  206. textStyle: {
  207. color: '#333'
  208. }
  209. }
  210. };
  211. var itemStyle = {
  212. normal: {
  213. },
  214. emphasis: {
  215. shadowBlur: 10,
  216. shadowOffsetX: 0,
  217. shadowOffsetY: 0,
  218. shadowColor: 'rgba(0,0,0,0.5)'
  219. }
  220. };
  221. chart.setOption({
  222. legend: {
  223. data: ['bar', 'bar2', 'bar3'],
  224. align: 'left'
  225. },
  226. toolbox: {
  227. // y: 'bottom',
  228. feature: {
  229. magicType: {
  230. type: ['line', 'bar', 'stack', 'tiled']
  231. },
  232. dataView: {}
  233. }
  234. },
  235. tooltip: {},
  236. xAxis: {
  237. data: xAxisData,
  238. axisLine: {
  239. onZero: true
  240. },
  241. splitLine: {
  242. show: false
  243. },
  244. splitArea: {
  245. show: false
  246. }
  247. },
  248. yAxis: {
  249. splitArea: {
  250. show: false
  251. },
  252. max: 6,
  253. min: -2
  254. },
  255. visualMap: [
  256. {
  257. type: 'continuous',
  258. right: 0,
  259. itemWidth: 15,
  260. bottom: 30,
  261. dimension: 1,
  262. calculable: true,
  263. min: -2,
  264. max: DATA_MAX,
  265. precision: 2,
  266. inRange: {
  267. opacity: [1, 1] // Using opacity when label color specified
  268. },
  269. controller: {
  270. inRange: {
  271. color: '#888'
  272. },
  273. outOfRange: {
  274. color: '#888'
  275. }
  276. },
  277. outOfRange: {
  278. opacity: [0.2, 0.2] // Using opacity when label color specified
  279. }
  280. }
  281. ],
  282. series: [
  283. {
  284. name: 'bar',
  285. type: 'bar',
  286. stack: 'one',
  287. itemStyle: itemStyle,
  288. label: labelStyle,
  289. data: data1
  290. },
  291. {
  292. name: 'bar2',
  293. type: 'bar',
  294. stack: 'one',
  295. itemStyle: itemStyle,
  296. label: labelStyle,
  297. data: data2
  298. },
  299. {
  300. name: 'bar3',
  301. type: 'bar',
  302. itemStyle: itemStyle,
  303. label: labelStyle,
  304. data: data3
  305. }
  306. ]
  307. });
  308. window.addEventListener('resize', function () {
  309. chart.resize();
  310. });
  311. });
  312. </script>
  313. <!-- OPACITY SCATTER -->
  314. <script type="text/javascript">
  315. require([
  316. 'echarts',
  317. 'echarts/chart/scatter',
  318. 'echarts/component/legend',
  319. 'echarts/component/grid',
  320. 'echarts/component/visualMapPiecewise'
  321. ], function (echarts) {
  322. var main = document.getElementById('main3');
  323. if (!main) {
  324. return;
  325. }
  326. var chart = echarts.init(main);
  327. var data1 = [];
  328. var symbolCount = 6;
  329. for (var i = 0; i < 100; i++) {
  330. data1.push([
  331. Math.random() * 5,
  332. Math.random() * 4,
  333. Math.random() * 20,
  334. Math.round(Math.random() * (symbolCount - 1))
  335. ]);
  336. }
  337. chart.setOption({
  338. legend: {
  339. data: ['scatter', 'scatter2', 'scatter3']
  340. },
  341. grid: {
  342. top: 50,
  343. bottom: 30
  344. },
  345. xAxis: {
  346. type: 'value',
  347. splitLine: {
  348. show: false
  349. }
  350. },
  351. yAxis: {
  352. type: 'value',
  353. splitLine: {
  354. show: false
  355. }
  356. },
  357. visualMap: [
  358. {
  359. type: 'piecewise',
  360. splitNumber: 6,
  361. left: 'right',
  362. bottom: 30,
  363. selectedMode: 'multiple',
  364. dimension: 'z',
  365. min: 0,
  366. max: 24,
  367. precision: 0,
  368. inRange: { // visual for short cut
  369. opacity: 1,
  370. symbolSize: [15, 50]
  371. },
  372. outOfRange: {
  373. opacity: 0.3,
  374. symbolSize: [15, 50]
  375. }
  376. }
  377. ],
  378. series: [
  379. {
  380. name: 'scatter',
  381. type: 'scatter',
  382. itemStyle: {
  383. normal: {
  384. opacity: 0.8,
  385. shadowBlur: 10,
  386. shadowOffsetX: 0,
  387. shadowOffsetY: 0,
  388. shadowColor: 'rgba(0, 0, 0, 0.5)'
  389. }
  390. },
  391. label: {
  392. normal: {
  393. show: true,
  394. position: 'inside',
  395. textStyle: {
  396. color: '#fff'
  397. }
  398. }
  399. },
  400. data: data1
  401. }
  402. ]
  403. });
  404. window.addEventListener('resize', function () {
  405. chart.resize();
  406. });
  407. });
  408. </script>
  409. <!-- OPACITY GRAPH -->
  410. <script>
  411. require([
  412. 'echarts',
  413. 'extension/dataTool/gexf',
  414. 'echarts/chart/graph',
  415. 'echarts/component/title',
  416. 'echarts/component/legend',
  417. 'echarts/component/geo',
  418. 'echarts/component/tooltip',
  419. 'echarts/component/visualMap',
  420. 'theme/vintage'
  421. ], function (echarts, gexf) {
  422. var main = document.getElementById('main4');
  423. if (!main) {
  424. return;
  425. }
  426. var chart = echarts.init(main);
  427. $.get('./data/les-miserables.gexf', function (xml) {
  428. var graph = gexf.parse(xml);
  429. var categories = [];
  430. for (var i = 0; i < 9; i++) {
  431. categories[i] = {
  432. name: '类目' + i
  433. };
  434. }
  435. graph.nodes.forEach(function (node) {
  436. delete node.itemStyle;
  437. node.value = node.symbolSize;
  438. node.label = {
  439. normal: {
  440. show: node.symbolSize > 30
  441. }
  442. };
  443. node.category = node.attributes['modularity_class'];
  444. });
  445. graph.links.forEach(function (link) {
  446. delete link.lineStyle;
  447. });
  448. var option = {
  449. tooltip: {},
  450. legend: [{
  451. // selectedMode: 'single',
  452. data: categories.map(function (a) {
  453. return a.name;
  454. })
  455. }],
  456. visualMap: {
  457. min: 0,
  458. max: 100,
  459. dimension: 0,
  460. calculable: true,
  461. inRange: {
  462. opacity: 1,
  463. symbolSize: [10, 100]
  464. },
  465. outOfRange: {
  466. opacity: 0.2,
  467. symbolSize: [10, 100]
  468. }
  469. },
  470. animationDurationUpdate: 1500,
  471. animationEasingUpdate: 'quinticInOut',
  472. series : [
  473. {
  474. name: 'Les Miserables',
  475. type: 'graph',
  476. layout: 'none',
  477. data: graph.nodes,
  478. links: graph.links,
  479. categories: categories,
  480. roam: true,
  481. label: {
  482. normal: {
  483. textStyle: {
  484. color: '#333'
  485. },
  486. position: 'right',
  487. formatter: '{b}'
  488. }
  489. },
  490. lineStyle: {
  491. normal: {
  492. curveness: 0.3
  493. }
  494. }
  495. }
  496. ]
  497. };
  498. chart.setOption(option);
  499. });
  500. });
  501. </script>
  502. <!-- OPACITY HEATMAP -->
  503. <script type="text/javascript">
  504. require([
  505. 'echarts',
  506. 'echarts/chart/heatmap',
  507. 'echarts/component/grid',
  508. 'echarts/component/tooltip',
  509. 'echarts/component/visualMapPiecewise'
  510. ], function (echarts) {
  511. var main = document.getElementById('main5');
  512. if (!main) {
  513. return;
  514. }
  515. var chart = echarts.init(main, null, {
  516. renderer: 'canvas'
  517. });
  518. var hours = ['12a', '1a', '2a', '3a', '4a', '5a', '6a',
  519. '7a', '8a', '9a','10a','11a',
  520. '12p', '1p', '2p', '3p', '4p', '5p',
  521. '6p', '7p', '8p', '9p', '10p', '11p'];
  522. var days = ['Saturday', 'Friday', 'Thursday',
  523. 'Wednesday', 'Tuesday', 'Monday', 'Sunday'];
  524. var data = [[0,0,5],[0,1,1],[0,2,0],[0,3,0],[0,4,0],[0,5,0],[0,6,0],[0,7,0],[0,8,0],[0,9,0],[0,10,0],[0,11,2],[0,12,4],[0,13,1],[0,14,1],[0,15,3],[0,16,4],[0,17,6],[0,18,4],[0,19,4],[0,20,3],[0,21,3],[0,22,2],[0,23,5],[1,0,7],[1,1,0],[1,2,0],[1,3,0],[1,4,0],[1,5,0],[1,6,0],[1,7,0],[1,8,0],[1,9,0],[1,10,5],[1,11,2],[1,12,2],[1,13,6],[1,14,9],[1,15,11],[1,16,6],[1,17,7],[1,18,8],[1,19,12],[1,20,5],[1,21,5],[1,22,7],[1,23,2],[2,0,1],[2,1,1],[2,2,0],[2,3,0],[2,4,0],[2,5,0],[2,6,0],[2,7,0],[2,8,0],[2,9,0],[2,10,3],[2,11,2],[2,12,1],[2,13,9],[2,14,8],[2,15,10],[2,16,6],[2,17,5],[2,18,5],[2,19,5],[2,20,7],[2,21,4],[2,22,2],[2,23,4],[3,0,7],[3,1,3],[3,2,0],[3,3,0],[3,4,0],[3,5,0],[3,6,0],[3,7,0],[3,8,1],[3,9,0],[3,10,5],[3,11,4],[3,12,7],[3,13,14],[3,14,13],[3,15,12],[3,16,9],[3,17,5],[3,18,5],[3,19,10],[3,20,6],[3,21,4],[3,22,4],[3,23,1],[4,0,1],[4,1,3],[4,2,0],[4,3,0],[4,4,0],[4,5,1],[4,6,0],[4,7,0],[4,8,0],[4,9,2],[4,10,4],[4,11,4],[4,12,2],[4,13,4],[4,14,4],[4,15,14],[4,16,12],[4,17,1],[4,18,8],[4,19,5],[4,20,3],[4,21,7],[4,22,3],[4,23,0],[5,0,2],[5,1,1],[5,2,0],[5,3,3],[5,4,0],[5,5,0],[5,6,0],[5,7,0],[5,8,2],[5,9,0],[5,10,4],[5,11,1],[5,12,5],[5,13,10],[5,14,5],[5,15,7],[5,16,11],[5,17,6],[5,18,0],[5,19,5],[5,20,3],[5,21,4],[5,22,2],[5,23,0],[6,0,1],[6,1,0],[6,2,0],[6,3,0],[6,4,0],[6,5,0],[6,6,0],[6,7,0],[6,8,0],[6,9,0],[6,10,1],[6,11,0],[6,12,2],[6,13,1],[6,14,3],[6,15,4],[6,16,0],[6,17,0],[6,18,0],[6,19,0],[6,20,1],[6,21,2],[6,22,2],[6,23,6]];
  525. data = data.map(function (item) {
  526. return [item[1], item[0], item[2] || '-'];
  527. });
  528. option = {
  529. backgroundColor: '#eee4ee',
  530. tooltip: {
  531. position: 'top'
  532. },
  533. animation: false,
  534. grid: {
  535. height: '50%',
  536. y: '10%'
  537. },
  538. xAxis: {
  539. type: 'category',
  540. data: hours
  541. },
  542. yAxis: {
  543. type: 'category',
  544. data: days
  545. },
  546. visualMap: {
  547. min: 1,
  548. max: 10,
  549. calculable: true,
  550. range: [3, 6],
  551. orient: 'horizontal',
  552. left: 'center',
  553. bottom: '15%'
  554. },
  555. series: [{
  556. name: 'Punch Card',
  557. type: 'heatmap',
  558. data: data,
  559. label: {
  560. normal: {
  561. show: true
  562. }
  563. },
  564. itemStyle: {
  565. emphasis: {
  566. shadowBlur: 10,
  567. shadowColor: 'rgba(0, 0, 0, 0.5)'
  568. }
  569. }
  570. }]
  571. };
  572. chart.setOption(option);
  573. });
  574. </script>
  575. <!-- OPACITY HEATMAP -->
  576. <script>
  577. require([
  578. 'echarts',
  579. 'echarts/chart/pie',
  580. 'echarts/component/legend',
  581. 'echarts/component/grid',
  582. 'echarts/component/tooltip'
  583. ], function (echarts) {
  584. var main = document.getElementById('main6');
  585. if (!main) {
  586. return;
  587. }
  588. var chart = echarts.init(main);
  589. chart.setOption({
  590. legend: {
  591. data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
  592. },
  593. tooltip: {},
  594. visualMap: {
  595. type: 'continuous',
  596. top: 'middle',
  597. min: 0,
  598. max: 700,
  599. dimension: 1,
  600. calculable: true,
  601. inRange: {
  602. color: ['yellow', 'green']
  603. }
  604. },
  605. series: [{
  606. name: 'pie',
  607. type: 'pie',
  608. selectedMode: 'single',
  609. selectedOffset: 30,
  610. clockwise: true,
  611. label: {
  612. normal: {
  613. textStyle: {
  614. color: '#333'
  615. }
  616. }
  617. },
  618. labelLine: {
  619. normal: {
  620. lineStyle: {
  621. color: '#333'
  622. }
  623. }
  624. },
  625. data:[
  626. {value: [335, 632], name:'直接访问'},
  627. {value: [310, 434], name:'邮件营销'},
  628. {value: [234, 233], name:'联盟广告'},
  629. {value: [135, 544], name:'视频广告'},
  630. {value: [1548, 381], name:'搜索引擎'}
  631. ]
  632. }]
  633. });
  634. });
  635. </script>
  636. </body>
  637. </html>