homepage3.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. function renderHomepage3Demo(echarts) {
  2. var mainColor = '#dd4541';
  3. var minValueSpan = 15;
  4. var dataZoomStartValue = 9;
  5. var dataZoomEndValue = 45;
  6. var backgroundColor = '#fff';
  7. var axisLabelColor = '#979797';
  8. var globalFontFamily = 'Arial';
  9. var pcGlobalFontSize = 12;
  10. var mobileGlobalFontSize = 12;
  11. var bgAreaColor = '#e4e4e4';
  12. var bgAreaColorTooltip = '#aaa';
  13. var categoryData = ['03/01','03/02','03/03','03/04','03/05','03/06','03/07','03/08','03/09','03/10','03/11','03/12','03/13','03/14','03/15','03/16','03/17','03/18','03/19','03/20','03/21','03/22','03/23','03/24','03/25','03/26','03/27','03/28','03/29','03/30','03/31','04/01','04/02','04/03','04/04','04/05','04/06','04/07','04/08','04/09','04/10','04/11','04/12','04/13','04/14','04/15','04/16','04/17','04/18','04/19','04/20','04/21','04/22','04/23','04/24','04/25','04/26','04/27','04/28','04/29','04/30','05/01','05/02','05/03','05/04','05/05','05/06','05/07','05/08','05/09','05/10','05/11','05/12','05/13','05/14','05/15']; // jshint ignore:line
  14. var series0Data = [23,32.65,61.06,47.84,54.2,65.96,41.47,48.16,27.59,65.96,52.24,37.22,44.73,53.22,60.08,68.24,58.29,74.78,62.2,71.67,66.78,71.18,46.47,56.39,34.02,47.41,47.11,25.67,28.94,34.73,40.29,46.86,52.96,64.82,51.63,72.33,61.39,66.94,60.57,51.27,47.18,56.49,50.12,52.57,42.45,47.18,34.45,38.69,25.63,35.1,31.51,40.82,30.69,34.45,41.31,46.69,48.82,41.31,52.24,55.51,47.51,32.65,37.71,26.78,16.65,21.06,17.31,26.61,32.98,45.06,41.63,53.39,63.67,58.94,43.92,50.29]; // jshint ignore:line
  15. var series1Data = [0.48,0.54,0.62,0.75,1.05,1.33,1.44,1.38,1.16,0.97,0.77,0.64,0.61,0.67,0.82,1.03,1.25,1.39,1.46,1.41,1.28,1.05,0.80,0.66,0.64,0.72,0.94,1.22,1.38,1.43,1.33,1.1,0.85,0.7,0.73,0.9,1.13,1.26,1.33,1.3,1.18,0.86,0.73,0.69,0.75,0.94,1.26,1.4,1.44,1.45,1.32,1.02,0.72,0.56,0.51,0.59,0.69,0.91,1.16,1.33,1.4,1.38,1.26,1.07,0.74,0.61,0.54,0.58,0.76,1.1,1.3,1.35,1.3,0.98,0.77,0.63]; // jshint ignore:line
  16. var series2Data = [1.63,1.61,1.58,1.54,1.5,1.47,1.47,1.5,1.57,1.67,1.74,1.83,1.91,1.96,1.98,1.94,1.84,1.68,1.55,1.43,1.32,1.27,1.26,1.31,1.46,1.59,1.67,1.68,1.62,1.56,1.52,1.52,1.64,1.89,2.2,2.39,2.47,2.46,2.37,2.24,2.06,1.92,1.87,1.86,1.92,2.06,2.18,2.24,2.22,2.09,1.93,1.82,1.78,1.79,1.81,1.85,1.94,2,2.01,1.96,1.9,1.76,1.65,1.56,1.49,1.45,1.44,1.46,1.54,1.59,1.57,1.54,1.54,1.62,1.74,1.85]; // jshint ignore:line
  17. var pcXAxisTextStyle = {
  18. fontSize: pcGlobalFontSize,
  19. fontFamily: globalFontFamily,
  20. color: axisLabelColor
  21. };
  22. var pcYAxisTextStyle = {
  23. fontSize: pcGlobalFontSize,
  24. fontFamily: globalFontFamily,
  25. color: axisLabelColor
  26. };
  27. var mobileXAxisTextStyle = {
  28. fontSize: mobileGlobalFontSize,
  29. fontFamily: globalFontFamily,
  30. color: axisLabelColor
  31. };
  32. var mobileYAxisTextStyle = {
  33. fontSize: mobileGlobalFontSize,
  34. fontFamily: globalFontFamily,
  35. color: axisLabelColor
  36. };
  37. var pcAxisPointerTextStyle = {
  38. color: '#333'
  39. };
  40. function getSeriesA() {
  41. return {
  42. type: 'bar',
  43. name: 'seriesA',
  44. id: 'gridScatter',
  45. showSymbol: false,
  46. symbolSize: 10,
  47. hoverAnimation: false,
  48. itemStyle: {
  49. normal: {
  50. color: mainColor,
  51. barBorderRadius: 8
  52. }
  53. },
  54. data: series0Data
  55. };
  56. }
  57. function getSeriesB() {
  58. return {
  59. type: 'line',
  60. name: 'seriesB',
  61. yAxisIndex: 1,
  62. xAxisIndex: 1,
  63. smooth: true,
  64. symbolSize: 10,
  65. showSymbol: false,
  66. hoverAnimation: false,
  67. areaStyle: {
  68. normal: {
  69. color: mainColor,
  70. opacity: 1,
  71. shadowOffsetX: 0,
  72. shadowOffsetY: 4,
  73. shadowBlur: 30,
  74. shadowColor: '#555'
  75. }
  76. },
  77. lineStyle: {
  78. normal: {
  79. width: 0
  80. }
  81. },
  82. data: series1Data,
  83. z: 10
  84. };
  85. }
  86. function getSeriesC() {
  87. return {
  88. type: 'line',
  89. name: 'seriesC',
  90. xAxisIndex: 1,
  91. yAxisIndex: 1,
  92. smooth: true,
  93. showSymbol: false,
  94. symbolSize: 0,
  95. hoverAnimation: false,
  96. areaStyle: {
  97. normal: {
  98. color: bgAreaColor,
  99. opacity: 1
  100. }
  101. },
  102. lineStyle: {
  103. normal: {
  104. width: 0
  105. }
  106. },
  107. data: series2Data,
  108. z: 9
  109. };
  110. }
  111. function getSeriesAxisPointer() {
  112. return {
  113. type: 'bar',
  114. xAxisIndex: 1,
  115. yAxisIndex: 1,
  116. barWidth: 1,
  117. animation: false,
  118. hoverAnimation: false,
  119. silent: true,
  120. itemStyle: {
  121. normal: {
  122. color: 'transparent'
  123. },
  124. emphasis: {
  125. color: '#fff'
  126. }
  127. },
  128. data: series1Data,
  129. z: 10
  130. };
  131. }
  132. function getXAxis(xAxis0, xAxis1) {
  133. return [
  134. echarts.util.merge({
  135. splitLine: {
  136. show: false
  137. },
  138. axisTick: {
  139. show: false
  140. },
  141. axisLine: {
  142. show: false,
  143. lineStyle: {
  144. color: '#ddd'
  145. }
  146. },
  147. axisLabel: {
  148. show: false
  149. },
  150. axisPointer: {
  151. type: 'shadow',
  152. label: {
  153. show: false
  154. },
  155. shadowStyle: {
  156. color: '#eee'
  157. // color: bgAreaColor
  158. // color: 'rgba(221,69,65,0.15)'
  159. },
  160. z: -100
  161. },
  162. data: categoryData
  163. }, xAxis0),
  164. echarts.util.merge({
  165. gridIndex: 1,
  166. splitLine: {
  167. show: false
  168. },
  169. axisTick: {
  170. show: false,
  171. lineStyle: {
  172. color: '#ddd'
  173. }
  174. },
  175. axisLine: {
  176. show: false,
  177. lineStyle: {
  178. color: '#ddd'
  179. }
  180. },
  181. axisLabel: {
  182. // textStyle: pcXAxisTextStyle
  183. },
  184. axisPointer: {
  185. type: 'none',
  186. label: {
  187. backgroundColor: bgAreaColor,
  188. textStyle: pcAxisPointerTextStyle
  189. }
  190. },
  191. data: categoryData
  192. }, xAxis1)
  193. ];
  194. }
  195. function getYAxis(yAxis0, yAxis1) {
  196. return [
  197. echarts.util.merge({
  198. min: 0,
  199. max: 80,
  200. nameTextStyle: {
  201. color: '#ccc',
  202. fontSize: 18
  203. },
  204. axisLine: {
  205. show: false
  206. },
  207. axisTick: {
  208. show: false
  209. },
  210. splitLine: {
  211. show: false
  212. },
  213. axisLabel: {
  214. },
  215. axisPointer: {
  216. label: {
  217. backgroundColor: bgAreaColor,
  218. textStyle: pcAxisPointerTextStyle
  219. }
  220. }
  221. }, yAxis0),
  222. echarts.util.merge({
  223. gridIndex: 1,
  224. minInterval: 1,
  225. nameTextStyle: {
  226. color: '#ccc',
  227. fontSize: 18
  228. },
  229. axisLine: {
  230. show: false
  231. },
  232. axisTick: {
  233. show: false
  234. },
  235. splitLine: {
  236. lineStyle: {
  237. color: bgAreaColor
  238. }
  239. },
  240. axisLabel: {
  241. formatter: '{value} m'
  242. },
  243. axisPointer: {
  244. label: {
  245. backgroundColor: bgAreaColor,
  246. textStyle: pcAxisPointerTextStyle
  247. }
  248. }
  249. }, yAxis1)
  250. ];
  251. }
  252. var option = {
  253. backgroundColor: backgroundColor,
  254. textStyle: {
  255. fontFamily: globalFontFamily,
  256. fontSize: pcGlobalFontSize
  257. },
  258. toolbox: {
  259. show: false
  260. },
  261. brush: {
  262. toolbox: ['lineX'],
  263. outOfBrush: {
  264. color: bgAreaColor
  265. },
  266. brushType: 'lineX',
  267. brushStyle: {
  268. borderWidth: 0,
  269. color: 'rgba(0,0,0,0)'
  270. },
  271. xAxisIndex: 0
  272. },
  273. tooltip: {
  274. trigger: 'axis',
  275. axisPointer: {
  276. type: 'cross'
  277. },
  278. padding: 5,
  279. backgroundColor: '#fff',
  280. borderWidth: 0,
  281. textStyle: {
  282. color: '#222'
  283. },
  284. extraCssText: 'z-index: 200;box-shadow: 0px 3px 15px rgba(0,0,0,0.3)',
  285. formatter: function (params) {
  286. var dataIndex = params[0].dataIndex;
  287. return echarts.util.map([
  288. ['seriesA', mainColor, series0Data],
  289. ['seriesB', mainColor, series1Data],
  290. ['seriesC', bgAreaColorTooltip, series2Data]
  291. ], function (def, idx) {
  292. return echarts.format.getTooltipMarker(def[1], !idx ? 'border-radius: 0;' : '')
  293. + '<span style="color:' + echarts.format.encodeHTML(def[1]) + '">'
  294. + def[0] + ': ' + def[2][dataIndex] + (idx ? ' m' : '')
  295. + '</span>';
  296. }).join('<br>');
  297. }
  298. },
  299. axisPointer: {
  300. link: [{xAxisIndex: 'all'}],
  301. label: {
  302. textStyle: {
  303. color: '#222'
  304. }
  305. },
  306. z: 500
  307. },
  308. xAxis: getXAxis({
  309. axisLabel: {
  310. textStyle: pcXAxisTextStyle
  311. }
  312. }, {
  313. axisLabel: {
  314. textStyle: pcXAxisTextStyle
  315. }
  316. }),
  317. yAxis: getYAxis({
  318. axisLabel: {
  319. textStyle: pcYAxisTextStyle
  320. }
  321. }, {
  322. axisLabel: {
  323. textStyle: pcYAxisTextStyle
  324. }
  325. }),
  326. grid: [{
  327. left: 50,
  328. right: 38,
  329. bottom: 228,
  330. height: 123
  331. }, {
  332. left: 50,
  333. right: 38,
  334. bottom: 84,
  335. height: 112
  336. }],
  337. dataZoom: [{
  338. startValue: dataZoomStartValue,
  339. endValue: dataZoomEndValue,
  340. left: 50,
  341. right: 38,
  342. bottom: 35,
  343. height: 4,
  344. showDataShadow: false,
  345. borderColor: 'transparent',
  346. backgroundColor: '#e2e2e2',
  347. // handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
  348. // handleIcon: 'M10.93,0.61c5.927,0,10.733,4.762,10.733,10.637S16.857,21.883,10.93,21.883 c-5.928,0-10.733-4.762-10.733-10.636S5.002,0.61,10.93,0.61z M15.646,10.247H6.215v2h9.431V10.247z', // jshint ignore:line
  349. handleIcon: 'image://data/handle.png', // jshint ignore:line
  350. handleSize: 20,
  351. handleStyle: {
  352. color: mainColor,
  353. shadowBlur: 6,
  354. shadowOffsetX: 1,
  355. shadowOffsetY: 2,
  356. shadowColor: '#aaa'
  357. },
  358. fillerColor: mainColor,
  359. labelFormatter: '',
  360. // borderColor: 'rgba(0,0,0,0.2)',
  361. xAxisIndex: [0, 1],
  362. minValueSpan: minValueSpan
  363. }, {
  364. startValue: dataZoomStartValue,
  365. endValue: dataZoomEndValue,
  366. type: 'inside',
  367. xAxisIndex: [0, 1],
  368. minValueSpan: minValueSpan
  369. }],
  370. series: [
  371. getSeriesA(),
  372. getSeriesB(),
  373. getSeriesC(),
  374. getSeriesAxisPointer()
  375. ]
  376. };
  377. var option2 = {
  378. backgroundColor: backgroundColor,
  379. textStyle: {
  380. fontFamily: globalFontFamily,
  381. fontSize: mobileGlobalFontSize
  382. },
  383. toolbox: {
  384. show: false
  385. },
  386. brush: {
  387. toolbox: ['lineX'],
  388. outOfBrush: {
  389. color: bgAreaColor
  390. },
  391. brushType: 'lineX',
  392. brushStyle: {
  393. borderWidth: 0,
  394. color: 'rgba(0,0,0,0)'
  395. },
  396. xAxisIndex: 0
  397. },
  398. tooltip: {
  399. show: true,
  400. triggerOn: 'none',
  401. alwaysShowContent: true,
  402. position: function (pos, params, dom, rect, size) {
  403. return {top: 10, left: 'center'};
  404. },
  405. backgroundColor: 'transparent',
  406. transitionDuration: 0,
  407. formatter: function (params) {
  408. var dataIndex = params[0].dataIndex;
  409. return echarts.util.map([
  410. ['seriesA', mainColor, series0Data],
  411. ['seriesB', mainColor, series1Data],
  412. ['seriesC', bgAreaColorTooltip, series2Data]
  413. ], function (def, idx) {
  414. return echarts.format.getTooltipMarker(def[1], !idx ? 'border-radius: 0;' : '')
  415. + '<span style="display:inline-block;width: 100px;color:' + echarts.format.encodeHTML(def[1]) + '">'
  416. + def[0] + ': ' + def[2][dataIndex] + (idx ? ' m' : '')
  417. + '</span>';
  418. }).join('&nbsp;&nbsp;&nbsp;');
  419. }
  420. },
  421. axisPointer: {
  422. triggerOn: 'none',
  423. link: [{xAxisIndex: 'all'}],
  424. label: {
  425. textStyle: {
  426. color: '#222'
  427. }
  428. },
  429. z: 500
  430. },
  431. xAxis: getXAxis({
  432. axisLabel: {
  433. textStyle: mobileXAxisTextStyle
  434. },
  435. axisPointer: {
  436. show: true
  437. }
  438. }, {
  439. axisLabel: {
  440. textStyle: mobileXAxisTextStyle
  441. },
  442. axisPointer: {
  443. value: '04/12',
  444. handle: {
  445. show: true,
  446. icon: 'image://./data/handle2.png',
  447. size: [36, 40],
  448. color: mainColor,
  449. shadowBlur: 12,
  450. shadowOffsetX: 2,
  451. shadowOffsetY: 4,
  452. shadowColor: '#aaa'
  453. }
  454. }
  455. }),
  456. yAxis: getYAxis({
  457. axisLabel: {
  458. textStyle: mobileYAxisTextStyle
  459. }
  460. }, {
  461. axisLabel: {
  462. textStyle: mobileYAxisTextStyle
  463. }
  464. }),
  465. grid: [{
  466. top: 63,
  467. left: 36,
  468. right: 14,
  469. height: 212
  470. }, {
  471. top: 335,
  472. left: 36,
  473. right: 14,
  474. height: 230
  475. }],
  476. dataZoom: [{
  477. startValue: dataZoomStartValue,
  478. endValue: dataZoomEndValue,
  479. type: 'inside',
  480. xAxisIndex: [0, 1],
  481. minValueSpan: minValueSpan
  482. }],
  483. series: [
  484. getSeriesA(),
  485. getSeriesB(),
  486. getSeriesC(),
  487. getSeriesAxisPointer()
  488. ]
  489. };
  490. var myChart = echarts.init($('.ch-pc-chart')[0]);
  491. myChart.setOption(option);
  492. var myChart2 = echarts.init($('.ch-mobile-chart')[0]);
  493. myChart2.setOption(option2);
  494. bindAction(myChart, myChart2, 'a');
  495. bindAction(myChart2, myChart, 'b');
  496. myChart.dispatchAction({
  497. type: 'brush',
  498. areas: [
  499. {
  500. xAxisIndex: 0,
  501. brushType: 'lineX',
  502. coordRange: [17, 27]
  503. }
  504. ]
  505. });
  506. function bindAction(fromChart, toChart, flag) {
  507. fromChart.on('updateAxisPointer', function (params) {
  508. toChart.dispatchAction(
  509. toChart.makeActionFromEvent(params),
  510. true
  511. );
  512. });
  513. fromChart.on('dataZoom', function (params) {
  514. var payload = params.batch ? params.batch[0] : params;
  515. toChart.dispatchAction({
  516. type: 'dataZoom',
  517. dataZoomIndex: 0,
  518. start: payload.start,
  519. end: payload.end
  520. }, true);
  521. });
  522. fromChart.on('brush', function (params) {
  523. params.areas[0] && toChart.dispatchAction({
  524. type: 'brush',
  525. areas: [
  526. {
  527. xAxisIndex: 0,
  528. brushType: 'lineX',
  529. coordRange: params.areas[0].coordRange
  530. }
  531. ]
  532. }, true);
  533. });
  534. }
  535. }