echart.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. $(function () {
  2. /*echart_1();*/
  3. echart_2();
  4. echart_3();
  5. /*echart_4();*/
  6. /*echart_map();*/
  7. echarts_1();
  8. echarts_4();
  9. echarts_2();
  10. char4();
  11. //echart_1
  12. function echart_1() {
  13. // 基于准备好的dom,初始化echarts实例
  14. var myChart = echarts.init(document.getElementById('chart_1'));
  15. var data = [
  16. {value: 335,name: '客运车'},
  17. {value: 335,name: '危险品运输车'},
  18. {value: 315,name: '网约车'},
  19. {value: 200,name: '学生班车'}
  20. ];
  21. option = {
  22. backgroundColor: 'transparent',
  23. tooltip: {
  24. trigger: 'item',
  25. formatter: "{a} <br/>{b}: {c} ({d}%)"
  26. },
  27. color: ['#0035f9', '#f36f8a', '#ffff43', '#25f3e6'],
  28. legend: { //图例组件,颜色和名字
  29. left: '65%',
  30. top: '95',
  31. orient: 'vertical',
  32. itemGap: 12, //图例每项之间的间隔
  33. itemWidth: 16,
  34. itemHeight: 12,
  35. icon: 'rect',
  36. data: ['客运车', '危险品运输车', '网约车', '学生班车'],
  37. textStyle: {
  38. color: [],
  39. fontStyle: 'normal',
  40. fontFamily: '微软雅黑',
  41. fontSize: 12,
  42. }
  43. },
  44. series: [{
  45. name: '车辆类型',
  46. type: 'pie',
  47. clockwise: false, //饼图的扇区是否是顺时针排布
  48. minAngle: 20, //最小的扇区角度(0 ~ 360)
  49. center: ['35%', '50%'], //饼图的中心(圆心)坐标
  50. radius: [50, 80], //饼图的半径
  51. avoidLabelOverlap: true, ////是否启用防止标签重叠
  52. itemStyle: { //图形样式
  53. normal: {
  54. borderColor: '#1e2239',
  55. borderWidth: 1.5,
  56. },
  57. },
  58. label: { //标签的位置
  59. normal: {
  60. show: false,
  61. position: 'inside', //标签的位置
  62. formatter: "{d}%",
  63. textStyle: {
  64. color: '#fff',
  65. }
  66. },
  67. emphasis: {
  68. show: true,
  69. textStyle: {
  70. fontWeight: 'bold'
  71. }
  72. }
  73. },
  74. data: data
  75. }, {
  76. name: '',
  77. type: 'pie',
  78. clockwise: false,
  79. silent: true,
  80. minAngle: 20, //最小的扇区角度(0 ~ 360)
  81. center: ['35%', '50%'], //饼图的中心(圆心)坐标
  82. radius: [0, 45], //饼图的半径
  83. itemStyle: { //图形样式
  84. normal: {
  85. borderColor: '#1e2239',
  86. borderWidth: 1.5,
  87. opacity: 0.21,
  88. }
  89. },
  90. label: { //标签的位置
  91. normal: {
  92. show: false,
  93. }
  94. },
  95. data: data
  96. }]
  97. };
  98. // 使用刚指定的配置项和数据显示图表。
  99. myChart.setOption(option);
  100. window.addEventListener("resize",function(){
  101. myChart.resize();
  102. });
  103. }
  104. function echarts_1() {
  105. // 基于准备好的dom,初始化echarts实例
  106. var myChart = echarts.init(document.getElementById('echarts_1'));
  107. var data = [
  108. {value: 12,name: '行业一'},
  109. {value: 13,name: '行业二'},
  110. {value: 70,name: '行业三'},
  111. {value: 52,name: '行业四'},
  112. {value: 35,name: '行业五'}
  113. ];
  114. option = {
  115. backgroundColor: 'rgba(0,0,0,0)',
  116. tooltip: {
  117. trigger: 'item',
  118. formatter: "{b}: <br/>{c} ({d}%)"
  119. },
  120. color: ['#af89d6', '#4ac7f5', '#0089ff', '#f36f8a', '#f5c847'],
  121. legend: { //图例组件,颜色和名字
  122. x: '70%',
  123. y: 'center',
  124. orient: 'vertical',
  125. itemGap: 12, //图例每项之间的间隔
  126. itemWidth: 10,
  127. itemHeight: 10,
  128. icon: 'rect',
  129. data: ['行业一', '行业二', '行业三', '行业四', '行业五'],
  130. textStyle: {
  131. color: [],
  132. fontStyle: 'normal',
  133. fontFamily: '微软雅黑',
  134. fontSize: 12,
  135. }
  136. },
  137. series: [{
  138. name: '行业占比',
  139. type: 'pie',
  140. clockwise: false, //饼图的扇区是否是顺时针排布
  141. minAngle: 20, //最小的扇区角度(0 ~ 360)
  142. center: ['35%', '50%'], //饼图的中心(圆心)坐标
  143. radius: [50, 75], //饼图的半径
  144. avoidLabelOverlap: true, ////是否启用防止标签重叠
  145. itemStyle: { //图形样式
  146. normal: {
  147. borderColor: '#1e2239',
  148. borderWidth: 2,
  149. },
  150. },
  151. label: { //标签的位置
  152. normal: {
  153. show: true,
  154. position: 'inside', //标签的位置
  155. formatter: "{d}%",
  156. textStyle: {
  157. color: '#fff',
  158. }
  159. },
  160. emphasis: {
  161. show: true,
  162. textStyle: {
  163. fontWeight: 'bold'
  164. }
  165. }
  166. },
  167. data: data
  168. }, {
  169. name: '',
  170. type: 'pie',
  171. clockwise: false,
  172. silent: true,
  173. minAngle: 20, //最小的扇区角度(0 ~ 360)
  174. center: ['35%', '50%'], //饼图的中心(圆心)坐标
  175. radius: [0, 40], //饼图的半径
  176. itemStyle: { //图形样式
  177. normal: {
  178. borderColor: '#1e2239',
  179. borderWidth: 1.5,
  180. opacity: 0.21,
  181. }
  182. },
  183. label: { //标签的位置
  184. normal: {
  185. show: false,
  186. }
  187. },
  188. data: data
  189. }]
  190. };
  191. // 使用刚指定的配置项和数据显示图表。
  192. myChart.setOption(option);
  193. window.addEventListener("resize",function(){
  194. myChart.resize();
  195. });
  196. }
  197. //echart_2
  198. function echart_2() {
  199. // 基于准备好的dom,初始化echarts实例
  200. var myChart = echarts.init(document.getElementById('chart_2'));
  201. option = {
  202. tooltip: {
  203. trigger: 'axis',
  204. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  205. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  206. }
  207. },
  208. legend: {
  209. // align: 'center',
  210. // left: '65%',
  211. top: '28',
  212. data: ['行驶', '停车', '熄火', '离线'],
  213. itemWidth:16,
  214. itemHeight:12,
  215. // borderRadius: 0, // 统一设置四个角的圆角大小
  216. icon: 'rect',
  217. textStyle: {
  218. itemGap: 12, //图例每项之间的间隔
  219. color: [],
  220. fontStyle: 'normal',
  221. fontFamily: '微软雅黑',
  222. fontSize: 14,
  223. }
  224. },
  225. grid: {
  226. left: '5%',
  227. right: '5%',
  228. bottom: '5%',
  229. containLabel: true
  230. },
  231. xAxis: {
  232. axisLabel: { //调整x轴的lable
  233. textStyle: {
  234. color: '#fff',
  235. fontSize: 13,
  236. }
  237. },
  238. splitLine: {
  239. show: false
  240. }
  241. },
  242. yAxis: {
  243. type: 'category',
  244. data: ['学生班车', '网约车', '危险品运输车', '客运车'],
  245. axisTick : {show: true},
  246. axisLabel: { //调整x轴的lable
  247. textStyle: {
  248. color: '#fff',
  249. fontSize: 13,
  250. }
  251. },
  252. splitLine: {
  253. show: false
  254. }
  255. },
  256. series: [{
  257. name: '行驶',
  258. type: 'bar',
  259. stack: '总量',
  260. color:'#0035f9',
  261. barWidth : 18,
  262. label: {
  263. normal: {
  264. show: false,
  265. position: 'insideRight'
  266. }
  267. },
  268. data: [4, 10, 8, 7]
  269. }, {
  270. name: '停车',
  271. type: 'bar',
  272. stack: '总量',
  273. color:'#f36f8a',
  274. barWidth : 20,
  275. label: {
  276. normal: {
  277. show: false,
  278. position: 'insideRight'
  279. }
  280. },
  281. data: [10, 4, 5, 6]
  282. }, {
  283. name: '熄火',
  284. type: 'bar',
  285. stack: '总量',
  286. color:'#efe39b',
  287. barWidth : 20,
  288. label: {
  289. normal: {
  290. show: false,
  291. position: 'insideRight'
  292. }
  293. },
  294. data: [4, 10, 8, 7]
  295. }, {
  296. name: '离线',
  297. type: 'bar',
  298. stack: '总量',
  299. color:'#25f3e6',
  300. barWidth : 20,
  301. label: {
  302. normal: {
  303. show: false,
  304. position: 'insideRight'
  305. }
  306. },
  307. data: [4, 10, 8, 7]
  308. }
  309. ]
  310. };
  311. // 使用刚指定的配置项和数据显示图表。
  312. myChart.setOption(option);
  313. window.addEventListener("resize",function(){
  314. myChart.resize();
  315. });
  316. }
  317. // echart_map
  318. function echart_map() {
  319. // 基于准备好的dom,初始化echarts实例
  320. var myChart = echarts.init(document.getElementById('chart_map'));
  321. /*var name_title = "投票统计"
  322. var subname = ''
  323. var nameColor = " rgb(55, 75, 113)"
  324. var name_fontFamily = '楷体'
  325. var name_fontSize = 52
  326. var mapName = 'china'
  327. var data = []
  328. var geoCoordMap = {};
  329. var toolTipData = [];
  330. /!*获取地图数据*!/
  331. myChart.showLoading();
  332. var mapFeatures = echarts.getMap(mapName).geoJson.features;
  333. myChart.hideLoading();
  334. mapFeatures.forEach(function(v) {
  335. // 地区名称
  336. var name = v.properties.name;
  337. // 地区经纬度
  338. geoCoordMap[name] = v.properties.cp;
  339. data.push({
  340. name: name,
  341. value: Math.round(Math.random() * 100 + 10)
  342. })
  343. toolTipData.push({
  344. name: name,
  345. value: [{
  346. name: "客运车",
  347. value: Math.round(Math.random() * 100 + 10)
  348. },
  349. {
  350. name: "危险品运输车",
  351. value: Math.round(Math.random() * 100 + 10)
  352. },
  353. {
  354. name: "网约车",
  355. value: Math.round(Math.random() * 100 + 10)
  356. },
  357. {
  358. name: "学生班车",
  359. value: Math.round(Math.random() * 100 + 10)
  360. }
  361. ]
  362. })
  363. });
  364. var max = 480,
  365. min = 9; // todo
  366. var maxSize4Pin = 100,
  367. minSize4Pin = 20;
  368. var convertData = function(data) {
  369. var res = [];
  370. for (var i = 0; i < data.length; i++) {
  371. var geoCoord = geoCoordMap[data[i].name];
  372. if (geoCoord) {
  373. res.push({
  374. name: data[i].name,
  375. value: geoCoord.concat(data[i].value),
  376. });
  377. }
  378. }
  379. return res;
  380. };
  381. option = {
  382. title: {
  383. show:false,
  384. text: name_title,
  385. subtext: subname,
  386. x: 'center',
  387. textStyle: {
  388. color: nameColor,
  389. fontFamily: name_fontFamily,
  390. fontSize: name_fontSize
  391. }
  392. },
  393. tooltip: {
  394. trigger: 'item',
  395. formatter: function(params) {
  396. if (typeof(params.value)[2] == "undefined") {
  397. var toolTiphtml = ''
  398. for(var i = 0;i<toolTipData.length;i++){
  399. if(params.name==toolTipData[i].name){
  400. toolTiphtml += toolTipData[i].name+':<br>'
  401. for(var j = 0;j<toolTipData[i].value.length;j++){
  402. toolTiphtml+=toolTipData[i].value[j].name+':'+toolTipData[i].value[j].value+"<br>"
  403. }
  404. }
  405. }
  406. return toolTiphtml;
  407. } else {
  408. var toolTiphtml = ''
  409. for(var i = 0;i<toolTipData.length;i++){
  410. if(params.name==toolTipData[i].name){
  411. toolTiphtml += toolTipData[i].name+':<br>'
  412. for(var j = 0;j<toolTipData[i].value.length;j++){
  413. toolTiphtml+=toolTipData[i].value[j].name+':'+toolTipData[i].value[j].value+"<br>"
  414. }
  415. }
  416. }
  417. return toolTiphtml;
  418. }
  419. }
  420. },
  421. legend: {
  422. orient: 'vertical',
  423. y: 'bottom',
  424. x: 'right',
  425. data: ['credit_pm2.5'],
  426. textStyle: {
  427. color: '#fff'
  428. }
  429. },
  430. visualMap: {
  431. show: false,
  432. min: 0,
  433. max: 500,
  434. left: 'left',
  435. top: 'bottom',
  436. text: ['高', '低'], // 文本,默认为数值文本
  437. calculable: true,
  438. seriesIndex: [1],
  439. inRange: {
  440. // color: ['#3B5077', '#031525'] // 蓝黑
  441. // color: ['#ffc0cb', '#800080'] // 红紫
  442. // color: ['#3C3B3F', '#605C3C'] // 黑绿
  443. color: ['#0f0c29', '#302b63', '#24243e'] // 黑紫黑
  444. // color: ['#23074d', '#cc5333'] // 紫红
  445. // color: ['#00467F', '#A5CC82'] // 蓝绿
  446. // color: ['#1488CC', '#2B32B2'] // 浅蓝
  447. // color: ['#00467F', '#A5CC82'] // 蓝绿
  448. // color: ['#00467F', '#A5CC82'] // 蓝绿
  449. // color: ['#00467F', '#A5CC82'] // 蓝绿
  450. // color: ['#00467F', '#A5CC82'] // 蓝绿
  451. }
  452. },
  453. /!*工具按钮组*!/
  454. toolbox: {
  455. show: false,
  456. orient: 'vertical',
  457. left: 'right',
  458. top: 'center',
  459. feature: {
  460. dataView: {
  461. readOnly: false
  462. },
  463. restore: {},
  464. saveAsImage: {}
  465. }
  466. },
  467. geo: {
  468. show: true,
  469. map: mapName,
  470. label: {
  471. normal: {
  472. show: false
  473. },
  474. emphasis: {
  475. show: false,
  476. }
  477. },
  478. roam: true,
  479. itemStyle: {
  480. normal: {
  481. areaColor: '#031525',
  482. borderColor: '#3B5077',
  483. },
  484. emphasis: {
  485. areaColor: '#2B91B7',
  486. }
  487. }
  488. },
  489. series: [{
  490. name: '散点',
  491. type: 'scatter',
  492. coordinateSystem: 'geo',
  493. data: convertData(data),
  494. symbolSize: function(val) {
  495. return val[2] / 10;
  496. },
  497. label: {
  498. normal: {
  499. formatter: '{b}',
  500. position: 'right',
  501. show: true
  502. },
  503. emphasis: {
  504. show: true
  505. }
  506. },
  507. itemStyle: {
  508. normal: {
  509. color: '#05C3F9'
  510. }
  511. }
  512. },
  513. {
  514. type: 'map',
  515. map: mapName,
  516. geoIndex: 0,
  517. aspectScale: 0.75, //长宽比
  518. showLegendSymbol: false, // 存在legend时显示
  519. label: {
  520. normal: {
  521. show: true
  522. },
  523. emphasis: {
  524. show: false,
  525. textStyle: {
  526. color: '#fff'
  527. }
  528. }
  529. },
  530. roam: true,
  531. itemStyle: {
  532. normal: {
  533. areaColor: '#031525',
  534. borderColor: '#0227ad',
  535. },
  536. emphasis: {
  537. areaColor: '#2B91B7'
  538. }
  539. },
  540. animation: false,
  541. data: data
  542. },
  543. {
  544. name: '点',
  545. type: 'scatter',
  546. coordinateSystem: 'geo',
  547. symbol: 'pin', //气泡
  548. symbolSize: function(val) {
  549. var a = (maxSize4Pin - minSize4Pin) / (max - min);
  550. var b = minSize4Pin - a * min;
  551. b = maxSize4Pin - a * max;
  552. return a * val[2] + b;
  553. },
  554. label: {
  555. //气泡上的文字
  556. normal: {
  557. show: false,
  558. textStyle: {
  559. color: '#fff',
  560. fontSize: 9,
  561. }
  562. }
  563. },
  564. itemStyle: {
  565. normal: {
  566. color: '#F62157', //标志颜色
  567. }
  568. },
  569. zlevel: 6,
  570. data: convertData(data),
  571. },
  572. {
  573. name: 'Top 5',
  574. type: 'effectScatter',
  575. coordinateSystem: 'geo',
  576. data: convertData(data.sort(function(a, b) {
  577. return b.value - a.value;
  578. }).slice(0, 5)),
  579. symbolSize: function(val) {
  580. return val[2] / 10;
  581. },
  582. showEffectOn: 'render',
  583. rippleEffect: {
  584. brushType: 'stroke'
  585. },
  586. hoverAnimation: true,
  587. label: {
  588. normal: {
  589. formatter: '{b}',
  590. position: 'right',
  591. show: true
  592. }
  593. },
  594. itemStyle: {
  595. normal: {
  596. color: '#05C3F9',
  597. shadowBlur: 10,
  598. shadowColor: '#05C3F9'
  599. }
  600. },
  601. zlevel: 1
  602. },
  603. ]
  604. };
  605. myChart.setOption(option);*/
  606. //var myChart = echarts.init(dom);
  607. var app = {};
  608. option = null;
  609. var posList = [
  610. 'left', 'right', 'top', 'bottom',
  611. 'inside',
  612. 'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
  613. 'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
  614. ];
  615. app.configParameters = {
  616. rotate: {
  617. min: -90,
  618. max: 90
  619. },
  620. align: {
  621. options: {
  622. left: 'left',
  623. center: 'center',
  624. right: 'right'
  625. }
  626. },
  627. verticalAlign: {
  628. options: {
  629. top: 'top',
  630. middle: 'middle',
  631. bottom: 'bottom'
  632. }
  633. },
  634. position: {
  635. options: echarts.util.reduce(posList, function (map, pos) {
  636. map[pos] = pos;
  637. return map;
  638. }, {})
  639. },
  640. distance: {
  641. min: 0,
  642. max: 100
  643. }
  644. };
  645. app.config = {
  646. rotate: 90,
  647. align: 'left',
  648. verticalAlign: 'middle',
  649. position: 'insideBottom',
  650. distance: 15,
  651. onChange: function () {
  652. var labelOption = {
  653. normal: {
  654. rotate: app.config.rotate,
  655. align: app.config.align,
  656. verticalAlign: app.config.verticalAlign,
  657. position: app.config.position,
  658. distance: app.config.distance
  659. }
  660. };
  661. myChart.setOption({
  662. series: [{
  663. label: labelOption
  664. }, {
  665. label: labelOption
  666. }, {
  667. label: labelOption
  668. }, {
  669. label: labelOption
  670. }]
  671. });
  672. }
  673. };
  674. var labelOption = {
  675. show: true,
  676. position: app.config.position,
  677. distance: app.config.distance,
  678. align: app.config.align,
  679. verticalAlign: app.config.verticalAlign,
  680. rotate: app.config.rotate,
  681. formatter: '{c} {name|{a}}',
  682. fontSize: 16,
  683. rich: {
  684. name: {
  685. textBorderColor: '#fff'
  686. }
  687. }
  688. };
  689. option = {
  690. color: ['#003366', '#006699', '#4cabce', '#e5323e'],
  691. tooltip: {
  692. trigger: 'axis',
  693. axisPointer: {
  694. type: 'shadow'
  695. }
  696. },
  697. legend: {
  698. data: ['Forest', 'Steppe', 'Desert', 'Wetland']
  699. },
  700. toolbox: {
  701. show: true,
  702. orient: 'vertical',
  703. left: 'right',
  704. top: 'center',
  705. feature: {
  706. mark: {show: true},
  707. dataView: {show: true, readOnly: false},
  708. magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
  709. restore: {show: true},
  710. saveAsImage: {show: true}
  711. }
  712. },
  713. xAxis: [
  714. {
  715. type: 'category',
  716. axisTick: {show: false},
  717. data: ['2012', '2013', '2014', '2015', '2016']
  718. }
  719. ],
  720. yAxis: [
  721. {
  722. type: 'value'
  723. }
  724. ],
  725. series: [
  726. {
  727. name: 'Forest',
  728. type: 'bar',
  729. barGap: 0,
  730. label: labelOption,
  731. data: [320, 332, 301, 334, 390]
  732. },
  733. {
  734. name: 'Steppe',
  735. type: 'bar',
  736. label: labelOption,
  737. data: [220, 182, 191, 234, 290]
  738. },
  739. {
  740. name: 'Desert',
  741. type: 'bar',
  742. label: labelOption,
  743. data: [150, 232, 201, 154, 190]
  744. },
  745. {
  746. name: 'Wetland',
  747. type: 'bar',
  748. label: labelOption,
  749. data: [98, 77, 101, 99, 40]
  750. }
  751. ]
  752. };;
  753. /*if (option && typeof option === "object") {
  754. myChart.setOption(option, true);
  755. }*/
  756. myChart.setOption(option);
  757. // 使用刚指定的配置项和数据显示图表。
  758. myChart.setOption(option);
  759. window.addEventListener("resize",function(){
  760. myChart.resize();
  761. });
  762. }
  763. //echart_3
  764. function echart_3() {
  765. // 基于准备好的dom,初始化echarts实例
  766. var myChart = echarts.init(document.getElementById('chart_3'));
  767. var xAxisData = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9','10','11','12','13','14','15','16','17','18','19','20','21','22','23'];
  768. var legendData= ['','',''];
  769. var title = "";
  770. var serieData = [];
  771. var metaDate = [
  772. [120, 140, 100, 120, 300, 230, 130, 170,140, 120, 300, 230,120, 140, 100, 120, 300, 230, 130, 170,140, 120, 300, 230]
  773. ]
  774. for(var v=0; v < legendData.length ; v++){
  775. var serie = {
  776. name:legendData[v],
  777. type: 'line',
  778. symbol:"circle",
  779. symbolSize:10,
  780. data: metaDate[v]
  781. };
  782. serieData.push(serie)
  783. }
  784. var colors = ["#ffff43"];
  785. var option = {
  786. backgroundColor: 'transparent',
  787. title : {text: title,textAlign:'left',textStyle:{color:"#fff",fontSize:"16",fontWeight:"normal"}},
  788. color:colors,
  789. grid: {left: '4%',top:"30%",bottom: "5%",right:"4%",containLabel: true},
  790. tooltip : { trigger: 'axis',axisPointer : { type : 'shadow'}},
  791. xAxis: [
  792. {
  793. type: 'category',
  794. axisLine: { show: true,lineStyle:{ color:'#2c3459' }},
  795. axisLabel:{interval:0,textStyle:{color:'#fff',fontSize:12} },
  796. axisTick : {show: false},
  797. data:xAxisData,
  798. },
  799. ],
  800. yAxis: [
  801. {
  802. axisTick : {show: false},
  803. splitLine: {show:false},
  804. axisLabel:{textStyle:{color:'#fff',fontSize:12} },
  805. axisLine: { show: true,lineStyle:{ color:'#2c3459'}},
  806. },
  807. ],
  808. series:serieData
  809. };
  810. // 使用刚指定的配置项和数据显示图表。
  811. myChart.setOption(option);
  812. window.addEventListener("resize",function(){
  813. myChart.resize();
  814. });
  815. }
  816. function echart_4() {
  817. // 基于准备好的dom,初始化echarts实例
  818. var myChart = echarts.init(document.getElementById('chart_4'));
  819. /*中间显示的数据*/
  820. /*中间显示的数据*/
  821. var myData = ['超速', 'SOS', '偏移', '其他']
  822. var databeast = {
  823. 1: [38, 25, 26, 32]
  824. }
  825. var databeauty = {
  826. 1: [11, 38, 23, 30]
  827. }
  828. var timeLineData = [1]
  829. var option = {
  830. baseOption: {
  831. backgroundColor: 'transparent',
  832. timeline: {
  833. show: false,
  834. top: 0,
  835. data: []
  836. },
  837. legend: {
  838. show:true,
  839. // align: 'center',
  840. left: '30%',
  841. top: 30,
  842. // data: ['行驶', '停车'],
  843. // itemWidth:16,
  844. // itemHeight:12,
  845. // // borderRadius: 0, // 统一设置四个角的圆角大小
  846. icon: 'rect',
  847. textStyle: {
  848. itemGap: 12, //图例每项之间的间隔
  849. color: [],
  850. fontStyle: 'normal',
  851. fontFamily: '微软雅黑',
  852. fontSize: 14,
  853. }
  854. },
  855. tooltip: {
  856. show: true,
  857. trigger: 'axis',
  858. formatter: '{b}<br/>{a}: {c}',
  859. axisPointer: {
  860. type: 'shadow'
  861. }
  862. },
  863. grid: [{
  864. show: false,
  865. left: '8%',
  866. top: 60,
  867. bottom: 0,
  868. containLabel: true,
  869. width: '30%'
  870. }, {
  871. show: false,
  872. left: '57%',
  873. top: 60,
  874. bottom: 0,
  875. width: '0%'
  876. }, {
  877. show: false,
  878. right: '8%',
  879. top: 60,
  880. bottom: 0,
  881. containLabel: true,
  882. width: '30%'
  883. }],
  884. xAxis: [{
  885. type: 'value',
  886. inverse: true,
  887. axisLine: {
  888. show: false
  889. },
  890. axisTick: {
  891. show: false
  892. },
  893. position: 'top',
  894. axisLabel: {
  895. show: false
  896. },
  897. splitLine: {
  898. show: false
  899. }
  900. }, {
  901. gridIndex: 1,
  902. show: false
  903. }, {
  904. gridIndex: 2,
  905. nameTextStyle: {
  906. color: '#50afff',
  907. fontSize: 14
  908. },
  909. axisLine: {
  910. show: false
  911. },
  912. axisTick: {
  913. show: false
  914. },
  915. position: 'top',
  916. axisLabel: {
  917. show: false
  918. },
  919. splitLine: {
  920. show: false
  921. }
  922. }],
  923. yAxis: [{
  924. type: 'category',
  925. inverse: true,
  926. position: 'right',
  927. axisLine: {
  928. show: false
  929. },
  930. axisTick: {
  931. show: false
  932. },
  933. axisLabel: {
  934. show: false
  935. },
  936. data: myData
  937. }, {
  938. gridIndex: 1,
  939. type: 'category',
  940. inverse: true,
  941. position: 'left',
  942. axisLine: {
  943. show: false
  944. },
  945. axisTick: {
  946. show: false
  947. },
  948. axisLabel: {
  949. show: true,
  950. textStyle: {
  951. color: '#fff',
  952. fontSize: 14
  953. }
  954. },
  955. data: myData.map(function(value) {
  956. return {
  957. value: value,
  958. textStyle: {
  959. align: 'center'
  960. }
  961. }
  962. })
  963. }, {
  964. gridIndex: 2,
  965. type: 'category',
  966. inverse: true,
  967. position: 'left',
  968. axisLine: {
  969. show: false
  970. },
  971. axisTick: {
  972. show: false
  973. },
  974. axisLabel: {
  975. show: false
  976. },
  977. data: myData
  978. }],
  979. series: [
  980. ]
  981. },
  982. options: []
  983. }
  984. option.baseOption.timeline.data.push(timeLineData[0])
  985. option.options.push({
  986. tooltip: {
  987. trigger: 'axis',
  988. formatter: '{b}<br/>{c} {a}'
  989. },
  990. series: [{
  991. name: '昨天',
  992. type: 'bar',
  993. barWidth: 17,
  994. label: {
  995. normal: {
  996. show: true,
  997. position: 'left',
  998. offset: [0, 0],
  999. textStyle: {
  1000. color: '#fff',
  1001. fontSize: 14
  1002. }
  1003. }
  1004. },
  1005. itemStyle: {
  1006. normal: {
  1007. color: '#0035f9',
  1008. // barBorderRadius: 50
  1009. }
  1010. },
  1011. data: databeast[timeLineData[0]]
  1012. }, {
  1013. name: '今天',
  1014. type: 'bar',
  1015. barWidth: 18,
  1016. xAxisIndex: 2,
  1017. yAxisIndex: 2,
  1018. label: {
  1019. normal: {
  1020. show: true,
  1021. position: 'right',
  1022. offset: [0, 0],
  1023. textStyle: {
  1024. color: '#fff',
  1025. fontSize: 14
  1026. }
  1027. }
  1028. },
  1029. itemStyle: {
  1030. normal: {
  1031. color: '#25f3e6',
  1032. // barBorderRadius: 50
  1033. }
  1034. },
  1035. data: databeauty[timeLineData[0]]
  1036. }]
  1037. })
  1038. // 使用刚指定的配置项和数据显示图表。
  1039. myChart.setOption(option);
  1040. window.addEventListener("resize",function(){
  1041. myChart.resize();
  1042. });
  1043. }
  1044. function echarts_4() {
  1045. // 基于准备好的dom,初始化echarts实例
  1046. var myChart = echarts.init(document.getElementById('echart4'));
  1047. option = {
  1048. tooltip: {
  1049. trigger: 'axis',
  1050. axisPointer: {
  1051. lineStyle: {
  1052. color: '#57617B'
  1053. }
  1054. }
  1055. },
  1056. "legend": {
  1057. "data": [
  1058. {"name": "图例1"},
  1059. {"name": "图例2"},
  1060. {"name": "完成率"}
  1061. ],
  1062. "top": "0%",
  1063. "textStyle": {
  1064. "color": "rgba(255,255,255,0.9)"//图例文字
  1065. }
  1066. },
  1067. "xAxis": [
  1068. {
  1069. "type": "category",
  1070. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  1071. axisLine: { lineStyle: {color: "rgba(255,255,255,.1)"}},
  1072. axisLabel: { textStyle: {color: "rgba(255,255,255,1)", fontSize: '14', },
  1073. },
  1074. },
  1075. ],
  1076. "yAxis": [
  1077. {
  1078. "type": "value",
  1079. "name": "金额",
  1080. "min": 0,
  1081. "max": 50,
  1082. "interval": 10,
  1083. "axisLabel": {
  1084. "show": true,
  1085. },
  1086. axisLine: {lineStyle: {color: 'rgba(255,255,67,.8)'}},//左线色
  1087. },
  1088. {
  1089. "type": "value",
  1090. "name": "完成率",
  1091. "show": true,
  1092. "axisLabel": {
  1093. "show": true,
  1094. },
  1095. axisLine: {lineStyle: {color: 'rgba(255,255,67,.8)'}},//右线色
  1096. splitLine: {show:true,lineStyle: {color:"#ffffff"}},//x轴线
  1097. },
  1098. ],
  1099. "grid": {
  1100. "top": "10%",
  1101. "right":"30",
  1102. "bottom":"30",
  1103. "left":"30",
  1104. },
  1105. "series": [
  1106. {
  1107. "name": "图例1",
  1108. "type": "bar",
  1109. "data": [4,6,36,6,8,6,4,6,30,6,8,12],
  1110. "barWidth": "auto",
  1111. "itemStyle": {
  1112. "normal": {
  1113. "color": {
  1114. "type": "linear",
  1115. "x": 0,
  1116. "y": 0,
  1117. "x2": 0,
  1118. "y2": 1,
  1119. "colorStops": [
  1120. {
  1121. "offset": 0,
  1122. "color": "#609db8"
  1123. },
  1124. {
  1125. "offset": 1,
  1126. "color": "#609db8"
  1127. }
  1128. ],
  1129. "globalCoord": false
  1130. }
  1131. }
  1132. }
  1133. },
  1134. {
  1135. "name": "图例2",
  1136. "type": "bar",
  1137. "data": [
  1138. 4,2,34,6,8,6,4,2,32,6,8,18
  1139. ],
  1140. "barWidth": "auto",
  1141. "itemStyle": {
  1142. "normal": {
  1143. "color": {
  1144. "type": "linear",
  1145. "x": 0,
  1146. "y": 0,
  1147. "x2": 0,
  1148. "y2": 1,
  1149. "colorStops": [
  1150. {
  1151. "offset": 0,
  1152. "color": "#66b8a7"
  1153. },
  1154. {
  1155. "offset": 1,
  1156. "color": "#66b8a7"
  1157. }
  1158. ],
  1159. "globalCoord": false
  1160. }
  1161. }
  1162. },
  1163. "barGap": "0"
  1164. },
  1165. {
  1166. "name": "完成率",
  1167. "type": "line",
  1168. "yAxisIndex": 1,
  1169. "data": [100,50,80,30,90,40, 70,33,100,40,80,20],
  1170. lineStyle: {
  1171. normal: {
  1172. width: 2
  1173. },
  1174. },
  1175. "itemStyle": {
  1176. "normal": {
  1177. "color": "#cdba00",
  1178. }
  1179. },
  1180. "smooth": true
  1181. }
  1182. ]
  1183. };
  1184. // 使用刚指定的配置项和数据显示图表。
  1185. myChart.setOption(option);
  1186. window.addEventListener("resize",function(){
  1187. myChart.resize();
  1188. });
  1189. }
  1190. })
  1191. function echarts_2() {
  1192. // 基于准备好的dom,初始化echarts实例
  1193. var myChart = echarts.init(document.getElementById('echarts_2'));
  1194. option = {
  1195. backgroundColor: 'rgba(0,0,0,0)',
  1196. tooltip: {
  1197. trigger: 'item',
  1198. formatter: "{b} <br/>{c}辆"
  1199. },
  1200. legend: {
  1201. x: 'center',
  1202. y: '2%',
  1203. data: ['车型一', '车型二', '车型三', '车型四', '车型五'],
  1204. icon: 'circle',
  1205. textStyle: {
  1206. color: '#fff',
  1207. }
  1208. },
  1209. calculable: true,
  1210. series: [{
  1211. name: '车型',
  1212. type: 'pie',
  1213. //起始角度,支持范围[0, 360]
  1214. startAngle: 0,
  1215. //饼图的半径,数组的第一项是内半径,第二项是外半径
  1216. radius: [41, 110],
  1217. //支持设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度
  1218. center: ['50%', '20%'],
  1219. //是否展示成南丁格尔图,通过半径区分数据大小。可选择两种模式:
  1220. // 'radius' 面积展现数据的百分比,半径展现数据的大小。
  1221. // 'area' 所有扇区面积相同,仅通过半径展现数据大小
  1222. roseType: 'area',
  1223. //是否启用防止标签重叠策略,默认开启,圆环图这个例子中需要强制所有标签放在中心位置,可以将该值设为 false。
  1224. avoidLabelOverlap: false,
  1225. label: {
  1226. normal: {
  1227. show: true,
  1228. formatter: '{c}辆'
  1229. },
  1230. emphasis: {
  1231. show: true
  1232. }
  1233. },
  1234. labelLine: {
  1235. normal: {
  1236. show: true,
  1237. length2: 1,
  1238. },
  1239. emphasis: {
  1240. show: true
  1241. }
  1242. },
  1243. data: [{
  1244. value: 600,
  1245. name: '车型一',
  1246. itemStyle: {
  1247. normal: {
  1248. color: '#f845f1'
  1249. }
  1250. }
  1251. },
  1252. {
  1253. value: 1100,
  1254. name: '车型二',
  1255. itemStyle: {
  1256. normal: {
  1257. color: '#ad46f3'
  1258. }
  1259. }
  1260. },
  1261. {
  1262. value: 1200,
  1263. name: '车型三',
  1264. itemStyle: {
  1265. normal: {
  1266. color: '#5045f6'
  1267. }
  1268. }
  1269. },
  1270. {
  1271. value: 1300,
  1272. name: '车型四',
  1273. itemStyle: {
  1274. normal: {
  1275. color: '#4777f5'
  1276. }
  1277. }
  1278. },
  1279. {
  1280. value: 1400,
  1281. name: '车型五',
  1282. itemStyle: {
  1283. normal: {
  1284. color: '#44aff0'
  1285. }
  1286. }
  1287. },
  1288. {
  1289. value: 0,
  1290. name: "",
  1291. label: {
  1292. show: false
  1293. },
  1294. labelLine: {
  1295. show: false
  1296. }
  1297. },
  1298. {
  1299. value: 0,
  1300. name: "",
  1301. label: {
  1302. show: false
  1303. },
  1304. labelLine: {
  1305. show: false
  1306. }
  1307. },
  1308. {
  1309. value: 0,
  1310. name: "",
  1311. label: {
  1312. show: false
  1313. },
  1314. labelLine: {
  1315. show: false
  1316. }
  1317. },
  1318. {
  1319. value: 0,
  1320. name: "",
  1321. label: {
  1322. show: false
  1323. },
  1324. labelLine: {
  1325. show: false
  1326. }
  1327. },
  1328. {
  1329. value: 0,
  1330. name: "",
  1331. label: {
  1332. show: false
  1333. },
  1334. labelLine: {
  1335. show: false
  1336. }
  1337. }
  1338. ]
  1339. }]
  1340. };
  1341. // 使用刚指定的配置项和数据显示图表。
  1342. myChart.setOption(option);
  1343. window.addEventListener("resize",function(){
  1344. myChart.resize();
  1345. });
  1346. }
  1347. function char4() {
  1348. var myChart = echarts.init($("#char4")[0]);
  1349. option = {
  1350. grid: {show:'true',borderWidth:'0'},
  1351. tooltip : {
  1352. trigger: 'axis',
  1353. axisPointer : { // 坐标轴指示器,坐标轴触发有效
  1354. type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  1355. },
  1356. formatter: function (params) {
  1357. var tar = params[0];
  1358. return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
  1359. }
  1360. },
  1361. xAxis : [
  1362. {
  1363. type : 'category',
  1364. splitLine: {show:false},
  1365. data : ['客运车','危险品车','网约车','学生校车'],
  1366. axisLabel: {
  1367. show: true,
  1368. textStyle: {
  1369. color: '#fff'
  1370. }
  1371. }
  1372. }
  1373. ],
  1374. yAxis : [
  1375. {
  1376. type : 'value',
  1377. splitLine: {show:false},
  1378. axisLabel: {
  1379. show: true,
  1380. textStyle: {
  1381. color: '#fff'
  1382. }
  1383. }
  1384. }
  1385. ],
  1386. series : [
  1387. {
  1388. name:'报警数量',
  1389. type:'bar',
  1390. stack: '总量',
  1391. itemStyle : {
  1392. normal: {
  1393. label : {show: true, position: 'inside'},
  1394. color: '#44aff0'
  1395. }
  1396. },
  1397. data:[2900, 1200, 300, 200]
  1398. }
  1399. ]
  1400. };
  1401. myChart.setOption(option);
  1402. window.addEventListener('resize', function () {myChart.resize();})
  1403. }