生活随笔
收集整理的這篇文章主要介紹了
Echarts地图编写
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.引入echarts庫文件
?
<script charset="utf-8" type="text/javascript" language="javascript" src="echarts-2.2.7/doc/example/www/js/echarts.js"></script> ?
2.在頁面中新建div用于地圖展示
?
<div id="main" style="height: 450px;width: 100%;"></div> ?
3.在頁面中引入js文件
?
<script charset="utf-8" type="text/javascript" language="javascript" src="xxx.js"></script>
4.在js腳本中編寫代碼
?
$(function() { require.config({ paths : { echarts : './plugins/echarts-2.2.7/doc/example/www/js' } }); require( [ 'echarts', 'echarts/chart/map' ], function(ec) { var myChart = ec.init(document.getElementById('main')); var ecConfig = require('echarts/config'); var zrEvent = require('zrender/tool/event'); option = { title : { show: true, text: 'iphone銷量', link: 'http://www.baidu.com', target: 'self', subtext: '純屬虛構', sublink: 'http://www.baidu.com', subtarget: 'self', x: 'center', y: 'top', textAlign: 'center', backgroundColor: 'rgba(0,0,0,0.1)', borderColor: '#66FF00', borderWidth: 1, padding: [20,40,20,40], itemGap: 20, textStyle: { color: '#0066FF', align: 'left', baseline: 'bottom', fontFamily: 'Arial, 宋體, sans-serif', fontSize: 20, fontStyle: 'italic', fontWeight: 'normal' }, subtextStyle: { color: '#FF7F50', align: 'left', baseline: 'bottom', fontFamily: 'Arial, 宋體, sans-serif', fontSize: 15, fontStyle: 'italic', fontWeight: 'normal' } }, tooltip : { show: true, showContent: true, trigger: 'item', showDelay: 0, hideDelay: 0, transitionDuration: 0, backgroundColor: 'rgba(0,0,0,0.5)', borderColor: '#FF7F50', borderRadius: 10, borderWidth: 2, padding: [15,15,15,15], textStyle:{ color: '#FF7F50', align: 'left', baseline: 'bottom', fontFamily: 'Arial, 宋體, sans-serif', fontSize: 20, fontStyle: 'italic', fontWeight: 'normal' } }, legend: { show: true, orient: 'vertical', x: 'left', y: 'top', backgroundColor: 'rgba(0,0,0,0.1)', borderColor: '#0066FF', borderWidth: 1, padding: [15,15,15,15], itemGap: 20, itemWidth: 30, itemHeight: 20, textStyle:{ color: '#FF7F50', align: 'left', baseline: 'bottom', fontFamily: 'Arial, 宋體, sans-serif', fontSize: 20, fontStyle: 'italic', fontWeight: 'normal' }, selectedMode: true, data:[{name:'iphone3' {name:'iphone4' {name:'iphone5' }, dataRange: { show: true, orient: 'horizontal', x: 'left', y: 'bottom', backgroundColor: 'rgba(0,0,0,0.1)', borderColor: '#0066FF', borderWidth: 1, padding: [15,15,15,15], itemGap: 20, itemWidth: 30, itemHeight: 20, min: 0, max: 2500, precision: 1, splitNumber: 10, range: {start: 0, end: 100}, selectedMode: 'multiple', calculable : true, hoverLink: true, realtime:true, color:['#e42515','#fad3d0'], text:['高','低'], textStyle:{ color: '#FF7F50', align: 'left', baseline: 'bottom', fontFamily: 'Arial, 宋體, sans-serif', fontSize: 20, fontStyle: 'italic', fontWeight: 'normal' } }, toolbox: { show: true, orient : 'horizontal', x: 'right', y: 'bottom', backgroundColor: 'rgba(218,112,214,0.6)', borderColor: '#0066FF', borderWidth: 1, padding: [15,15,15,15], itemGap: 20, itemSize: 20, color:['#1e90ff','#22bb22','#4b0082','#d2691e'], disableColor:'#fff', effectiveColor:'red', showTitle:true, textStyle:{ color: '#FF7F50', align: 'left', baseline: 'bottom', fontFamily: 'Arial, 宋體, sans-serif', fontSize: 20, fontStyle: 'italic', fontWeight: 'normal' }, feature : { mark : { show : true, title : { mark : '輔助線開關', markUndo : '刪除輔助線', markClear : '清空輔助線' }, lineStyle : { width : 2, color : '#1e90ff', type : 'dashed' } }, dataZoom : { show : true, title : { dataZoom : '區域縮放', dataZoomReset : '區域縮放后退' } }, dataView : { show : true, title : '數據視圖', readOnly: false, lang: ['數據視圖', '關閉', '刷新'] }, magicType: { show : true, title : { line : '折線圖切換', bar : '柱形圖切換', stack : '堆積', tiled : '平鋪', force: '力導向布局圖切換', chord: '和弦圖切換', pie: '餅圖切換', funnel: '漏斗圖切換' }, option: { }, type : [] }, restore : { show : true, title : '還原' }, saveAsImage : { show : true, title : '保存為圖片', type : 'png', lang : ['點擊保存'] } } }, roamController: { show: true, x: 'right', y: 'top', width: 120, height:200, backgroundColor:'rgba(0,0,0,0.1)', borderColor: '#1e90ff', borderWidth: 1, padding: [15,15,15,15], fillerColor:'#000', handleColor:'#e3655a', step:10, mapTypeControl: { 'china': true } }, series : [ { type: 'map', name: 'iphone3', mapType: 'china', roam: false, itemStyle:{ normal:{label:{show:true}}, emphasis:{label:{show:true}} }, data:[ {name: '北京',value: Math.round(Math.random()*1000)}, {name: '天津',value: Math.round(Math.random()*1000)}, {name: '上海',value: Math.round(Math.random()*1000)}, {name: '重慶',value: Math.round(Math.random()*1000)}, {name: '河北',value: Math.round(Math.random()*1000)}, {name: '河南',value: Math.round(Math.random()*1000)}, {name: '云南',value: Math.round(Math.random()*1000)}, {name: '遼寧',value: Math.round(Math.random()*1000)}, {name: '黑龍江',value: Math.round(Math.random()*1000)}, {name: '湖南',value: Math.round(Math.random()*1000)}, {name: '安徽',value: Math.round(Math.random()*1000)}, {name: '山東',value: Math.round(Math.random()*1000)}, {name: '新疆',value: Math.round(Math.random()*1000)}, {name: '江蘇',value: Math.round(Math.random()*1000)}, {name: '浙江',value: Math.round(Math.random()*1000)}, {name: '江西',value: Math.round(Math.random()*1000)}, {name: '湖北',value: Math.round(Math.random()*1000)}, {name: '廣西',value: Math.round(Math.random()*1000)}, {name: '甘肅',value: Math.round(Math.random()*1000)}, {name: '山西',value: Math.round(Math.random()*1000)}, {name: '內蒙古',value: Math.round(Math.random()*1000)}, {name: '陜西',value: Math.round(Math.random()*1000)}, {name: '吉林',value: Math.round(Math.random()*1000)}, {name: '福建',value: Math.round(Math.random()*1000)}, {name: '貴州',value: Math.round(Math.random()*1000)}, {name: '廣東',value: Math.round(Math.random()*1000)}, {name: '青海',value: Math.round(Math.random()*1000)}, {name: '西藏',value: Math.round(Math.random()*1000)}, {name: '四川',value: Math.round(Math.random()*1000)}, {name: '寧夏',value: Math.round(Math.random()*1000)}, {name: '海南',value: Math.round(Math.random()*1000)}, {name: '臺灣',value: Math.round(Math.random()*1000)}, {name: '香港',value: Math.round(Math.random()*1000)}, {name: '澳門',value: Math.round(Math.random()*1000)} ] }, { name: 'iphone4', type: 'map', mapType: 'china', itemStyle:{ normal:{label:{show:true}}, emphasis:{label:{show:true}} }, data:[ {name: '北京',value: Math.round(Math.random()*1000)}, {name: '天津',value: Math.round(Math.random()*1000)}, {name: '上海',value: Math.round(Math.random()*1000)}, {name: '重慶',value: Math.round(Math.random()*1000)}, {name: '河北',value: Math.round(Math.random()*1000)}, {name: '安徽',value: Math.round(Math.random()*1000)}, {name: '新疆',value: Math.round(Math.random()*1000)}, {name: '浙江',value: Math.round(Math.random()*1000)}, {name: '江西',value: Math.round(Math.random()*1000)}, {name: '山西',value: Math.round(Math.random()*1000)}, {name: '內蒙古',value: Math.round(Math.random()*1000)}, {name: '吉林',value: Math.round(Math.random()*1000)}, {name: '福建',value: Math.round(Math.random()*1000)}, {name: '廣東',value: Math.round(Math.random()*1000)}, {name: '西藏',value: Math.round(Math.random()*1000)}, {name: '四川',value: Math.round(Math.random()*1000)}, {name: '寧夏',value: Math.round(Math.random()*1000)}, {name: '香港',value: Math.round(Math.random()*1000)}, {name: '澳門',value: Math.round(Math.random()*1000)} ] }, { name: 'iphone5', type: 'map', mapType: 'china', itemStyle:{ normal:{label:{show:true}}, emphasis:{label:{show:true}} }, data:[ {name: '北京',value: Math.round(Math.random()*1000)}, {name: '天津',value: Math.round(Math.random()*1000)}, {name: '上海',value: Math.round(Math.random()*1000)}, {name: '廣東',value: Math.round(Math.random()*1000)}, {name: '臺灣',value: Math.round(Math.random()*1000)}, {name: '香港',value: Math.round(Math.random()*1000)}, {name: '澳門',value: Math.round(Math.random()*1000)} ] } ] }; myChart.setOption(option); }); }); ?
5.最終結果
轉載于:https://www.cnblogs.com/HeXiaoZhou/p/9399525.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的Echarts地图编写的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。