CRECharts.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. /**
  2. * 创建者:王成
  3. * 创建日期:2021年12月10日
  4. * 描述:自定义ECharts
  5. */
  6. /**
  7. * 构造函数
  8. * @param {JSON} options 选项
  9. */
  10. function CrCharts(options) {
  11. this._init(options);
  12. this.click = options.click;
  13. }
  14. /**
  15. * 原型设置 必须的
  16. * @param {JSON} options 选项
  17. */
  18. CrCharts.prototype.extend = function(options) {
  19. for (var key in options) {
  20. CrCharts.prototype[key] = options[key];
  21. }
  22. }
  23. /**
  24. * 内部函数集合
  25. */
  26. CrCharts.prototype.extend({
  27. /**
  28. * 初始化函数
  29. * @param {JSON} options 选项
  30. */
  31. _init: function(options) {
  32. if (options.domId == undefined) {
  33. console.error('未设置显示容器!')
  34. return;
  35. }
  36. var self = this;
  37. //局部变量
  38. this.selector = options.domId; //3D地图容器
  39. this.chart = echarts.init(document.getElementById(this.selector));
  40. /* 添加事件 */
  41. this.chart.on('click', function(params) {
  42. if (self.click != undefined) {
  43. self.click(params);
  44. }
  45. });
  46. this.splitLine = {
  47. show: true,
  48. lineStyle: {
  49. type: 'dashed',
  50. color: 'rgba(69,69,69,0.3)',
  51. }
  52. };
  53. this.xAxisLine = {
  54. show: true,
  55. lineStyle: {
  56. color: "rgba(69,69,69,1.0)"
  57. },
  58. };
  59. this.xAxisLabel = {
  60. color: "rgba(69,69,69,1.0)",
  61. fontSize: 12,
  62. fontFamily: 'TTTGB-Medium',
  63. interval: 0,
  64. };
  65. this.yAxisLine = {
  66. show: true,
  67. lineStyle: {
  68. color: "rgba(69,69,69,1.0)"
  69. },
  70. };
  71. this.yAxisLabel = {
  72. color: "rgba(69,69,69,1.0)",
  73. fontSize: 12,
  74. fontFamily: 'TTTGB-Medium',
  75. };
  76. },
  77. /**
  78. * 结合坐标Map和数值数组 构建创建地图点的数据数组
  79. * @param {Map} geoCoordMap 包含name字段
  80. * @param {JSON数组} data 内部的JSON包含{name: value:}
  81. */
  82. _convertData: function(geoCoordMap, data) {
  83. var res = [];
  84. for (var i = 0; i < data.length; i++) {
  85. var geoCoord = geoCoordMap[data[i].name];
  86. if (geoCoord) {
  87. res.push({
  88. name: data[i].name,
  89. value: geoCoord.concat(data[i].name).concat(data[i].value),
  90. });
  91. }
  92. }
  93. return res;
  94. },
  95. /**
  96. * 动态轨迹线数据转换
  97. * @param {JSON数组} data [{from:[] to:}]
  98. * @param {String} type 类型 undefined 代表创建动态路径 而其他则代表创建底线
  99. */
  100. _convertLines: function(data, fromMap, toMap, type) {
  101. var res = [];
  102. for (var i = 0; i < data.length; i++) {
  103. var dataLines = data[i];
  104. for (var idx = 0; idx < dataLines.from.length; idx++) {
  105. var coords = [];
  106. coords.push(fromMap[dataLines.from[idx]]);
  107. coords.push(toMap[dataLines.to]);
  108. if (type == undefined) {
  109. res.push({
  110. coords: coords,
  111. })
  112. } else {
  113. res.push({
  114. coords: coords,
  115. lineStyle: {
  116. color: 'rgb(34,115,141)',
  117. width: 1.0,
  118. curveness: -0.4,
  119. opacity: 0.9,
  120. }
  121. })
  122. }
  123. }
  124. }
  125. return res;
  126. },
  127. /**
  128. * 创建地图配置
  129. * @param {Object} minValue 区间最小值
  130. * @param {Object} maxValue 区间最大值
  131. */
  132. _createVisualMap: function(minValue, maxValue) {
  133. return {
  134. min: minValue,
  135. max: maxValue,
  136. realtime: true, //拖拽时是否实时更新
  137. calculable: false, //是否显示拖拽的手柄
  138. show: false, //是否显示拖拽手柄
  139. inRange: {
  140. color: ['lightskyblue', 'yellow', 'orangered']
  141. }
  142. }
  143. },
  144. /**
  145. * 创建地图
  146. * @param {Object} registerName 注册名称
  147. * @param {Object} propertyName 默认属性名称
  148. */
  149. _createGeo: function(registerName, propertyName) {
  150. return {
  151. map: registerName,
  152. roam: false,
  153. aspectScale: 1.0, //默认显示的地图宽高比
  154. label: {
  155. show: false,
  156. color: "#fff"
  157. },
  158. itemStyle: {
  159. areaColor: 'rgb(20,41,87)',
  160. borderColor: 'rgb(34,115,141)',
  161. borderWidth: 3,
  162. shadowColor: 'rgb(0, 180, 255)',
  163. shadowBlur: 20,
  164. opacity: 0.8,
  165. },
  166. emphasis: {
  167. itemStyle: {
  168. areaColor: 'rgb(128,128,128)',
  169. }
  170. },
  171. scaleLimit: { //滚轮缩放的极限控制
  172. min: 1.2, //缩放最小大小
  173. max: 6 //缩放最大大小
  174. },
  175. nameProperty: propertyName,
  176. }
  177. },
  178. /**
  179. * 斜线纹理
  180. */
  181. _decalSlant: function() {
  182. return {
  183. color: "rgba(0, 0, 0, 0.2)",
  184. dashArrayX: [1, 0],
  185. dashArrayY: [2, 5],
  186. symbolSize: 1,
  187. rotation: 0.523598775598298,
  188. dirty: false,
  189. symbol: "rect",
  190. symbolKeepAspect: true,
  191. backgroundColor: null,
  192. maxTileWidth: 512,
  193. maxTileHeight: 512,
  194. };
  195. },
  196. /**
  197. * 圆形纹理
  198. */
  199. _decalCircle: function() {
  200. return {
  201. color: "rgba(0, 0, 0, 0.2)",
  202. dashArrayX: [
  203. [8, 8],
  204. [0, 8, 8, 0]
  205. ],
  206. dashArrayY: [6, 0],
  207. symbolSize: 0.8,
  208. rotation: 0,
  209. dirty: false,
  210. symbol: "circle",
  211. symbolKeepAspect: true,
  212. backgroundColor: null,
  213. maxTileWidth: 512,
  214. maxTileHeight: 512,
  215. };
  216. },
  217. /**
  218. * 十字交叉纹理
  219. */
  220. _decalCross: function() {
  221. return {
  222. color: "rgba(0, 0, 0, 0.2)",
  223. dashArrayX: [
  224. [1, 0],
  225. [1, 6]
  226. ],
  227. dashArrayY: [1, 0, 6, 0],
  228. symbolSize: 1.0,
  229. rotation: 0.7853981633974483,
  230. dirty: false,
  231. symbol: "rect",
  232. symbolKeepAspect: true,
  233. backgroundColor: null,
  234. maxTileWidth: 512,
  235. maxTileHeight: 512,
  236. }
  237. },
  238. /**
  239. * 矩形方块
  240. */
  241. _decalRect: function() {
  242. return {
  243. color: "rgba(0, 0, 0, 0.2)",
  244. dashArrayX: [
  245. [6, 6],
  246. [0, 6, 6, 0]
  247. ],
  248. dashArrayY: [6, 0],
  249. symbolSize: 1,
  250. rotation: 0,
  251. dirty: false,
  252. symbol: "rect",
  253. symbolKeepAspect: true,
  254. backgroundColor: null,
  255. maxTileWidth: 512,
  256. maxTileHeight: 512,
  257. };
  258. },
  259. /**
  260. * 三角形
  261. */
  262. _decalTriangle: function() {
  263. return {
  264. color: "rgba(0, 0, 0, 0.2)",
  265. dashArrayX: [
  266. [9, 9],
  267. [0, 9, 9, 0]
  268. ],
  269. dashArrayY: [7, 2],
  270. symbolSize: 1,
  271. rotation: 0,
  272. dirty: false,
  273. symbol: "triangle",
  274. symbolKeepAspect: true,
  275. backgroundColor: null,
  276. maxTileWidth: 512,
  277. maxTileHeight: 512,
  278. };
  279. }
  280. });
  281. /**
  282. * 基础方法
  283. */
  284. CrCharts.prototype.extend({
  285. /**
  286. * 清除全部内容
  287. */
  288. clear: function() {
  289. this.chart.clear();
  290. },
  291. /**
  292. * 释放资源
  293. */
  294. dispose: function() {
  295. if(this.chart != null && this.chart != "" && this.chart != undefined)
  296. this.chart.dispose();
  297. },
  298. });
  299. /**
  300. * 对外函数
  301. */
  302. CrCharts.prototype.extend({
  303. /**
  304. * 创建搬迁地图
  305. * @param {Object} jsonFile 地图的JSON文件
  306. * @param {Object} lines 运动线集合
  307. * @param {Object} villageMap 村庄坐标Map
  308. * @param {Object} villageValue 村庄数据集合
  309. * @param {Object} communityMap 社区坐标Map
  310. * @param {Object} communityValue 社区数据集合
  311. */
  312. CreateMap: function(jsonFile, lines, villageMap, villageValue, communityMap, communityValue) {
  313. var self = this;
  314. var series = [];
  315. series.push({
  316. type: 'map',
  317. map: 'village',
  318. roam: false,
  319. itemStyle: {
  320. areaColor: 'rgb(20,41,87)',
  321. borderColor: 'rgb(34,115,141)',
  322. borderWidth: 1,
  323. },
  324. emphasis: {
  325. itemStyle: {
  326. areaColor: 'rgb(128,128,128)',
  327. },
  328. label: {
  329. color: 'rgb(255,255,255)',
  330. }
  331. },
  332. nameProperty: 'XZQMC',
  333. aspectScale: 1.0, //默认显示的地图宽高比
  334. scaleLimit: { //滚轮缩放的极限控制
  335. min: 1.2, //缩放最小大小
  336. max: 6 //缩放最大大小
  337. },
  338. });
  339. series.push({
  340. type: 'lines',
  341. zlevel: 999,
  342. animation: false,
  343. effect: {
  344. show: true, //是否显示特效
  345. period: 7, //特效动画的重复时间
  346. trailLength: 0.1, //尾迹线的长度[0-1]值越大,越长
  347. color: 'rgb(255,255,255)',
  348. symbol: 'circle',
  349. symbolSize: [4, 4]
  350. },
  351. lineStyle: {
  352. color: '#fff',
  353. width: 2.0,
  354. curveness: -0.4
  355. },
  356. data: self._convertLines(lines, villageMap, communityMap, undefined)
  357. });
  358. series.push({
  359. name: '线条',
  360. type: 'lines',
  361. coordinateSystem: 'geo',
  362. data: self._convertLines(lines, villageMap, communityMap, '')
  363. })
  364. series.push({
  365. name: '户数',
  366. type: 'scatter',
  367. coordinateSystem: 'geo',
  368. data: self._convertData(villageMap, villageValue),
  369. symbolSize: function(val) {
  370. return (val[3] * 4) / 1036 + 6;
  371. },
  372. label: {
  373. show: false,
  374. position: 'right',
  375. color: 'rgb(162,200,82)',
  376. fontWeight: 'bold',
  377. fontFamily: 'TTTGB-Medium',
  378. shadowColor: 'rgb(255,255,255)',
  379. shadowBlur: '200',
  380. textBorderColor: 'rgb(255,255,255)',
  381. textBorderWidth: 0,
  382. formatter: '{b}',
  383. },
  384. emphasis: {
  385. itemStyle: {
  386. borderColor: '#fff',
  387. borderWidth: 1
  388. }
  389. }
  390. });
  391. series.push({
  392. name: '社区',
  393. type: 'effectScatter',
  394. coordinateSystem: 'geo',
  395. data: self._convertData(communityMap, communityValue),
  396. symbolSize: function(val) {
  397. return 10;
  398. },
  399. label: {
  400. show: true,
  401. position: 'right',
  402. color: 'rgb(255,255,255)',
  403. fontWeight: 'bold',
  404. fontFamily: 'SimHei',
  405. fontSize: 14,
  406. formatter: '{b}',
  407. },
  408. emphasis: {
  409. itemStyle: {
  410. borderColor: '#fff',
  411. borderWidth: 1
  412. }
  413. }
  414. });
  415. $.get(jsonFile, function(geoJson) {
  416. echarts.registerMap('village', geoJson);
  417. var option = {
  418. visualMap: self._createVisualMap(93, 1129),
  419. geo: self._createGeo('village', 'XZQMC'),
  420. series: series,
  421. }
  422. self.chart.setOption(option);
  423. });
  424. }
  425. });
  426. /**
  427. * 图形函数
  428. */
  429. CrCharts.prototype.extend({
  430. /**
  431. * 创建饼图
  432. * @param {JOSN} jsonData 数据
  433. * @param {String} title 标题
  434. */
  435. createPie: function(jsonData, title) {
  436. var self = this;
  437. var decals = [];
  438. for (var i = 0; i < jsonData.data.length; i++) {
  439. var idx = i % 5;
  440. if (idx == 0) {
  441. decals.push(self._decalSlant());
  442. } else if (idx == 1) {
  443. decals.push(self._decalCircle());
  444. } else if (idx == 2) {
  445. decals.push(self._decalRect());
  446. } else if (idx == 3) {
  447. decals.push(self._decalCross());
  448. } else if (idx == 4) {
  449. decals.push(self._decalTriangle());
  450. }
  451. }
  452. var option = {
  453. tooltip: {
  454. trigger: 'item'
  455. },
  456. aria: {
  457. enabled: true,
  458. decal: {
  459. show: true,
  460. decals: decals,
  461. }
  462. },
  463. stateAnimation: {
  464. duration: 300,
  465. easing: "cubicOut",
  466. },
  467. animation: "auto",
  468. animationDuration: 1000,
  469. animationDurationUpdate: 500,
  470. animationEasing: "cubicInOut",
  471. animationEasingUpdate: "cubicInOut",
  472. animationThreshold: 2000,
  473. series: [{
  474. name: title,
  475. type: 'pie',
  476. radius: jsonData.radius == undefined ? [10, 90] : jsonData.radius,
  477. center: ['50%', '50%'],
  478. roseType: 'radius',
  479. startAngle: jsonData.startAngle == undefined ? 10 : jsonData.startAngle,
  480. label: {
  481. formatter: '{a|{b}}{abg|}\n{hr|}\n{per|{d}%}',
  482. rich: {
  483. a: {
  484. color: 'rgb(69,69,69)',
  485. lineHeight: 22,
  486. align: 'center',
  487. fontFamily: 'TTTGB-Medium',
  488. fontSize: 13,
  489. },
  490. hr: {
  491. borderColor: 'rgb(69,69,69)',
  492. width: '100%',
  493. borderWidth: 1,
  494. height: 0
  495. },
  496. b: {
  497. color: '#4C5058',
  498. fontSize: 10,
  499. fontWeight: 'bold',
  500. lineHeight: 33
  501. },
  502. per: {
  503. color: 'rgb(123,149,248)',
  504. align: 'center',
  505. fontFamily: 'TTTGB-Medium',
  506. lineHeight: 20,
  507. }
  508. }
  509. },
  510. labelLine: {
  511. lineStyle: {
  512. color: 'rgb(69,69,69)',
  513. },
  514. },
  515. labelLayout: {
  516. draggable: false, //是否可以拖动标注
  517. },
  518. itemStyle: {
  519. borderRadius: 0,
  520. shadowColor: '#5cfbff',
  521. shadowBlur: 5,
  522. },
  523. data: jsonData.data,
  524. }]
  525. };
  526. self.chart.setOption(option);
  527. },
  528. /**
  529. * 创建普通饼图
  530. * @param {JOSN} jsonData 数据
  531. * @param {String} title 标题
  532. */
  533. createNormalPie: function(jsonData, title) {
  534. var self = this;
  535. var option = {
  536. tooltip: {
  537. trigger: 'item'
  538. },
  539. legend: {
  540. left: 'center',
  541. show: false,
  542. },
  543. series: [{
  544. name: title,
  545. type: 'pie',
  546. radius: ['40%', '80%'],
  547. center: ['50%', '50%'],
  548. label: {
  549. position: 'inside',
  550. formatter: '{a|{b}}{abg|}\n{per|{d}%}',
  551. rich: {
  552. a: {
  553. color: 'rgb(0,51,102)',
  554. lineHeight: 22,
  555. align: 'center',
  556. fontFamily: 'TTTGB-Medium',
  557. fontSize: 13,
  558. },
  559. hr: {
  560. borderColor: '#fff',
  561. width: '100%',
  562. borderWidth: 2,
  563. height: 0
  564. },
  565. b: {
  566. color: '#4C5058',
  567. fontSize: 10,
  568. fontWeight: 'bold',
  569. lineHeight: 33
  570. },
  571. per: {
  572. color: '#ffff00',
  573. align: 'center',
  574. fontFamily: 'TTTGB-Medium',
  575. }
  576. }
  577. },
  578. itemStyle: {
  579. borderRadius: 5,
  580. borderColor: 'rgb(255,255,255)',
  581. borderWidth: 0,
  582. shadowBlur: 1,
  583. },
  584. data: jsonData,
  585. }]
  586. };
  587. self.chart.setOption(option);
  588. },
  589. /**
  590. * 创建横向柱状图
  591. * @param {JSON} jsonData 横向柱状图数据
  592. * grid:{JSON}{left: right: bottom: top: containLabel:true/false}
  593. * labels:[]
  594. * datas:[{name: values:[] color:[] lblColor: unit:}]
  595. * enabledAria:true/false
  596. */
  597. createHorizontalBar: function(jsonData) {
  598. var self = this;
  599. var decals = [];
  600. decals.push(self._decalSlant());
  601. var legendData = [];
  602. var series = [];
  603. for (var i = 0; i < jsonData.datas.length; i++) {
  604. var data = jsonData.datas[i];
  605. legendData.push(data.name);
  606. /* 标签配置 */
  607. var labelOption = {
  608. show: true,
  609. position: data.lblPosition == undefined ? 'left' : data.lblPosition,
  610. distance: data.lblPosition == undefined ? -10 : 10,
  611. align: 'left',
  612. verticalAlign: 'middle',
  613. rotate: 0,
  614. formatter: '{c}',
  615. fontSize: 12,
  616. color: data.lblColor,
  617. fontFamily: 'TTTGB-Medium',
  618. rich: {
  619. name: {}
  620. }
  621. };
  622. /* 追加单位 */
  623. if (data.unit != undefined) {
  624. labelOption.formatter += data.unit;
  625. }
  626. /* 追加服务 */
  627. var item = {
  628. name: data.name,
  629. label: labelOption,
  630. type: 'bar',
  631. data: data.values,
  632. itemStyle: {
  633. shadowColor: '#5cfbff',
  634. shadowBlur: 5,
  635. }
  636. }
  637. if (data.color.length == 1) {
  638. item.itemStyle.color = data.color[0];
  639. } else if (data.color.length >= 2) {
  640. item.itemStyle.color = {
  641. type: 'linear',
  642. x: 0,
  643. y: 0,
  644. x2: 1,
  645. y2: 0,
  646. colorStops: [{
  647. offset: 0,
  648. color: data.color[0], // 0% 处的颜色
  649. }, {
  650. offset: 1,
  651. color: data.color[1], // 100% 处的颜色
  652. }],
  653. global: false // 缺省为 false
  654. };
  655. }
  656. series.push(item);
  657. }
  658. /* 配置项 */
  659. var option = {
  660. tooltip: {
  661. trigger: 'axis',
  662. axisPointer: {
  663. type: 'shadow'
  664. }
  665. },
  666. aria: {
  667. enabled: jsonData.enabledAria == undefined ? false : jsonData.enabledAria,
  668. decal: {
  669. show: true,
  670. decals: decals,
  671. }
  672. },
  673. legend: {
  674. show: jsonData.lenged == undefined ? true : jsonData.lenged.show,
  675. data: legendData,
  676. textStyle: {
  677. color: 'rgb(255,255,0)',
  678. }
  679. },
  680. grid: jsonData.grid,
  681. xAxis: {
  682. type: 'value',
  683. boundaryGap: [0, 0.01],
  684. axisLabel: self.xAxisLabel,
  685. axisLine: self.xAxisLine,
  686. splitLine: self.splitLine,
  687. },
  688. yAxis: {
  689. type: 'category',
  690. data: jsonData.labels,
  691. axisLabel: self.yAxisLabel,
  692. axisLine: self.yAxisLine,
  693. splitLine: self.splitLine,
  694. },
  695. series: series,
  696. };
  697. if (jsonData.zoom != undefined) {
  698. option.dataZoom = jsonData.zoom;
  699. }
  700. self.chart.setOption(option);
  701. },
  702. /**
  703. * 创建竖向柱状图
  704. * @param {JSON} jsonData 数据集
  705. * @param {int} left 距离左侧的距离
  706. * @param {boolean} enabledAria 是否使用花纹
  707. * @param {array} units 单位名称
  708. */
  709. createVerticalBar: function(jsonData, left, enabledAria, units) {
  710. var self = this;
  711. var grid = {
  712. right: 3,
  713. bottom: jsonData.gridBottom != undefined ? jsonData.gridBottom : 20,
  714. top: 35,
  715. left: left == undefined ? 80 : left,
  716. };
  717. if (jsonData.xrotate != undefined) {
  718. self.xAxisLabel.rotate = jsonData.xrotate;
  719. }
  720. var legendData = [];
  721. var xData = jsonData.labels;
  722. var servies = [];
  723. var decals = [];
  724. decals.push(self._decalSlant());
  725. /*数据配置*/
  726. for (var i = 0; i < jsonData.datas.length; i++) {
  727. var sData = jsonData.datas[i];
  728. legendData.push(sData.name);
  729. /* 标签配置 */
  730. var labelOption = {
  731. show: true,
  732. position: 'top',
  733. distance: 5,
  734. align: 'left',
  735. verticalAlign: 'middle',
  736. rotate: 90,
  737. formatter: function(param) {
  738. return param.value == 0.1 ? "" : param.value;
  739. },
  740. fontSize: 10,
  741. color: 'rgb(69,69,69)',
  742. fontFamily: 'TTTGB-Medium',
  743. rich: {
  744. name: {}
  745. }
  746. };
  747. if (sData.label != undefined) {
  748. if (sData.label.position != undefined) labelOption.position = sData.label
  749. .position;
  750. if (sData.label.rotate != undefined) labelOption.rotate = sData.label.rotate;
  751. if (sData.label.formatter != undefined) labelOption.formatter = sData.label
  752. .formatter;
  753. }
  754. var service = {
  755. name: sData.name,
  756. type: 'bar',
  757. label: labelOption,
  758. emphasis: {
  759. focus: 'series'
  760. },
  761. data: sData.data,
  762. itemStyle: {
  763. color: sData.color,
  764. shadowColor: '#5cfbff',
  765. shadowBlur: 5,
  766. }
  767. };
  768. if (sData.stack != undefined) service.stack = sData.stack;
  769. servies.push(service);
  770. }
  771. /* 图表配置 */
  772. var option = {
  773. tooltip: {
  774. trigger: 'axis',
  775. axisPointer: {
  776. type: 'shadow'
  777. },
  778. formatter: function(params) {
  779. var strHtml = "";
  780. strHtml += "<div class='echarts-tooltip-title'>" + params[0].axisValue + "</div>";
  781. for (var i = 0; i < params.length; i++) {
  782. var unit = units != undefined && units[i] != undefined ? units[
  783. i] : "";
  784. var value = params[i].data > 0 ? params[i].data : params[i]
  785. .data * (-1);
  786. if(value < 1){
  787. continue;
  788. }
  789. if (i != params.length - 1) {
  790. strHtml += params[i].marker + params[i].seriesName + " " +
  791. value + unit + "<br>";
  792. } else {
  793. strHtml += params[i].marker + params[i].seriesName + " " +
  794. value + unit;
  795. }
  796. }
  797. return strHtml;
  798. }
  799. },
  800. aria: {
  801. enabled: enabledAria == undefined ? false : enabledAria,
  802. decal: {
  803. show: true,
  804. decals: decals,
  805. }
  806. },
  807. legend: {
  808. data: legendData,
  809. textStyle: {
  810. color: 'rgb(69,69,69)',
  811. fontSize: 13,
  812. fontFamily: 'TTTGB-Medium',
  813. },
  814. itemGap: 20,
  815. },
  816. grid: grid,
  817. xAxis: [{
  818. type: 'category',
  819. axisTick: {
  820. show: false
  821. },
  822. data: xData,
  823. axisLabel: self.xAxisLabel,
  824. axisLine: self.xAxisLine,
  825. }],
  826. yAxis: [{
  827. type: 'log',
  828. min: 1,
  829. axisLabel: self.yAxisLabel,
  830. axisLine: self.yAxisLine,
  831. splitLine: self.splitLine,
  832. }],
  833. series: servies,
  834. };
  835. self.chart.setOption(option);
  836. },
  837. /**
  838. * 创建折线图
  839. * @param {JSON} jsonData 数据集
  840. */
  841. createLine: function(jsonData) {
  842. var self = this;
  843. var series = [];
  844. var legendData = [];
  845. var xData = jsonData.labels;
  846. for (var i = 0; i < jsonData.datas.length; i++) {
  847. var lData = jsonData.datas[i];
  848. legendData.push(lData.name);
  849. series.push({
  850. name: lData.name,
  851. type: 'line',
  852. yAxisIndex: 0,
  853. symbolSize: 4,
  854. itemStyle: {
  855. color: lData.color,
  856. borderWidth: 2,
  857. shadowColor: '#5cfbff',
  858. shadowBlur: 5,
  859. },
  860. data: lData.data,
  861. smooth: true,
  862. areaStyle: {
  863. opacity: jsonData.areaStyle == undefined ? 0 : jsonData.areaStyle
  864. .opacity,
  865. },
  866. });
  867. if (lData.label != undefined) {
  868. var unit = lData.label.unit == undefined ? '' : lData.label.unit;
  869. series[i].label = {
  870. show: lData.label.show == undefined ? false : lData.label.show,
  871. position: 'top',
  872. distance: 10,
  873. align: 'center',
  874. verticalAlign: 'top',
  875. rotate: lData.label.rotate == undefined ? 0 : lData.label.rotate,
  876. formatter: '{c}' + unit,
  877. fontSize: 12,
  878. color: lData.label.color == undefined ? 'rgb(255,255,255)' : lData.label
  879. .color,
  880. fontFamily: 'TTTGB-Medium',
  881. rich: {
  882. name: {}
  883. }
  884. }
  885. }
  886. }
  887. /* 配置项 */
  888. var option = {
  889. dataZoom: [{
  890. type: "inside" //详细配置可见echarts官网
  891. }],
  892. tooltip: {
  893. trigger: 'axis',
  894. axisPointer: {
  895. type: 'cross'
  896. }
  897. },
  898. legend: {
  899. x: 'center',
  900. y: '0px',
  901. textStyle: {
  902. color: '#FFFFFF',
  903. fontSize: 13,
  904. },
  905. icon: 'circle',
  906. data: legendData,
  907. },
  908. grid: {
  909. right: '5%',
  910. bottom: '5%',
  911. left: '3%',
  912. top: '55px',
  913. containLabel: true
  914. },
  915. xAxis: [{
  916. type: 'category',
  917. data: xData,
  918. axisLine: self.xAxisLine,
  919. axisLabel: self.xAxisLabel,
  920. axisTick: {
  921. show: false,
  922. },
  923. }],
  924. yAxis: [{
  925. type: 'value',
  926. axisLine: self.yAxisLine,
  927. axisLabel: self.yAxisLabel,
  928. splitLine: self.splitLine,
  929. }],
  930. series: series,
  931. };
  932. self.chart.setOption(option);
  933. // var app = {
  934. // currentIndex: -1,
  935. // };
  936. // setInterval(function() {
  937. // var dataLen = option.series[0].data.length;
  938. // // 显示 tooltip
  939. // myChartB.dispatchAction({
  940. // type: 'showTip',
  941. // seriesIndex: 0,
  942. // dataIndex: app.currentIndex
  943. // });
  944. // }, 1000);
  945. },
  946. /**
  947. * 创建混合图
  948. * @param {Object} jsonData 混合Data '{value} ml'
  949. */
  950. createBlend: function(jsonData) {
  951. var self = this;
  952. var legendData = [];
  953. var yAxis = [];
  954. var series = [];
  955. var xAxis = jsonData.labels;
  956. for (var i = 0; i < jsonData.axixs.length; i++) {
  957. var axis = jsonData.axixs[i];
  958. yAxis.push({
  959. type: 'value',
  960. name: axis.name,
  961. min: axis.minValue,
  962. max: axis.maxValue,
  963. interval: axis.spaceValue,
  964. position: axis.position,
  965. offset: axis.offset,
  966. axisLabel: {
  967. formatter: axis.formatter,
  968. color: axis.color,
  969. fontSize: 12,
  970. fontFamily: 'TTTGB-Medium',
  971. },
  972. axisLine: {
  973. show: true,
  974. lineStyle: {
  975. color: axis.color,
  976. },
  977. },
  978. splitLine: self.splitLine,
  979. });
  980. }
  981. for (var i = 0; i < jsonData.datas.length; i++) {
  982. var data = jsonData.datas[i];
  983. legendData.push(data.name);
  984. series.push({
  985. name: data.name,
  986. type: data.type,
  987. data: data.data,
  988. yAxisIndex: data.yAxisIndex,
  989. itemStyle: {
  990. color: data.color,
  991. shadowColor: '#5cfbff',
  992. shadowBlur: 5,
  993. },
  994. smooth: true,
  995. })
  996. }
  997. var option = {
  998. grid: {
  999. right: jsonData.right,
  1000. left: jsonData.left,
  1001. bottom: jsonData.bottom,
  1002. },
  1003. tooltip: {
  1004. trigger: 'axis',
  1005. axisPointer: {
  1006. type: 'cross',
  1007. crossStyle: {
  1008. color: '#999'
  1009. }
  1010. }
  1011. },
  1012. legend: {
  1013. data: legendData,
  1014. x: 'center',
  1015. y: '0px',
  1016. textStyle: {
  1017. color: '#FFFFFF',
  1018. fontSize: 13,
  1019. },
  1020. },
  1021. xAxis: [{
  1022. type: 'category',
  1023. data: xAxis,
  1024. axisPointer: {
  1025. type: 'shadow',
  1026. },
  1027. axisLabel: self.xAxisLabel,
  1028. axisLine: self.xAxisLine,
  1029. }],
  1030. yAxis: yAxis,
  1031. series: series,
  1032. }
  1033. self.chart.setOption(option);
  1034. },
  1035. /**
  1036. * 创建地图
  1037. * @param {Object} jsonFile
  1038. * @param {Object} valueJson
  1039. * @param {Object} valueLegend
  1040. * @param {Object} showName
  1041. * @param {Object} unit
  1042. */
  1043. createMap: function(jsonFile, valueJson, valueLegend, showName, unit) {
  1044. var self = this;
  1045. var minValue = 5000000000,
  1046. maxValue = 0;
  1047. /* 循环获取最大最小值 */
  1048. for (var i = 0; i < valueJson.length; i++) {
  1049. if (valueJson[i].value < minValue) {
  1050. minValue = valueJson[i].value;
  1051. }
  1052. if (valueJson[i].value > maxValue) {
  1053. maxValue = valueJson[i].value;
  1054. }
  1055. }
  1056. var map = {
  1057. min: minValue,
  1058. max: maxValue,
  1059. realtime: true, //拖拽时是否实时更新
  1060. calculable: false, //是否显示拖拽的手柄
  1061. show: true, //是否显示拖拽手柄
  1062. textStyle: {
  1063. color: 'rgb(255,255,0)',
  1064. fontFamily: 'TTTGB-Medium',
  1065. },
  1066. inRange: {
  1067. color: ['rgb(61,201,61)', 'rgb(5,78,5)']
  1068. },
  1069. pieces: valueLegend,
  1070. left: 5,
  1071. }
  1072. $.get(jsonFile, function(geoJson) {
  1073. echarts.registerMap('village', geoJson);
  1074. var option = {
  1075. visualMap: map,
  1076. tooltip: {
  1077. trigger: 'item',
  1078. formatter: '{b}</br>{c}' + unit,
  1079. },
  1080. series: [{
  1081. name: '人口分布',
  1082. type: 'map',
  1083. mapType: 'village',
  1084. nameProperty: showName,
  1085. roam: true,
  1086. aspectScale: 1.0, //默认显示的地图宽高比
  1087. scaleLimit: { //滚轮缩放的极限控制
  1088. min: 1.2, //缩放最小大小
  1089. max: 6 //缩放最大大小
  1090. },
  1091. label: {
  1092. show: false,
  1093. color: 'rgb(255,255,255)',
  1094. fontFamily: 'TTTGB-Medium',
  1095. },
  1096. borderColor: 'rgb(34,115,141)',
  1097. data: valueJson,
  1098. left: 160
  1099. }],
  1100. }
  1101. self.chart.setOption(option);
  1102. });
  1103. },
  1104. /**
  1105. * 创建指标
  1106. * @param {JSON} jsonData 数据JSON
  1107. * {title: min: max: value: unit:}
  1108. */
  1109. createWatch: function(jsonData) {
  1110. var self = this;
  1111. var option = {
  1112. series: [{
  1113. type: 'gauge',
  1114. min: jsonData.min,
  1115. max: jsonData.max,
  1116. axisLine: {
  1117. lineStyle: {
  1118. width: 15,
  1119. color: [
  1120. [0.3, 'rgb(70,197,69)'],
  1121. [0.7, '#37a2da'],
  1122. [1, '#fd666d']
  1123. ]
  1124. }
  1125. },
  1126. pointer: {
  1127. itemStyle: {
  1128. color: 'auto'
  1129. }
  1130. },
  1131. axisTick: {
  1132. distance: -15,
  1133. length: 8,
  1134. lineStyle: {
  1135. color: '#fff',
  1136. width: 2
  1137. }
  1138. },
  1139. splitLine: {
  1140. distance: -15,
  1141. length: 15,
  1142. lineStyle: {
  1143. color: '#fff',
  1144. width: 2
  1145. }
  1146. },
  1147. axisLabel: {
  1148. color: 'auto',
  1149. distance: -19,
  1150. fontSize: 12,
  1151. fontWeight: 'bold',
  1152. },
  1153. detail: {
  1154. valueAnimation: true,
  1155. formatter: '{value}' + jsonData.unit,
  1156. color: 'auto',
  1157. fontSize: 20,
  1158. fontWeight: 'bold',
  1159. // color: 'rgb(255,255,255)',
  1160. },
  1161. data: [{
  1162. value: jsonData.value,
  1163. name: jsonData.title,
  1164. title: {
  1165. show: true,
  1166. offsetCenter: [0, '120%'],
  1167. color: 'rgb(255,255,0)',
  1168. fontSize: 14,
  1169. fontWeight: 'bold',
  1170. }
  1171. }]
  1172. }]
  1173. };
  1174. self.chart.setOption(option);
  1175. },
  1176. /**
  1177. * 创建雷达图
  1178. * @param {JSON} jsonData 雷达图数据
  1179. */
  1180. createRadar: function(jsonData) {
  1181. var self = this;
  1182. /* 获取最大值 */
  1183. var maxValue = 0;
  1184. for (var i = 0; i < jsonData.datas.length; i++) {
  1185. var dataItem = jsonData.datas[i];
  1186. for (var j = 0; j < dataItem.values.length; j++) {
  1187. if (dataItem.values[j] > maxValue) {
  1188. maxValue = dataItem.values[j];
  1189. }
  1190. }
  1191. }
  1192. /* 构建指示器 */
  1193. var indicator = [];
  1194. for (var i = 0; i < jsonData.labels.length; i++) {
  1195. indicator.push({
  1196. name: jsonData.labels[i],
  1197. max: maxValue,
  1198. })
  1199. }
  1200. /* 构建数据集合 */
  1201. var datas = [];
  1202. for (var i = 0; i < jsonData.datas.length; i++) {
  1203. var dataItem = jsonData.datas[i];
  1204. datas.push({
  1205. itemStyle: {
  1206. color: dataItem.color,
  1207. },
  1208. value: dataItem.values,
  1209. name: dataItem.name,
  1210. })
  1211. }
  1212. /* 构建图例 */
  1213. var ldatas = [];
  1214. for (var i = 0; i < jsonData.datas.length; i++) {
  1215. ldatas.push(jsonData.datas[i].name);
  1216. }
  1217. /* 配置项 */
  1218. var option = {
  1219. legend: {
  1220. data: ldatas,
  1221. show: jsonData.lengend,
  1222. textStyle: {
  1223. color: 'rgb(255,255,0)',
  1224. fontFamily: 'TTTGB-Medium',
  1225. },
  1226. icon: 'roundRect',
  1227. },
  1228. radar: {
  1229. // shape: 'circle',
  1230. name: {
  1231. color: jsonData.lblColor,
  1232. fontSize: jsonData.lblSize == undefined ? 13 : jsonData.lblSize,
  1233. fontFamily: 'TTTGB-Medium',
  1234. formatter: function(value, indicator) {
  1235. var val = value.split(';');
  1236. if (val.length == 1) {
  1237. return value;
  1238. } else {
  1239. return '{a|' + val[0] + '}' + '\n' + '{b|' + val[1] + '}';
  1240. }
  1241. },
  1242. rich: {
  1243. a: {
  1244. color: jsonData.lblColor,
  1245. fontSize: 13,
  1246. fontFamily: 'TTTGB-Medium',
  1247. lineHeight: 20,
  1248. },
  1249. b: {
  1250. color: 'rgb(255,255,255)',
  1251. fontSize: 11,
  1252. fontFamily: 'TTTGB-Medium',
  1253. backgroundColor: '#666',
  1254. fontFamily: 'SimHei',
  1255. padding: 4,
  1256. borderRadius: 2,
  1257. align: 'center',
  1258. }
  1259. }
  1260. },
  1261. indicator: indicator,
  1262. splitLine: {
  1263. lineStyle: {
  1264. color: 'rgb(255,255,255,0.35)',
  1265. type: 'dashed'
  1266. },
  1267. },
  1268. axisLine: {
  1269. lineStyle: {
  1270. color: 'rgb(255,255,255,0.35)',
  1271. type: 'dashed'
  1272. }
  1273. }
  1274. },
  1275. series: [{
  1276. type: 'radar',
  1277. data: datas,
  1278. }]
  1279. };
  1280. if (jsonData.lengend) {
  1281. option.radar.center = ['50%', '55%'];
  1282. option.radar.radius = '55%';
  1283. }
  1284. self.chart.setOption(option);
  1285. },
  1286. /**
  1287. * 重置大小
  1288. */
  1289. resize: function() {
  1290. this.chart.resize();
  1291. },
  1292. });