ECharts的二次封装

ECharts的二次封装

封装的意义:ECharts的二次封装有利于项目后期的维护和使用

目录:

  1. 封装初始化代码
  2. 调用方式
  3. 折线图 1
  4. 折线图 2
  5. 散点图 1
  6. 散点图 2
  7. 散点图 3
  8. 条形图 1
  9. 条形图 2
  10. 条形图和折线图
  11. 极坐标图和折线图
  12. 极坐标条形图
  13. 双轴图
  14. 北京地图
  15. 全国地图
  16. 全国地图发光效果
  17. 全国地图突出北京
  18. 热力图
  19. 环形图
  20. 象形柱图
  21. 路线图
  22. 雷达图

一、封装初始化代码

  • 创建一个 echarts.js 文件(写入初始化代码)
import echarts from 'echarts';

const echartsInstall = function (Vue) {
// Vue.prototype 把实例挂在到 Vue 的原型上 方便全局使用
  Object.defineProperties(Vue.prototype, {
    $myecharts: {
      get() {
        return {
          // 折线图 案例
          line(id) {
            const dom = document.getElementById(id);
            const myCharts = echarts.init(dom);
            // 折线图相关配置写在这里
            const option = {
            	// 例子
            	xAxis: {
                	type: 'category',
                	data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
              	},
              	yAxis: {
                	type: 'value',
              	},
              	series: [{
                	data: [150, 230, 224, 218, 135, 147, 260],
                	type: 'line',
              	}],
            };
            myCharts.setOption(option);
          },
          // 地图案例
          chinaMap(id) {
            const dom = document.getElementById(id);
            const myCharts = echarts.init(dom);
            // 地图相关配置写在这里
            const option = {
            };
            myCharts.setOption(option);
          },
        };
      },
    },
  });
};
export default echartsInstall;
  • 调用方式
    (1)在main.js根目录中引入二次封装的插件
    ECharts的二次封装_第1张图片
    (2)使用自己二次封装的插件
    在这里插入图片描述
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/6da5d60dfa83439b9f131cd02734ecde.png

ECharts的二次封装_第2张图片
(3)!!!记得给你创建的标签一个宽度和高度不然会显示不出来
ECharts的二次封装_第3张图片

  • 折线图 1
<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
    <title>特效折线图</title>
    <style>
        #container {
            width: 1000px;
            height: 800px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    var data = [{
        value: 0,
        count: 35,
        year: '2013年',
    }, {
        value: 6,
        count: 29,
        year: '2014年',
    }, {
        value: 6,
        count: 29,
        year: '2015年',
    }, {
        value: 10,
        count: 25,
        year: '2016年',
    }, {
        value: 13,
        count: 22,
        year: '2017年',

    }, {
        value: 18,
        count: 17,
        year: '2018年',
    }, {
        value: 28,
        count: '',
        year: '',
        symbol: 'image://../img/ding1.png',
    }]

	// 把对应 echarts 图行的 option 复制到我们封装的 插件中就可以
    var option = {
        backgroundColor: '#404a59', //整体背景
        //直角坐标系
        grid: {
            left: '2%', //坐标系到左边的距离
            right: '2%',
            top: '5%',
            bottom: '10%',
        },
        xAxis: {
            data: [],
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            splitArea: {
                show: false
            },
            splitLine: {
                show: false
            },
        },
        yAxis: {
            splitLine: {
                show: false
            },
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            splitArea: {
                show: false
            },
            data: []
        },
        series: [
            {
                name: '特效折线图',
                type: 'line',
                showAllSymbol: true, //显示所有图形
                symbol: 'image://../img/ding.png',
                symbolSize: 30,
                label: { //图形上的文本标签
                    show: true,
                    position: 'top',
                    formatter: function (e) {
                        return e.data.count
                    },
                    offset: [0, -15], //偏移量
                    textStyle: {
                        color: '#fff',
                        fontSize: 16,
                    }
                },
                lineStyle: { //线条样式。
                    width: 10,
                    color: '#268b87'
                },
                data: data,
                zlevel: 10,
                animationDuration: 2000
            },
            {
                name: '',
                type: 'line',
                showAllSymbol: true, //显示所有图形
                symbolSize:0.1,
                label: { //图形上的文本标签
                    show: true,
                    position: 'bottom',
                    formatter: function (e) {
                        return e.data.year
                    },
                    offset: [0, 30],    //偏移量
                    textStyle: {
                        color: '#fff',
                        fontSize: 16,
                    }
                },
                lineStyle: { //线条样式。
                    opacity:0
                },
                data: data,
                zlevel: 1,
                animationDuration: 2000
            },
        ],
    };
    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }
</script>

</html>
  • 折线图 2
<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
    <title>特效折线图</title>
    <style>
        #container {
            width: 1000px;
            height: 800px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    var data = [{
        value: 0,
        count: 35,
        year: '2013年',
    }, {
        value: 6,
        count: 29,
        year: '2014年',
    }, {
        value: 6,
        count: 29,
        year: '2015年',
    }, {
        value: 10,
        count: 25,
        year: '2016年',
    }, {
        value: 13,
        count: 22,
        year: '2017年',

    }, {
        value: 18,
        count: 17,
        year: '2018年',
    }, {
        value: 28,
        count: '',
        year: '',
        symbol: 'image://../img/ding1.png',
    }]

    var option = {
        backgroundColor: '#404a59', //整体背景
        //直角坐标系
        grid: {
            left: '2%', //坐标系到左边的距离
            right: '2%',
            top: '5%',
            bottom: '10%',
        },
        xAxis: {
            data: [],
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            splitArea: {
                show: false
            },
            splitLine: {
                show: false
            },
        },
        yAxis: {
            splitLine: {
                show: false
            },
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            splitArea: {
                show: false
            },
            data: []
        },
        series: [
            {
                name: '特效折线图',
                type: 'line',
                showAllSymbol: true, //显示所有图形
                symbol: 'image://../img/ding.png',
                symbolSize: 30,
                label: { //图形上的文本标签
                    show: true,
                    position: 'top',
                    formatter: function (e) {
                        return e.data.count
                    },
                    offset: [0, -15], //偏移量
                    textStyle: {
                        color: '#fff',
                        fontSize: 16,
                    }
                },
                lineStyle: { //线条样式。
                    width: 10,
                    color: '#268b87'
                },
                data: data,
                zlevel: 10,
                animationDuration: 2000
            },
            {
                name: '',
                type: 'line',
                showAllSymbol: true, //显示所有图形
                symbolSize:0.1,
                label: { //图形上的文本标签
                    show: true,
                    position: 'bottom',
                    formatter: function (e) {
                        return e.data.year
                    },
                    offset: [0, 30],    //偏移量
                    textStyle: {
                        color: '#fff',
                        fontSize: 16,
                    }
                },
                lineStyle: { //线条样式。
                    opacity:0
                },
                data: data,
                zlevel: 1,
                animationDuration: 2000
            },
        ],
    };
    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }
</script>

</html>
  • 散点图 1
<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
    <title>散点图1</title>
    <style>
        #container {
            width: 1000px;
            height: 800px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script src="../script/map/china.js"></script>
<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var app = {};
    var data = [
        {
            name: '海门',
            value: 9
        },
        {
            name: '鄂尔多斯',
            value: 12
        },
        {
            name: '招远',
            value: 12
        },
        {
            name: '舟山',
            value: 12
        },
        {
            name: '齐齐哈尔',
            value: 14
        },
        {
            name: '盐城',
            value: 15
        },
        {
            name: '赤峰',
            value: 16
        },
        {
            name: '青岛',
            value: 18
        },
        {
            name: '乳山',
            value: 18
        },
        {
            name: '金昌',
            value: 19
        },
        {
            name: '泉州',
            value: 21
        },
        {
            name: '莱西',
            value: 21
        },
        {
            name: '日照',
            value: 21
        },
        {
            name: '胶南',
            value: 22
        },
        {
            name: '南通',
            value: 23
        },
        {
            name: '拉萨',
            value: 24
        },
        {
            name: '云浮',
            value: 24
        },
        {
            name: '梅州',
            value: 25
        },
        {
            name: '文登',
            value: 25
        },
        {
            name: '上海',
            value: 25
        },
        {
            name: '攀枝花',
            value: 25
        },
        {
            name: '威海',
            value: 25
        },
        {
            name: '承德',
            value: 25
        },
        {
            name: '厦门',
            value: 26
        },
        {
            name: '汕尾',
            value: 26
        },
        {
            name: '潮州',
            value: 26
        },
        {
            name: '丹东',
            value: 27
        },
        {
            name: '太仓',
            value: 27
        },
        {
            name: '曲靖',
            value: 27
        },
        {
            name: '烟台',
            value: 28
        },
        {
            name: '福州',
            value: 29
        },
        {
            name: '瓦房店',
            value: 30
        },
        {
            name: '即墨',
            value: 30
        },
        {
            name: '抚顺',
            value: 31
        },
        {
            name: '玉溪',
            value: 31
        },
        {
            name: '张家口',
            value: 31
        },
        {
            name: '阳泉',
            value: 31
        },
        {
            name: '莱州',
            value: 32
        },
        {
            name: '湖州',
            value: 32
        },
        {
            name: '汕头',
            value: 32
        },
        {
            name: '昆山',
            value: 33
        },
        {
            name: '宁波',
            value: 33
        },
        {
            name: '湛江',
            value: 33
        },
        {
            name: '揭阳',
            value: 34
        },
        {
            name: '荣成',
            value: 34
        },
        {
            name: '连云港',
            value: 35
        },
        {
            name: '葫芦岛',
            value: 35
        },
        {
            name: '常熟',
            value: 36
        },
        {
            name: '东莞',
            value: 36
        },
        {
            name: '河源',
            value: 36
        },
        {
            name: '淮安',
            value: 36
        },
        {
            name: '泰州',
            value: 36
        },
        {
            name: '南宁',
            value: 37
        },
        {
            name: '营口',
            value: 37
        },
        {
            name: '惠州',
            value: 37
        },
        {
            name: '江阴',
            value: 37
        },
        {
            name: '蓬莱',
            value: 37
        },
        {
            name: '韶关',
            value: 38
        },
        {
            name: '嘉峪关',
            value: 38
        },
        {
            name: '广州',
            value: 38
        },
        {
            name: '延安',
            value: 38
        },
        {
            name: '太原',
            value: 39
        },
        {
            name: '清远',
            value: 39
        },
        {
            name: '中山',
            value: 39
        },
        {
            name: '昆明',
            value: 39
        },
        {
            name: '寿光',
            value: 40
        },
        {
            name: '盘锦',
            value: 40
        },
        {
            name: '长治',
            value: 41
        },
        {
            name: '深圳',
            value: 41
        },
        {
            name: '珠海',
            value: 42
        },
        {
            name: '宿迁',
            value: 43
        },
        {
            name: '咸阳',
            value: 43
        },
        {
            name: '铜川',
            value: 44
        },
        {
            name: '平度',
            value: 44
        },
        {
            name: '佛山',
            value: 44
        },
        {
            name: '海口',
            value: 44
        },
        {
            name: '江门',
            value: 45
        },
        {
            name: '章丘',
            value: 45
        },
        {
            name: '肇庆',
            value: 46
        },
        {
            name: '大连',
            value: 47
        },
        {
            name: '临汾',
            value: 47
        },
        {
            name: '吴江',
            value: 47
        },
        {
            name: '石嘴山',
            value: 49
        },
        {
            name: '沈阳',
            value: 50
        },
        {
            name: '苏州',
            value: 50
        },
        {
            name: '茂名',
            value: 50
        },
        {
            name: '嘉兴',
            value: 51
        },
        {
            name: '长春',
            value: 51
        },
        {
            name: '胶州',
            value: 52
        },
        {
            name: '银川',
            value: 52
        },
        {
            name: '张家港',
            value: 52
        },
        {
            name: '三门峡',
            value: 53
        },
        {
            name: '锦州',
            value: 54
        },
        {
            name: '南昌',
            value: 54
        },
        {
            name: '柳州',
            value: 54
        },
        {
            name: '三亚',
            value: 54
        },
        {
            name: '自贡',
            value: 56
        },
        {
            name: '吉林',
            value: 56
        },
        {
            name: '阳江',
            value: 57
        },
        {
            name: '泸州',
            value: 57
        },
        {
            name: '西宁',
            value: 57
        },
        {
            name: '宜宾',
            value: 58
        },
        {
            name: '呼和浩特',
            value: 58
        },
        {
            name: '成都',
            value: 58
        },
        {
            name: '大同',
            value: 58
        },
        {
            name: '镇江',
            value: 59
        },
        {
            name: '桂林',
            value: 59
        },
        {
            name: '张家界',
            value: 59
        },
        {
            name: '宜兴',
            value: 59
        },
        {
            name: '北海',
            value: 60
        },
        {
            name: '西安',
            value: 61
        },
        {
            name: '金坛',
            value: 62
        },
        {
            name: '东营',
            value: 62
        },
        {
            name: '牡丹江',
            value: 63
        },
        {
            name: '遵义',
            value: 63
        },
        {
            name: '绍兴',
            value: 63
        },
        {
            name: '扬州',
            value: 64
        },
        {
            name: '常州',
            value: 64
        },
        {
            name: '潍坊',
            value: 65
        },
        {
            name: '重庆',
            value: 66
        },
        {
            name: '台州',
            value: 67
        },
        {
            name: '南京',
            value: 67
        },
        {
            name: '滨州',
            value: 70
        },
        {
            name: '贵阳',
            value: 71
        },
        {
            name: '无锡',
            value: 71
        },
        {
            name: '本溪',
            value: 71
        },
        {
            name: '克拉玛依',
            value: 72
        },
        {
            name: '渭南',
            value: 72
        },
        {
            name: '马鞍山',
            value: 72
        },
        {
            name: '宝鸡',
            value: 72
        },
        {
            name: '焦作',
            value: 75
        },
        {
            name: '句容',
            value: 75
        },
        {
            name: '北京',
            value: 79
        },
        {
            name: '徐州',
            value: 79
        },
        {
            name: '衡水',
            value: 80
        },
        {
            name: '包头',
            value: 80
        },
        {
            name: '绵阳',
            value: 80
        },
        {
            name: '乌鲁木齐',
            value: 84
        },
        {
            name: '枣庄',
            value: 84
        },
        {
            name: '杭州',
            value: 84
        },
        {
            name: '淄博',
            value: 85
        },
        {
            name: '鞍山',
            value: 86
        },
        {
            name: '溧阳',
            value: 86
        },
        {
            name: '库尔勒',
            value: 86
        },
        {
            name: '安阳',
            value: 90
        },
        {
            name: '开封',
            value: 90
        },
        {
            name: '济南',
            value: 92
        },
        {
            name: '德阳',
            value: 93
        },
        {
            name: '温州',
            value: 95
        },
        {
            name: '九江',
            value: 96
        },
        {
            name: '邯郸',
            value: 98
        },
        {
            name: '临安',
            value: 99
        },
        {
            name: '兰州',
            value: 99
        },
        {
            name: '沧州',
            value: 100
        },
        {
            name: '临沂',
            value: 103
        },
        {
            name: '南充',
            value: 104
        },
        {
            name: '天津',
            value: 105
        },
        {
            name: '富阳',
            value: 106
        },
        {
            name: '泰安',
            value: 112
        },
        {
            name: '诸暨',
            value: 112
        },
        {
            name: '郑州',
            value: 113
        },
        {
            name: '哈尔滨',
            value: 114
        },
        {
            name: '聊城',
            value: 116
        },
        {
            name: '芜湖',
            value: 117
        },
        {
            name: '唐山',
            value: 119
        },
        {
            name: '平顶山',
            value: 119
        },
        {
            name: '邢台',
            value: 119
        },
        {
            name: '德州',
            value: 120
        },
        {
            name: '济宁',
            value: 120
        },
        {
            name: '荆州',
            value: 127
        },
        {
            name: '宜昌',
            value: 130
        },
        {
            name: '义乌',
            value: 132
        },
        {
            name: '丽水',
            value: 133
        },
        {
            name: '洛阳',
            value: 134
        },
        {
            name: '秦皇岛',
            value: 136
        },
        {
            name: '株洲',
            value: 143
        },
        {
            name: '石家庄',
            value: 147
        },
        {
            name: '莱芜',
            value: 148
        },
        {
            name: '常德',
            value: 152
        },
        {
            name: '保定',
            value: 153
        },
        {
            name: '湘潭',
            value: 154
        },
        {
            name: '金华',
            value: 157
        },
        {
            name: '岳阳',
            value: 169
        },
        {
            name: '长沙',
            value: 175
        },
        {
            name: '衢州',
            value: 177
        },
        {
            name: '廊坊',
            value: 193
        },
        {
            name: '菏泽',
            value: 194
        },
        {
            name: '合肥',
            value: 229
        },
        {
            name: '武汉',
            value: 273
        },
        {
            name: '大庆',
            value: 279
        }
    ];
    var geoCoordMap = {
        '海门': [121.15, 31.89],
        '鄂尔多斯': [109.781327, 39.608266],
        '招远': [120.38, 37.35],
        '舟山': [122.207216, 29.985295],
        '齐齐哈尔': [123.97, 47.33],
        '盐城': [120.13, 33.38],
        '赤峰': [118.87, 42.28],
        '青岛': [120.33, 36.07],
        '乳山': [121.52, 36.89],
        '金昌': [102.188043, 38.520089],
        '泉州': [118.58, 24.93],
        '莱西': [120.53, 36.86],
        '日照': [119.46, 35.42],
        '胶南': [119.97, 35.88],
        '南通': [121.05, 32.08],
        '拉萨': [91.11, 29.97],
        '云浮': [112.02, 22.93],
        '梅州': [116.1, 24.55],
        '文登': [122.05, 37.2],
        '上海': [121.48, 31.22],
        '攀枝花': [101.718637, 26.582347],
        '威海': [122.1, 37.5],
        '承德': [117.93, 40.97],
        '厦门': [118.1, 24.46],
        '汕尾': [115.375279, 22.786211],
        '潮州': [116.63, 23.68],
        '丹东': [124.37, 40.13],
        '太仓': [121.1, 31.45],
        '曲靖': [103.79, 25.51],
        '烟台': [121.39, 37.52],
        '福州': [119.3, 26.08],
        '瓦房店': [121.979603, 39.627114],
        '即墨': [120.45, 36.38],
        '抚顺': [123.97, 41.97],
        '玉溪': [102.52, 24.35],
        '张家口': [114.87, 40.82],
        '阳泉': [113.57, 37.85],
        '莱州': [119.942327, 37.177017],
        '湖州': [120.1, 30.86],
        '汕头': [116.69, 23.39],
        '昆山': [120.95, 31.39],
        '宁波': [121.56, 29.86],
        '湛江': [110.359377, 21.270708],
        '揭阳': [116.35, 23.55],
        '荣成': [122.41, 37.16],
        '连云港': [119.16, 34.59],
        '葫芦岛': [120.836932, 40.711052],
        '常熟': [120.74, 31.64],
        '东莞': [113.75, 23.04],
        '河源': [114.68, 23.73],
        '淮安': [119.15, 33.5],
        '泰州': [119.9, 32.49],
        '南宁': [108.33, 22.84],
        '营口': [122.18, 40.65],
        '惠州': [114.4, 23.09],
        '江阴': [120.26, 31.91],
        '蓬莱': [120.75, 37.8],
        '韶关': [113.62, 24.84],
        '嘉峪关': [98.289152, 39.77313],
        '广州': [113.23, 23.16],
        '延安': [109.47, 36.6],
        '太原': [112.53, 37.87],
        '清远': [113.01, 23.7],
        '中山': [113.38, 22.52],
        '昆明': [102.73, 25.04],
        '寿光': [118.73, 36.86],
        '盘锦': [122.070714, 41.119997],
        '长治': [113.08, 36.18],
        '深圳': [114.07, 22.62],
        '珠海': [113.52, 22.3],
        '宿迁': [118.3, 33.96],
        '咸阳': [108.72, 34.36],
        '铜川': [109.11, 35.09],
        '平度': [119.97, 36.77],
        '佛山': [113.11, 23.05],
        '海口': [110.35, 20.02],
        '江门': [113.06, 22.61],
        '章丘': [117.53, 36.72],
        '肇庆': [112.44, 23.05],
        '大连': [121.62, 38.92],
        '临汾': [111.5, 36.08],
        '吴江': [120.63, 31.16],
        '石嘴山': [106.39, 39.04],
        '沈阳': [123.38, 41.8],
        '苏州': [120.62, 31.32],
        '茂名': [110.88, 21.68],
        '嘉兴': [120.76, 30.77],
        '长春': [125.35, 43.88],
        '胶州': [120.03336, 36.264622],
        '银川': [106.27, 38.47],
        '张家港': [120.555821, 31.875428],
        '三门峡': [111.19, 34.76],
        '锦州': [121.15, 41.13],
        '南昌': [115.89, 28.68],
        '柳州': [109.4, 24.33],
        '三亚': [109.511909, 18.252847],
        '自贡': [104.778442, 29.33903],
        '吉林': [126.57, 43.87],
        '阳江': [111.95, 21.85],
        '泸州': [105.39, 28.91],
        '西宁': [101.74, 36.56],
        '宜宾': [104.56, 29.77],
        '呼和浩特': [111.65, 40.82],
        '成都': [104.06, 30.67],
        '大同': [113.3, 40.12],
        '镇江': [119.44, 32.2],
        '桂林': [110.28, 25.29],
        '张家界': [110.479191, 29.117096],
        '宜兴': [119.82, 31.36],
        '北海': [109.12, 21.49],
        '西安': [108.95, 34.27],
        '金坛': [119.56, 31.74],
        '东营': [118.49, 37.46],
        '牡丹江': [129.58, 44.6],
        '遵义': [106.9, 27.7],
        '绍兴': [120.58, 30.01],
        '扬州': [119.42, 32.39],
        '常州': [119.95, 31.79],
        '潍坊': [119.1, 36.62],
        '重庆': [106.54, 29.59],
        '台州': [121.420757, 28.656386],
        '南京': [118.78, 32.04],
        '滨州': [118.03, 37.36],
        '贵阳': [106.71, 26.57],
        '无锡': [120.29, 31.59],
        '本溪': [123.73, 41.3],
        '克拉玛依': [84.77, 45.59],
        '渭南': [109.5, 34.52],
        '马鞍山': [118.48, 31.56],
        '宝鸡': [107.15, 34.38],
        '焦作': [113.21, 35.24],
        '句容': [119.16, 31.95],
        '北京': [116.46, 39.92],
        '徐州': [117.2, 34.26],
        '衡水': [115.72, 37.72],
        '包头': [110, 40.58],
        '绵阳': [104.73, 31.48],
        '乌鲁木齐': [87.68, 43.77],
        '枣庄': [117.57, 34.86],
        '杭州': [120.19, 30.26],
        '淄博': [118.05, 36.78],
        '鞍山': [122.85, 41.12],
        '溧阳': [119.48, 31.43],
        '库尔勒': [86.06, 41.68],
        '安阳': [114.35, 36.1],
        '开封': [114.35, 34.79],
        '济南': [117, 36.65],
        '德阳': [104.37, 31.13],
        '温州': [120.65, 28.01],
        '九江': [115.97, 29.71],
        '邯郸': [114.47, 36.6],
        '临安': [119.72, 30.23],
        '兰州': [103.73, 36.03],
        '沧州': [116.83, 38.33],
        '临沂': [118.35, 35.05],
        '南充': [106.110698, 30.837793],
        '天津': [117.2, 39.13],
        '富阳': [119.95, 30.07],
        '泰安': [117.13, 36.18],
        '诸暨': [120.23, 29.71],
        '郑州': [113.65, 34.76],
        '哈尔滨': [126.63, 45.75],
        '聊城': [115.97, 36.45],
        '芜湖': [118.38, 31.33],
        '唐山': [118.02, 39.63],
        '平顶山': [113.29, 33.75],
        '邢台': [114.48, 37.05],
        '德州': [116.29, 37.45],
        '济宁': [116.59, 35.38],
        '荆州': [112.239741, 30.335165],
        '宜昌': [111.3, 30.7],
        '义乌': [120.06, 29.32],
        '丽水': [119.92, 28.45],
        '洛阳': [112.44, 34.7],
        '秦皇岛': [119.57, 39.95],
        '株洲': [113.16, 27.83],
        '石家庄': [114.48, 38.03],
        '莱芜': [117.67, 36.19],
        '常德': [111.69, 29.05],
        '保定': [115.48, 38.85],
        '湘潭': [112.91, 27.87],
        '金华': [119.64, 29.12],
        '岳阳': [113.09, 29.37],
        '长沙': [113, 28.21],
        '衢州': [118.88, 28.97],
        '廊坊': [116.7, 39.53],
        '菏泽': [115.480656, 35.23375],
        '合肥': [117.27, 31.86],
        '武汉': [114.31, 30.52],
        '大庆': [125.03, 46.58]
    };

    var convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            } else {
                console.log(data[i].name)
            }
        }
        return res;
    };

    var option = {
        backgroundColor: '#404a59', //整体背景
        title: { //标题
            text: '创客天下',
            subtext: '创客天下发展城市',
            left: 'center',
            textStyle: {
                color: '#fff'
            }
        },
        legend: { //导航
            orient: 'vertical',
            y: 'bottom',
            x: 'right',
            data: ['创客城市', 'Top 5'], //必须与series一一对应
            textStyle: {
                color: '#fff'
            }
        },
        geo: {
            map: 'china', //中国地图
            label: { //控制省份名
                normal: { //正常模式
                    show: false,
                },
                emphasis: { //hover模式
                    show: false,
                }
            },
            roam: false, //是否开启平移和缩放
            zoom: 1.2,
            itemStyle: { //控制省份区域(省份块)
                normal: {
                    areaColor: '#323c48',
                    borderColor: '#111',
                },
                emphasis: {
                    areaColor: '#2a333d'
                }
            }
        },
        tooltip: { //提示框组件。 hover导航框
            trigger: 'item',
            //            formatter: (data)=>{        //导航框内容  可以写标签哦!!!
            //                console.log(data)
            //                return  '
123
'
// } }, series: [{ name: '创客城市', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 data: convertData(data), symbolSize: function (val) { return val[2] / 15; }, label: { //每个点的信息 normal: { formatter: '{b}', position: 'right', show: false, textStyle: { color: '#9ba0aa', fontFamily: '微软雅黑' } }, emphasis: { show: true } }, itemStyle: { normal: { color: '#ddb926' //圆点颜色 } } }, { name: 'Top 5', type: 'effectScatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 data: convertData(data.sort(function (a, b) { return b.value - a.value; }).slice(0, 6)), symbolSize: function (val) { return val[2] / 10; }, effectType: 'ripple', //特效类型,目前只支持涟漪特效'ripple'。 showEffectOn: 'render', //配置何时显示特效。'render' 绘制完成后显示特效。 rippleEffect: { //涟漪特效相关配置。 brushType: 'stroke' }, hoverAnimation: true, label: { normal: { formatter: '{b}', position: 'right', show: true } }, itemStyle: { normal: { color: '#f4e925', shadowBlur: 10, shadowColor: '#333' } }, markLine: { label: { normal: { show: true } }, lineStyle: { normal: { color: '#fdc57f', width: 2, type: 'solid' } }, data: [ [{ name: '北京到上海', coord: geoCoordMap['北京'] }, { coord: geoCoordMap['上海'] } ], [{ name: '武汉到原点', coord: geoCoordMap['武汉'] }, { x: 0, y: 0 } ], ] }, zlevel: 1 } ] }; if (option && typeof option === "object") { myChart.setOption(option, true); } </script> </html>
  • 散点图 2
<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>散点图2</title>
    <style>
        #container{
            width: 950px;
            height: 680px;
        }
    </style>

</head>
<body>
<div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script src="../script/map/china.js"></script>
<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var data = [
        {name: '海门', value: 9},
        {name: '鄂尔多斯', value: 12},
        {name: '招远', value: 12},
        {name: '舟山', value: 12},
        {name: '齐齐哈尔', value: 14},
        {name: '盐城', value: 15},
        {name: '赤峰', value: 16},
        {name: '青岛', value: 18},
        {name: '乳山', value: 18},
        {name: '金昌', value: 19},
        {name: '泉州', value: 21},
        {name: '莱西', value: 21},
        {name: '日照', value: 21},
        {name: '胶南', value: 22},
        {name: '南通', value: 23},
        {name: '拉萨', value: 24},
        {name: '云浮', value: 24},
        {name: '梅州', value: 25},
        {name: '文登', value: 25},
        {name: '上海', value: 25},
        {name: '攀枝花', value: 25},
        {name: '威海', value: 25},
        {name: '承德', value: 25},
        {name: '厦门', value: 26},
        {name: '汕尾', value: 26},
        {name: '潮州', value: 26},
        {name: '丹东', value: 27},
        {name: '太仓', value: 27},
        {name: '曲靖', value: 27},
        {name: '烟台', value: 28},
        {name: '福州', value: 29},
        {name: '瓦房店', value: 30},
        {name: '即墨', value: 30},
        {name: '抚顺', value: 31},
        {name: '玉溪', value: 31},
        {name: '张家口', value: 31},
        {name: '阳泉', value: 31},
        {name: '莱州', value: 32},
        {name: '湖州', value: 32},
        {name: '汕头', value: 32},
        {name: '昆山', value: 33},
        {name: '宁波', value: 33},
        {name: '湛江', value: 33},
        {name: '揭阳', value: 34},
        {name: '荣成', value: 34},
        {name: '连云港', value: 35},
        {name: '葫芦岛', value: 35},
        {name: '常熟', value: 36},
        {name: '东莞', value: 36},
        {name: '河源', value: 36},
        {name: '淮安', value: 36},
        {name: '泰州', value: 36},
        {name: '南宁', value: 37},
        {name: '营口', value: 37},
        {name: '惠州', value: 37},
        {name: '江阴', value: 37},
        {name: '蓬莱', value: 37},
        {name: '韶关', value: 38},
        {name: '嘉峪关', value: 38},
        {name: '广州', value: 38},
        {name: '延安', value: 38},
        {name: '太原', value: 39},
        {name: '清远', value: 39},
        {name: '中山', value: 39},
        {name: '昆明', value: 39},
        {name: '寿光', value: 40},
        {name: '盘锦', value: 40},
        {name: '长治', value: 41},
        {name: '深圳', value: 41},
        {name: '珠海', value: 42},
        {name: '宿迁', value: 43},
        {name: '咸阳', value: 43},
        {name: '铜川', value: 44},
        {name: '平度', value: 44},
        {name: '佛山', value: 44},
        {name: '海口', value: 44},
        {name: '江门', value: 45},
        {name: '章丘', value: 45},
        {name: '肇庆', value: 46},
        {name: '大连', value: 47},
        {name: '临汾', value: 47},
        {name: '吴江', value: 47},
        {name: '石嘴山', value: 49},
        {name: '沈阳', value: 50},
        {name: '苏州', value: 50},
        {name: '茂名', value: 50},
        {name: '嘉兴', value: 51},
        {name: '长春', value: 51},
        {name: '胶州', value: 52},
        {name: '银川', value: 52},
        {name: '张家港', value: 52},
        {name: '三门峡', value: 53},
        {name: '锦州', value: 54},
        {name: '南昌', value: 54},
        {name: '柳州', value: 54},
        {name: '三亚', value: 54},
        {name: '自贡', value: 56},
        {name: '吉林', value: 56},
        {name: '阳江', value: 57},
        {name: '泸州', value: 57},
        {name: '西宁', value: 57},
        {name: '宜宾', value: 58},
        {name: '呼和浩特', value: 58},
        {name: '成都', value: 58},
        {name: '大同', value: 58},
        {name: '镇江', value: 59},
        {name: '桂林', value: 59},
        {name: '张家界', value: 59},
        {name: '宜兴', value: 59},
        {name: '北海', value: 60},
        {name: '西安', value: 61},
        {name: '金坛', value: 62},
        {name: '东营', value: 62},
        {name: '牡丹江', value: 63},
        {name: '遵义', value: 63},
        {name: '绍兴', value: 63},
        {name: '扬州', value: 64},
        {name: '常州', value: 64},
        {name: '潍坊', value: 65},
        {name: '重庆', value: 66},
        {name: '台州', value: 67},
        {name: '南京', value: 67},
        {name: '滨州', value: 70},
        {name: '贵阳', value: 71},
        {name: '无锡', value: 71},
        {name: '本溪', value: 71},
        {name: '克拉玛依', value: 72},
        {name: '渭南', value: 72},
        {name: '马鞍山', value: 72},
        {name: '宝鸡', value: 72},
        {name: '焦作', value: 75},
        {name: '句容', value: 75},
        {name: '北京', value: 79},
        {name: '徐州', value: 79},
        {name: '衡水', value: 80},
        {name: '包头', value: 80},
        {name: '绵阳', value: 80},
        {name: '乌鲁木齐', value: 84},
        {name: '枣庄', value: 84},
        {name: '杭州', value: 84},
        {name: '淄博', value: 85},
        {name: '鞍山', value: 86},
        {name: '溧阳', value: 86},
        {name: '库尔勒', value: 86},
        {name: '安阳', value: 90},
        {name: '开封', value: 90},
        {name: '济南', value: 92},
        {name: '德阳', value: 93},
        {name: '温州', value: 95},
        {name: '九江', value: 96},
        {name: '邯郸', value: 98},
        {name: '临安', value: 99},
        {name: '兰州', value: 99},
        {name: '沧州', value: 100},
        {name: '临沂', value: 103},
        {name: '南充', value: 104},
        {name: '天津', value: 105},
        {name: '富阳', value: 106},
        {name: '泰安', value: 112},
        {name: '诸暨', value: 112},
        {name: '郑州', value: 113},
        {name: '哈尔滨', value: 114},
        {name: '聊城', value: 116},
        {name: '芜湖', value: 117},
        {name: '唐山', value: 119},
        {name: '平顶山', value: 119},
        {name: '邢台', value: 119},
        {name: '德州', value: 120},
        {name: '济宁', value: 120},
        {name: '荆州', value: 127},
        {name: '宜昌', value: 130},
        {name: '义乌', value: 132},
        {name: '丽水', value: 133},
        {name: '洛阳', value: 134},
        {name: '秦皇岛', value: 136},
        {name: '株洲', value: 143},
        {name: '石家庄', value: 147},
        {name: '莱芜', value: 148},
        {name: '常德', value: 152},
        {name: '保定', value: 153},
        {name: '湘潭', value: 154},
        {name: '金华', value: 157},
        {name: '岳阳', value: 169},
        {name: '长沙', value: 175},
        {name: '衢州', value: 177},
        {name: '廊坊', value: 193},
        {name: '菏泽', value: 194},
        {name: '合肥', value: 229},
        {name: '武汉', value: 273},
        {name: '大庆', value: 279}
    ];

    var geoCoordMap = {
        '海门': [121.15, 31.89],
        '鄂尔多斯': [109.781327, 39.608266],
        '招远': [120.38, 37.35],
        '舟山': [122.207216, 29.985295],
        '齐齐哈尔': [123.97, 47.33],
        '盐城': [120.13, 33.38],
        '赤峰': [118.87, 42.28],
        '青岛': [120.33, 36.07],
        '乳山': [121.52, 36.89],
        '金昌': [102.188043, 38.520089],
        '泉州': [118.58, 24.93],
        '莱西': [120.53, 36.86],
        '日照': [119.46, 35.42],
        '胶南': [119.97, 35.88],
        '南通': [121.05, 32.08],
        '拉萨': [91.11, 29.97],
        '云浮': [112.02, 22.93],
        '梅州': [116.1, 24.55],
        '文登': [122.05, 37.2],
        '上海': [121.48, 31.22],
        '攀枝花': [101.718637, 26.582347],
        '威海': [122.1, 37.5],
        '承德': [117.93, 40.97],
        '厦门': [118.1, 24.46],
        '汕尾': [115.375279, 22.786211],
        '潮州': [116.63, 23.68],
        '丹东': [124.37, 40.13],
        '太仓': [121.1, 31.45],
        '曲靖': [103.79, 25.51],
        '烟台': [121.39, 37.52],
        '福州': [119.3, 26.08],
        '瓦房店': [121.979603, 39.627114],
        '即墨': [120.45, 36.38],
        '抚顺': [123.97, 41.97],
        '玉溪': [102.52, 24.35],
        '张家口': [114.87, 40.82],
        '阳泉': [113.57, 37.85],
        '莱州': [119.942327, 37.177017],
        '湖州': [120.1, 30.86],
        '汕头': [116.69, 23.39],
        '昆山': [120.95, 31.39],
        '宁波': [121.56, 29.86],
        '湛江': [110.359377, 21.270708],
        '揭阳': [116.35, 23.55],
        '荣成': [122.41, 37.16],
        '连云港': [119.16, 34.59],
        '葫芦岛': [120.836932, 40.711052],
        '常熟': [120.74, 31.64],
        '东莞': [113.75, 23.04],
        '河源': [114.68, 23.73],
        '淮安': [119.15, 33.5],
        '泰州': [119.9, 32.49],
        '南宁': [108.33, 22.84],
        '营口': [122.18, 40.65],
        '惠州': [114.4, 23.09],
        '江阴': [120.26, 31.91],
        '蓬莱': [120.75, 37.8],
        '韶关': [113.62, 24.84],
        '嘉峪关': [98.289152, 39.77313],
        '广州': [113.23, 23.16],
        '延安': [109.47, 36.6],
        '太原': [112.53, 37.87],
        '清远': [113.01, 23.7],
        '中山': [113.38, 22.52],
        '昆明': [102.73, 25.04],
        '寿光': [118.73, 36.86],
        '盘锦': [122.070714, 41.119997],
        '长治': [113.08, 36.18],
        '深圳': [114.07, 22.62],
        '珠海': [113.52, 22.3],
        '宿迁': [118.3, 33.96],
        '咸阳': [108.72, 34.36],
        '铜川': [109.11, 35.09],
        '平度': [119.97, 36.77],
        '佛山': [113.11, 23.05],
        '海口': [110.35, 20.02],
        '江门': [113.06, 22.61],
        '章丘': [117.53, 36.72],
        '肇庆': [112.44, 23.05],
        '大连': [121.62, 38.92],
        '临汾': [111.5, 36.08],
        '吴江': [120.63, 31.16],
        '石嘴山': [106.39, 39.04],
        '沈阳': [123.38, 41.8],
        '苏州': [120.62, 31.32],
        '茂名': [110.88, 21.68],
        '嘉兴': [120.76, 30.77],
        '长春': [125.35, 43.88],
        '胶州': [120.03336, 36.264622],
        '银川': [106.27, 38.47],
        '张家港': [120.555821, 31.875428],
        '三门峡': [111.19, 34.76],
        '锦州': [121.15, 41.13],
        '南昌': [115.89, 28.68],
        '柳州': [109.4, 24.33],
        '三亚': [109.511909, 18.252847],
        '自贡': [104.778442, 29.33903],
        '吉林': [126.57, 43.87],
        '阳江': [111.95, 21.85],
        '泸州': [105.39, 28.91],
        '西宁': [101.74, 36.56],
        '宜宾': [104.56, 29.77],
        '呼和浩特': [111.65, 40.82],
        '成都': [104.06, 30.67],
        '大同': [113.3, 40.12],
        '镇江': [119.44, 32.2],
        '桂林': [110.28, 25.29],
        '张家界': [110.479191, 29.117096],
        '宜兴': [119.82, 31.36],
        '北海': [109.12, 21.49],
        '西安': [108.95, 34.27],
        '金坛': [119.56, 31.74],
        '东营': [118.49, 37.46],
        '牡丹江': [129.58, 44.6],
        '遵义': [106.9, 27.7],
        '绍兴': [120.58, 30.01],
        '扬州': [119.42, 32.39],
        '常州': [119.95, 31.79],
        '潍坊': [119.1, 36.62],
        '重庆': [106.54, 29.59],
        '台州': [121.420757, 28.656386],
        '南京': [118.78, 32.04],
        '滨州': [118.03, 37.36],
        '贵阳': [106.71, 26.57],
        '无锡': [120.29, 31.59],
        '本溪': [123.73, 41.3],
        '克拉玛依': [84.77, 45.59],
        '渭南': [109.5, 34.52],
        '马鞍山': [118.48, 31.56],
        '宝鸡': [107.15, 34.38],
        '焦作': [113.21, 35.24],
        '句容': [119.16, 31.95],
        '北京': [116.46, 39.92],
        '徐州': [117.2, 34.26],
        '衡水': [115.72, 37.72],
        '包头': [110, 40.58],
        '绵阳': [104.73, 31.48],
        '乌鲁木齐': [87.68, 43.77],
        '枣庄': [117.57, 34.86],
        '杭州': [120.19, 30.26],
        '淄博': [118.05, 36.78],
        '鞍山': [122.85, 41.12],
        '溧阳': [119.48, 31.43],
        '库尔勒': [86.06, 41.68],
        '安阳': [114.35, 36.1],
        '开封': [114.35, 34.79],
        '济南': [117, 36.65],
        '德阳': [104.37, 31.13],
        '温州': [120.65, 28.01],
        '九江': [115.97, 29.71],
        '邯郸': [114.47, 36.6],
        '临安': [119.72, 30.23],
        '兰州': [103.73, 36.03],
        '沧州': [116.83, 38.33],
        '临沂': [118.35, 35.05],
        '南充': [106.110698, 30.837793],
        '天津': [117.2, 39.13],
        '富阳': [119.95, 30.07],
        '泰安': [117.13, 36.18],
        '诸暨': [120.23, 29.71],
        '郑州': [113.65, 34.76],
        '哈尔滨': [126.63, 45.75],
        '聊城': [115.97, 36.45],
        '芜湖': [118.38, 31.33],
        '唐山': [118.02, 39.63],
        '平顶山': [113.29, 33.75],
        '邢台': [114.48, 37.05],
        '德州': [116.29, 37.45],
        '济宁': [116.59, 35.38],
        '荆州': [112.239741, 30.335165],
        '宜昌': [111.3, 30.7],
        '义乌': [120.06, 29.32],
        '丽水': [119.92, 28.45],
        '洛阳': [112.44, 34.7],
        '秦皇岛': [119.57, 39.95],
        '株洲': [113.16, 27.83],
        '石家庄': [114.48, 38.03],
        '莱芜': [117.67, 36.19],
        '常德': [111.69, 29.05],
        '保定': [115.48, 38.85],
        '湘潭': [112.91, 27.87],
        '金华': [119.64, 29.12],
        '岳阳': [113.09, 29.37],
        '长沙': [113, 28.21],
        '衢州': [118.88, 28.97],
        '廊坊': [116.7, 39.53],
        '菏泽': [115.480656, 35.23375],
        '合肥': [117.27, 31.86],
        '武汉': [114.31, 30.52],
        '大庆': [125.03, 46.58]
    };

    var convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            }else{
                console.log(data[i].name)
            }
        }
        return res;
    };

    var option = {
        backgroundColor: '#404a59',  //整体背景
        title: {                     //标题
            text: '成果/需求对接分布图',
            left: 'center',
            top:40,
            textStyle: {
                color: '#fff'
            }
        },
        geo: {
            map: 'china',             //中国地图
            label: {                  //控制省份名
                normal: {             //正常模式
                    show:false,
                },
                emphasis: {           //hover模式
                    show: false,
                }
            },
            roam: true, //是否开启平移和缩放
            zoom:1.2,
            itemStyle: {              //控制省份区域(省份块)
                normal: {
                    areaColor: '#323c48',
                    borderColor: '#111',
                },
                emphasis: {
                    areaColor: '#2a333d'
                }
            }
        },
        toolbox: {                     //工具栏
            show: true,
            feature: {

                restore: {},           //重置
            }
        },
        tooltip: {                   //提示框组件。 hover导航框
            trigger: 'item',
            formatter: (data)=>{        //导航框内容  可以写标签哦!!!
                console.log(data)
                return  '

成果名称:这是第一段废话这是第一段废话这是第一段废话

所属单位:这是第一段废话这是第一段废话这是第一段废话

发布时间:这是第一段废话这是第一段废话这是第一段废话

成果状态:这是第一段废话这是第一段废话这是第一段废话

隶属领域:这是第一段废话这是第一段废话这是第一段废话

该领域所在省在全国的占比:这是第一段废话这是第一段废话这是第一段废话

'
} }, series: [ { name: '已对接成果', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 data: convertData(data).slice(0,50), symbolSize: function (val) { return val[2] / 15; }, label: { //每个点的信息 normal: { formatter: '{b}', position: 'right', show: false, textStyle: { color: '#9ba0aa', fontFamily: '微软雅黑' } }, emphasis: { show: true } }, itemStyle: { normal: { color: 'red' //圆点颜色 } } }, { name: '未对接成果', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 data: convertData(data).slice(50,100), symbolSize: function (val) { return val[2] / 15; }, label: { //每个点的信息 normal: { formatter: '{b}', position: 'right', show: false, textStyle: { color: '#9ba0aa', fontFamily: '微软雅黑' } }, emphasis: { show: true } }, itemStyle: { normal: { color: 'green' //圆点颜色 } } }, { name: '已对接需求', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 data: convertData(data).slice(100,150), symbolSize: function (val) { return val[2] / 15; }, label: { //每个点的信息 normal: { formatter: '{b}', position: 'right', show: false, textStyle: { color: '#9ba0aa', fontFamily: '微软雅黑' } }, emphasis: { show: true } }, itemStyle: { normal: { color: 'blue' //圆点颜色 } } }, { name: '未对接需求', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 data: convertData(data).slice(150,190), symbolSize: function (val) { return val[2] / 15; }, label: { //每个点的信息 normal: { formatter: '{b}', position: 'right', show: false, textStyle: { color: '#9ba0aa', fontFamily: '微软雅黑' } }, emphasis: { show: true } }, itemStyle: { normal: { color: 'yellow' //圆点颜色 } } }, { name: '连线', type: 'lines', //用于带有起点和终点信息的线数据的绘制,主要用于地图上的航线,路线的可视化。 zlevel: 2, effect: { //线的运行特效 show: true, period: 4, //运行时间 symbol: 'triangle', //头的形状 symbolSize: 3, //头的大小 trailLength: 0.3, //特效尾迹的长度。取从 0 到 1 的值,数值越大尾迹越长。 color: 'rgba(244,233,37,0.8)', }, symbol: ['none', 'triangle'], //线两端的标记类型 lineStyle: { normal: { color: 'rgba(30,144,255,0.5)', width: 3, curveness: 0.2 } }, data:[{ coords:[[116.46, 39.92],[121.48, 31.22]], fromName: "北京", toName:"上海" }] } ] }; if (option && typeof option === "object") { myChart.setOption(option, true); }; </script> </html>
  • 散点图 3
<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
    <title>散点图3</title>
    <style>
        #container{
            width: 950px;
            height: 680px;
        }
    </style>

</head>

<body>
    <div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script src="../script/map/china.js"></script>
<script type="text/javascript">
    //https://www.echartsjs.com/gallery/editor.html?c=doc-example/scatter-visualMap-categories&edit=1&reset=1
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var data = [{
            name: '海门',
            value: 9
        },
        {
            name: '鄂尔多斯',
            value: 12
        },
        {
            name: '招远',
            value: 12
        },
        {
            name: '舟山',
            value: 12
        },
        {
            name: '齐齐哈尔',
            value: 14
        },
        {
            name: '盐城',
            value: 15
        },
        {
            name: '赤峰',
            value: 16
        },
        {
            name: '青岛',
            value: 18
        },
        {
            name: '乳山',
            value: 18
        },
        {
            name: '金昌',
            value: 19
        },
        {
            name: '泉州',
            value: 21
        },
        {
            name: '莱西',
            value: 21
        },
        {
            name: '日照',
            value: 21
        },
        {
            name: '胶南',
            value: 22
        },
        {
            name: '南通',
            value: 23
        },
        {
            name: '拉萨',
            value: 24
        },
        {
            name: '云浮',
            value: 24
        },
        {
            name: '梅州',
            value: 25
        },
        {
            name: '文登',
            value: 25
        },
        {
            name: '上海',
            value: 25
        },
        {
            name: '攀枝花',
            value: 25
        },
        {
            name: '威海',
            value: 25
        },
        {
            name: '承德',
            value: 25
        },
        {
            name: '厦门',
            value: 26
        },
        {
            name: '汕尾',
            value: 26
        },
        {
            name: '潮州',
            value: 26
        },
        {
            name: '丹东',
            value: 27
        },
        {
            name: '太仓',
            value: 27
        },
        {
            name: '曲靖',
            value: 27
        },
        {
            name: '烟台',
            value: 28
        },
        {
            name: '福州',
            value: 29
        },
        {
            name: '瓦房店',
            value: 30
        },
        {
            name: '即墨',
            value: 30
        },
        {
            name: '抚顺',
            value: 31
        },
        {
            name: '玉溪',
            value: 31
        },
        {
            name: '张家口',
            value: 31
        },
        {
            name: '阳泉',
            value: 31
        },
        {
            name: '莱州',
            value: 32
        },
        {
            name: '湖州',
            value: 32
        },
        {
            name: '汕头',
            value: 32
        },
        {
            name: '昆山',
            value: 33
        },
        {
            name: '宁波',
            value: 33
        },
        {
            name: '湛江',
            value: 33
        },
        {
            name: '揭阳',
            value: 34
        },
        {
            name: '荣成',
            value: 34
        },
        {
            name: '连云港',
            value: 35
        },
        {
            name: '葫芦岛',
            value: 35
        },
        {
            name: '常熟',
            value: 36
        },
        {
            name: '东莞',
            value: 36
        },
        {
            name: '河源',
            value: 36
        },
        {
            name: '淮安',
            value: 36
        },
        {
            name: '泰州',
            value: 36
        },
        {
            name: '南宁',
            value: 37
        },
        {
            name: '营口',
            value: 37
        },
        {
            name: '惠州',
            value: 37
        },
        {
            name: '江阴',
            value: 37
        },
        {
            name: '蓬莱',
            value: 37
        },
        {
            name: '韶关',
            value: 38
        },
        {
            name: '嘉峪关',
            value: 38
        },
        {
            name: '广州',
            value: 38
        },
        {
            name: '延安',
            value: 38
        },
        {
            name: '太原',
            value: 39
        },
        {
            name: '清远',
            value: 39
        },
        {
            name: '中山',
            value: 39
        },
        {
            name: '昆明',
            value: 39
        },
        {
            name: '寿光',
            value: 40
        },
        {
            name: '盘锦',
            value: 40
        },
        {
            name: '长治',
            value: 41
        },
        {
            name: '深圳',
            value: 41
        },
        {
            name: '珠海',
            value: 42
        },
        {
            name: '宿迁',
            value: 43
        },
        {
            name: '咸阳',
            value: 43
        },
        {
            name: '铜川',
            value: 44
        },
        {
            name: '平度',
            value: 44
        },
        {
            name: '佛山',
            value: 44
        },
        {
            name: '海口',
            value: 44
        },
        {
            name: '江门',
            value: 45
        },
        {
            name: '章丘',
            value: 45
        },
        {
            name: '肇庆',
            value: 46
        },
        {
            name: '大连',
            value: 47
        },
        {
            name: '临汾',
            value: 47
        },
        {
            name: '吴江',
            value: 47
        },
        {
            name: '石嘴山',
            value: 49
        },
        {
            name: '沈阳',
            value: 50
        },
        {
            name: '苏州',
            value: 50
        },
        {
            name: '茂名',
            value: 50
        },
        {
            name: '嘉兴',
            value: 51
        },
        {
            name: '长春',
            value: 51
        },
        {
            name: '胶州',
            value: 52
        },
        {
            name: '银川',
            value: 52
        },
        {
            name: '张家港',
            value: 52
        },
        {
            name: '三门峡',
            value: 53
        },
        {
            name: '锦州',
            value: 54
        },
        {
            name: '南昌',
            value: 54
        },
        {
            name: '柳州',
            value: 54
        },
        {
            name: '三亚',
            value: 54
        },
        {
            name: '自贡',
            value: 56
        },
        {
            name: '吉林',
            value: 56
        },
        {
            name: '阳江',
            value: 57
        },
        {
            name: '泸州',
            value: 57
        },
        {
            name: '西宁',
            value: 57
        },
        {
            name: '宜宾',
            value: 58
        },
        {
            name: '呼和浩特',
            value: 58
        },
        {
            name: '成都',
            value: 58
        },
        {
            name: '大同',
            value: 58
        },
        {
            name: '镇江',
            value: 59
        },
        {
            name: '桂林',
            value: 59
        },
        {
            name: '张家界',
            value: 59
        },
        {
            name: '宜兴',
            value: 59
        },
        {
            name: '北海',
            value: 60
        },
        {
            name: '西安',
            value: 61
        },
        {
            name: '金坛',
            value: 62
        },
        {
            name: '东营',
            value: 62
        },
        {
            name: '牡丹江',
            value: 63
        },
        {
            name: '遵义',
            value: 63
        },
        {
            name: '绍兴',
            value: 63
        },
        {
            name: '扬州',
            value: 64
        },
        {
            name: '常州',
            value: 64
        },
        {
            name: '潍坊',
            value: 65
        },
        {
            name: '重庆',
            value: 66
        },
        {
            name: '台州',
            value: 67
        },
        {
            name: '南京',
            value: 67
        },
        {
            name: '滨州',
            value: 70
        },
        {
            name: '贵阳',
            value: 71
        },
        {
            name: '无锡',
            value: 71
        },
        {
            name: '本溪',
            value: 71
        },
        {
            name: '克拉玛依',
            value: 72
        },
        {
            name: '渭南',
            value: 72
        },
        {
            name: '马鞍山',
            value: 72
        },
        {
            name: '宝鸡',
            value: 72
        },
        {
            name: '焦作',
            value: 75
        },
        {
            name: '句容',
            value: 75
        },
        {
            name: '北京',
            value: 79
        },
        {
            name: '徐州',
            value: 79
        },
        {
            name: '衡水',
            value: 80
        },
        {
            name: '包头',
            value: 80
        },
        {
            name: '绵阳',
            value: 80
        },
        {
            name: '乌鲁木齐',
            value: 84
        },
        {
            name: '枣庄',
            value: 84
        },
        {
            name: '杭州',
            value: 84
        },
        {
            name: '淄博',
            value: 85
        },
        {
            name: '鞍山',
            value: 86
        },
        {
            name: '溧阳',
            value: 86
        },
        {
            name: '库尔勒',
            value: 86
        },
        {
            name: '安阳',
            value: 90
        },
        {
            name: '开封',
            value: 90
        },
        {
            name: '济南',
            value: 92
        },
        {
            name: '德阳',
            value: 93
        },
        {
            name: '温州',
            value: 95
        },
        {
            name: '九江',
            value: 96
        },
        {
            name: '邯郸',
            value: 98
        },
        {
            name: '临安',
            value: 99
        },
        {
            name: '兰州',
            value: 99
        },
        {
            name: '沧州',
            value: 100
        },
        {
            name: '临沂',
            value: 103
        },
        {
            name: '南充',
            value: 104
        },
        {
            name: '天津',
            value: 105
        },
        {
            name: '富阳',
            value: 106
        },
        {
            name: '泰安',
            value: 112
        },
        {
            name: '诸暨',
            value: 112
        },
        {
            name: '郑州',
            value: 113
        },
        {
            name: '哈尔滨',
            value: 114
        },
        {
            name: '聊城',
            value: 116
        },
        {
            name: '芜湖',
            value: 117
        },
        {
            name: '唐山',
            value: 119
        },
        {
            name: '平顶山',
            value: 119
        },
        {
            name: '邢台',
            value: 119
        },
        {
            name: '德州',
            value: 120
        },
        {
            name: '济宁',
            value: 120
        },
        {
            name: '荆州',
            value: 127
        },
        {
            name: '宜昌',
            value: 130
        },
        {
            name: '义乌',
            value: 132
        },
        {
            name: '丽水',
            value: 133
        },
        {
            name: '洛阳',
            value: 134
        },
        {
            name: '秦皇岛',
            value: 136
        },
        {
            name: '株洲',
            value: 143
        },
        {
            name: '石家庄',
            value: 147
        },
        {
            name: '莱芜',
            value: 148
        },
        {
            name: '常德',
            value: 152
        },
        {
            name: '保定',
            value: 153
        },
        {
            name: '湘潭',
            value: 154
        },
        {
            name: '金华',
            value: 157
        },
        {
            name: '岳阳',
            value: 169
        },
        {
            name: '长沙',
            value: 175
        },
        {
            name: '衢州',
            value: 177
        },
        {
            name: '廊坊',
            value: 193
        },
        {
            name: '菏泽',
            value: 194
        },
        {
            name: '合肥',
            value: 229
        },
        {
            name: '武汉',
            value: 273
        },
        {
            name: '大庆',
            value: 279
        }
    ];

    var geoCoordMap = {
        '海门': [121.15, 31.89],
        '鄂尔多斯': [109.781327, 39.608266],
        '招远': [120.38, 37.35],
        '舟山': [122.207216, 29.985295],
        '齐齐哈尔': [123.97, 47.33],
        '盐城': [120.13, 33.38],
        '赤峰': [118.87, 42.28],
        '青岛': [120.33, 36.07],
        '乳山': [121.52, 36.89],
        '金昌': [102.188043, 38.520089],
        '泉州': [118.58, 24.93],
        '莱西': [120.53, 36.86],
        '日照': [119.46, 35.42],
        '胶南': [119.97, 35.88],
        '南通': [121.05, 32.08],
        '拉萨': [91.11, 29.97],
        '云浮': [112.02, 22.93],
        '梅州': [116.1, 24.55],
        '文登': [122.05, 37.2],
        '上海': [121.48, 31.22],
        '攀枝花': [101.718637, 26.582347],
        '威海': [122.1, 37.5],
        '承德': [117.93, 40.97],
        '厦门': [118.1, 24.46],
        '汕尾': [115.375279, 22.786211],
        '潮州': [116.63, 23.68],
        '丹东': [124.37, 40.13],
        '太仓': [121.1, 31.45],
        '曲靖': [103.79, 25.51],
        '烟台': [121.39, 37.52],
        '福州': [119.3, 26.08],
        '瓦房店': [121.979603, 39.627114],
        '即墨': [120.45, 36.38],
        '抚顺': [123.97, 41.97],
        '玉溪': [102.52, 24.35],
        '张家口': [114.87, 40.82],
        '阳泉': [113.57, 37.85],
        '莱州': [119.942327, 37.177017],
        '湖州': [120.1, 30.86],
        '汕头': [116.69, 23.39],
        '昆山': [120.95, 31.39],
        '宁波': [121.56, 29.86],
        '湛江': [110.359377, 21.270708],
        '揭阳': [116.35, 23.55],
        '荣成': [122.41, 37.16],
        '连云港': [119.16, 34.59],
        '葫芦岛': [120.836932, 40.711052],
        '常熟': [120.74, 31.64],
        '东莞': [113.75, 23.04],
        '河源': [114.68, 23.73],
        '淮安': [119.15, 33.5],
        '泰州': [119.9, 32.49],
        '南宁': [108.33, 22.84],
        '营口': [122.18, 40.65],
        '惠州': [114.4, 23.09],
        '江阴': [120.26, 31.91],
        '蓬莱': [120.75, 37.8],
        '韶关': [113.62, 24.84],
        '嘉峪关': [98.289152, 39.77313],
        '广州': [113.23, 23.16],
        '延安': [109.47, 36.6],
        '太原': [112.53, 37.87],
        '清远': [113.01, 23.7],
        '中山': [113.38, 22.52],
        '昆明': [102.73, 25.04],
        '寿光': [118.73, 36.86],
        '盘锦': [122.070714, 41.119997],
        '长治': [113.08, 36.18],
        '深圳': [114.07, 22.62],
        '珠海': [113.52, 22.3],
        '宿迁': [118.3, 33.96],
        '咸阳': [108.72, 34.36],
        '铜川': [109.11, 35.09],
        '平度': [119.97, 36.77],
        '佛山': [113.11, 23.05],
        '海口': [110.35, 20.02],
        '江门': [113.06, 22.61],
        '章丘': [117.53, 36.72],
        '肇庆': [112.44, 23.05],
        '大连': [121.62, 38.92],
        '临汾': [111.5, 36.08],
        '吴江': [120.63, 31.16],
        '石嘴山': [106.39, 39.04],
        '沈阳': [123.38, 41.8],
        '苏州': [120.62, 31.32],
        '茂名': [110.88, 21.68],
        '嘉兴': [120.76, 30.77],
        '长春': [125.35, 43.88],
        '胶州': [120.03336, 36.264622],
        '银川': [106.27, 38.47],
        '张家港': [120.555821, 31.875428],
        '三门峡': [111.19, 34.76],
        '锦州': [121.15, 41.13],
        '南昌': [115.89, 28.68],
        '柳州': [109.4, 24.33],
        '三亚': [109.511909, 18.252847],
        '自贡': [104.778442, 29.33903],
        '吉林': [126.57, 43.87],
        '阳江': [111.95, 21.85],
        '泸州': [105.39, 28.91],
        '西宁': [101.74, 36.56],
        '宜宾': [104.56, 29.77],
        '呼和浩特': [111.65, 40.82],
        '成都': [104.06, 30.67],
        '大同': [113.3, 40.12],
        '镇江': [119.44, 32.2],
        '桂林': [110.28, 25.29],
        '张家界': [110.479191, 29.117096],
        '宜兴': [119.82, 31.36],
        '北海': [109.12, 21.49],
        '西安': [108.95, 34.27],
        '金坛': [119.56, 31.74],
        '东营': [118.49, 37.46],
        '牡丹江': [129.58, 44.6],
        '遵义': [106.9, 27.7],
        '绍兴': [120.58, 30.01],
        '扬州': [119.42, 32.39],
        '常州': [119.95, 31.79],
        '潍坊': [119.1, 36.62],
        '重庆': [106.54, 29.59],
        '台州': [121.420757, 28.656386],
        '南京': [118.78, 32.04],
        '滨州': [118.03, 37.36],
        '贵阳': [106.71, 26.57],
        '无锡': [120.29, 31.59],
        '本溪': [123.73, 41.3],
        '克拉玛依': [84.77, 45.59],
        '渭南': [109.5, 34.52],
        '马鞍山': [118.48, 31.56],
        '宝鸡': [107.15, 34.38],
        '焦作': [113.21, 35.24],
        '句容': [119.16, 31.95],
        '北京': [116.46, 39.92],
        '徐州': [117.2, 34.26],
        '衡水': [115.72, 37.72],
        '包头': [110, 40.58],
        '绵阳': [104.73, 31.48],
        '乌鲁木齐': [87.68, 43.77],
        '枣庄': [117.57, 34.86],
        '杭州': [120.19, 30.26],
        '淄博': [118.05, 36.78],
        '鞍山': [122.85, 41.12],
        '溧阳': [119.48, 31.43],
        '库尔勒': [86.06, 41.68],
        '安阳': [114.35, 36.1],
        '开封': [114.35, 34.79],
        '济南': [117, 36.65],
        '德阳': [104.37, 31.13],
        '温州': [120.65, 28.01],
        '九江': [115.97, 29.71],
        '邯郸': [114.47, 36.6],
        '临安': [119.72, 30.23],
        '兰州': [103.73, 36.03],
        '沧州': [116.83, 38.33],
        '临沂': [118.35, 35.05],
        '南充': [106.110698, 30.837793],
        '天津': [117.2, 39.13],
        '富阳': [119.95, 30.07],
        '泰安': [117.13, 36.18],
        '诸暨': [120.23, 29.71],
        '郑州': [113.65, 34.76],
        '哈尔滨': [126.63, 45.75],
        '聊城': [115.97, 36.45],
        '芜湖': [118.38, 31.33],
        '唐山': [118.02, 39.63],
        '平顶山': [113.29, 33.75],
        '邢台': [114.48, 37.05],
        '德州': [116.29, 37.45],
        '济宁': [116.59, 35.38],
        '荆州': [112.239741, 30.335165],
        '宜昌': [111.3, 30.7],
        '义乌': [120.06, 29.32],
        '丽水': [119.92, 28.45],
        '洛阳': [112.44, 34.7],
        '秦皇岛': [119.57, 39.95],
        '株洲': [113.16, 27.83],
        '石家庄': [114.48, 38.03],
        '莱芜': [117.67, 36.19],
        '常德': [111.69, 29.05],
        '保定': [115.48, 38.85],
        '湘潭': [112.91, 27.87],
        '金华': [119.64, 29.12],
        '岳阳': [113.09, 29.37],
        '长沙': [113, 28.21],
        '衢州': [118.88, 28.97],
        '廊坊': [116.7, 39.53],
        '菏泽': [115.480656, 35.23375],
        '合肥': [117.27, 31.86],
        '武汉': [114.31, 30.52],
        '大庆': [125.03, 46.58]
    };

    var convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            } else {
                console.log(data[i].name)
            }
        }
        return res;
    };
    var companyColor = ['#f5fe02', '#019cfe', '#b9f0a7'];
    var option = {
        backgroundColor: '#404a59', //整体背景
        color: companyColor,
        geo: {
            map: 'china', //中国地图
            label: { //控制省份名
                normal: { //正常模式
                    show: false,
                },
                emphasis: { //hover模式
                    show: false,
                }
            },
            roam: true, //是否开启平移和缩放
            zoom: 1.2,
            itemStyle: { //控制省份区域(省份块)
                normal: {
                    areaColor: '#323c48',
                    borderColor: '#111',
                },
                emphasis: {
                    areaColor: '#2a333d'
                }
            }
        },
        tooltip: { //提示框组件。 hover导航框
            trigger: 'item',
            formatter: function (res) { //导航框内容  可以写标签哦!!!
                // console.log(res)
                // return '

公司名称:' + res.data.Name + '

公司地点:' + res.data.Park + '

隶属领域:' + res.data.TechField + '

'
} }, legend: { bottom: 0, left: 10, padding: [ 0, // 上 0, // 右 7, // 下 0, // 左 ], itemGap: 18, itemWidth: 14, itemHeight: 14, textStyle: { fontFamily: 'Microsoft YaHei', fontSize: 14, color: '#fff' }, data: [{ name: '创新型企业', icon: 'circle' }, { name: '军工资质企业', icon: 'circle' }, { name: '参军潜力企业', icon: 'circle' }] }, visualMap: { type: 'piecewise', //类型为分段型。 orient: 'horizontal', bottom: 0, right: 0, showLabel: true, text: ['军民融合潜力指数图例'], textStyle: { color: '#fff' }, // min: 0, // max: 100, splitNumber: 5, //分几段 inRange: { //定义 在选中范围中 的视觉元素。 symbol: 'circle', symbolSize: [5, 25] // 5 10 15 20 25 } }, series: [{ name: '创新型企业', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 label: { //每个点的信息 normal: { show: false, } }, itemStyle: { normal: { // color: companyColor[0], shadowBlur: 2, shadowColor: companyColor[0] } }, data: convertData(data).slice(0, 50), zlevel: 1 }, { name: '军工资质企业', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 label: { //每个点的信息 normal: { show: false, } }, itemStyle: { normal: { // color: companyColor[1], shadowBlur: 2, shadowColor: companyColor[1] } }, data: convertData(data).slice(50, 100), zlevel: 1 }, { name: '参军潜力企业', type: 'scatter', coordinateSystem: 'geo', progressive: 0, //不启用渐进式渲染 因为数据量在3000-10000有问题 label: { //每个点的信息 normal: { show: false, } }, itemStyle: { normal: { // color: companyColor[2], shadowBlur: 2, shadowColor: companyColor[2] } }, data: convertData(data).slice(100, 150), zlevel: 1 } ] }; if (option && typeof option === "object") { myChart.setOption(option, true); }; </script> </html>
  • 条形图 1
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>条形图1</title>
    <style>
        #right{
            width: 473px;
            height: 306px;
        }
    </style>
</head>
<body>
<div id="right"></div>

</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">
    var myChart = echarts.init(document.getElementById("right"));
    var app = {};
    app.title = '';

    var option = {
        backgroundColor: '#404a59',  //整体背景
        title: {
            text: '成果/需求领域分布图',
            left: 'center',
            top: 10,
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'axis',           //提示框组件
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            data: ['成果', '需求'],    //必须与series一一对应
            orient: 'vertical',
            top: 'bottom',
            left: '10',
            textStyle: {
                color: '#fff'
            }
        },
        //直角坐标系
        grid: {
            show:false,
            left: 100,                  //坐标系到左边的距离
            right: 45,                   //坐标系到右边的距离
            bottom:0,                   //坐标系到下边的距离
            containLabel: true           //是否包含坐标轴的刻度标签。
        },
        xAxis: {
            type: 'category',             //类目轴
            data: ['互联网', '人工智能','电子信息', '其他','自动化'],
            splitLine: {                  //坐标轴在 grid 区域中的分隔线设置。
                show: true,
                lineStyle:{
                    color:'#fff'
                }
            },
            axisLine:{                        //坐标轴轴线相关设置。
                lineStyle:{
                    color:'#9fdabf'           //坐标轴颜色
                }
            },
            axisTick: { show: false },     //坐标轴刻度相关设置。
            axisLabel: {                    //坐标轴标签的相关设置。轴下面的字
                show: true,
                color: 'cyan'
            }
        },
        yAxis: {
            type: 'value',                //数值轴
            splitLine: {                  //坐标轴在 grid 区域中的分隔线设置。
                show: true,
                lineStyle:{
                    color:'#fff'
                }
            },
            axisLine:{                    //坐标轴轴线相关设置。
                lineStyle:{
                    color:'#9fdabf'           //坐标轴颜色
                }
            },
            axisTick: { show: false },     //坐标轴刻度相关设置。
            axisLabel: {                    //坐标轴标签的相关设置。轴下面的字
                show: true,
                rotate:50,                  //刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠 旋转的角度从 -90 度到 90 度。
                color: 'cyan'
            }

        },
        series: [
            {
                name: '成果',
                type: 'bar',
                data: [18203, 23489, 29034, 104970,23489],
                silent: true,
                barWidth:20,        //柱条宽度
                barGap:'1%',        //柱条间距
                itemStyle: {
                    normal: { color: '#ffc917' }
                }
            },
            {
                name: '需求',
                type: 'bar',
                data: [19325, 23438, 31000, 121594,23489],
                z: 10,
                barWidth:20,
                itemStyle: {
                    normal: { color: '#00ffec' }
                }
            }
        ]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

</script>
</html>
  • 条形图 2
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>条形图2</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>
</head>
<body>
<div id="container"></div>

</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">
    var myChart = echarts.init(document.getElementById("container"));
    var app = {};
    app.title = '';

    var option = {
        title: {
            text: '成果需求转化',
            subtext: '数据来自创客天下'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            data: ['成果', '需求']    //必须与series一一对应
        },
        //直角坐标系
        grid: {
            left: '3%',      //坐标系到左边的距离
            right: '4%',     //坐标系到右边的距离
            bottom: '3%',   //坐标系到下边的距离
            containLabel: true  //是否包含坐标轴的刻度标签。
        },
        xAxis: {
            type: 'value',
            axisTick: {show: false},
            boundaryGap: ['0%', '10%'],   //坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。
        },
        yAxis: {
            type: 'category',
            data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)'],
            splitLine: {show: false}
        },
        animationDurationUpdate: 1200,
        series: [
            {
                name: '成果',
                type: 'bar',
                data: [18203, 23489, 29034, 104970, 131744, 630230],
                silent: true,
                barWidth: 40,
                barGap: '-100%' // Make series be overlap
            },
            {
                name: '需求',
                type: 'bar',
                data: [19325, 23438, 31000, 121594, 134141, 681807],
                barWidth: 40,
                z: 10
            }
        ]
    };
    var barGaps = ['30%', '-100%'];
    var loopIndex = 0;

    setInterval(function () {
        var barGap = barGaps[loopIndex];

        myChart.setOption({
            xAxis: {
                axisLabel: {
                    formatter: 'barGap: \'' + barGap + '\''
                }
            },
            series: [{
                barGap: barGap
            }]
        });
        loopIndex = (loopIndex + 1) % barGaps.length;

    }, 2000);
    
    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

</script>
</html>```

- 条形图和折线图

```javascript
<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>条形图和折线图</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>
</head>
<body >
<div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">

    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                crossStyle: {
                    color: '#999'
                }
            }
        },
        legend: {
            data:['市场规模','增长率']
        },
        xAxis: [
            {
                type: 'category',
                data: ['2015','2016','2017','2018','2019','2020'],
                axisPointer: {
                    type: 'shadow'
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '市场规模',
                min: 0,
                max: 1200,
                interval: 200,
                axisLabel: {
                    formatter: '{value} 亿元'
                }
            },
            {
                type: 'value',
                name: '增长率',
                min: 0,
                max: 90,
                interval: 15,
                axisLabel: {
                    formatter: '{value} %'
                }
            }
        ],
        series: [
            {
                name:'市场规模',
                type:'bar',
                barWidth:20,        //柱条宽度
                barGap:'1%',        //柱条间距
                label: {
                    normal: {
                        position: 'top',
                        color:'#033efc',
                        show: true
                    }
                },
                itemStyle: {
                    normal: { color: '#0396fd' }
                },
                data:[112, 143, 240, 420, 698 , 978]
            },
            {
                name:'增长率',
                type:'line',
                yAxisIndex: 1,
                data:[{},28,68,75,66,40]
            }
        ]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

</script>
</html>
  • 极坐标图和折线图
<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>条形图和折线图</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>
</head>
<body >
<div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">

    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                crossStyle: {
                    color: '#999'
                }
            }
        },
        legend: {
            data:['市场规模','增长率']
        },
        xAxis: [
            {
                type: 'category',
                data: ['2015','2016','2017','2018','2019','2020'],
                axisPointer: {
                    type: 'shadow'
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '市场规模',
                min: 0,
                max: 1200,
                interval: 200,
                axisLabel: {
                    formatter: '{value} 亿元'
                }
            },
            {
                type: 'value',
                name: '增长率',
                min: 0,
                max: 90,
                interval: 15,
                axisLabel: {
                    formatter: '{value} %'
                }
            }
        ],
        series: [
            {
                name:'市场规模',
                type:'bar',
                barWidth:20,        //柱条宽度
                barGap:'1%',        //柱条间距
                label: {
                    normal: {
                        position: 'top',
                        color:'#033efc',
                        show: true
                    }
                },
                itemStyle: {
                    normal: { color: '#0396fd' }
                },
                data:[112, 143, 240, 420, 698 , 978]
            },
            {
                name:'增长率',
                type:'line',
                yAxisIndex: 1,
                data:[{},28,68,75,66,40]
            }
        ]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

</script>
</html>```

- 极坐标条形图

```javascript
<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>极坐标条形图</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>
</head>
<body >
<div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">

    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var arr1=["能源与节能","材料", "先进制造与自动化",  "电子信息", "其他"];
    var arr2=[2234,4448, 5142,8442, 3132];

    var option = {
        backgroundColor: '#404a59',  //整体背景
        title: {
            text: '领域转化量分布图',
            top: '10',
            left: 'center',
            textStyle: {
                color: '#fff',
                fontWeight: 100,
                fontSize: 20
            }
        },
        color: ['#c23531', '#ffc917', '#61a0a8', '#00ffec', '#91c7ae'],
        legend: {
            data: [{            //必须与series一一对应
                name: '领域转化量'

            }],
            orient: 'vertical',
            top: 'bottom',
            left: 0,
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        polar: {                    //极坐标系 必须有
            center:['50%','60%'],   //极坐标的圆心
            radius:'60%'            //极坐标的半径
        },
        angleAxis: {
            type: 'category',    //极坐标系角度轴 必须有
            startAngle: 90,
            data:arr1,
            axisLine: {                    //坐标轴轴线相关设置。
                lineStyle: {
                    color: '#cccccc'      //坐标轴颜色
                }
            },
            axisTick: { show: true },      //坐标轴刻度相关设置。
            axisLabel: {
                show: true,
                color: '#fff'
            }
        },
        radiusAxis: {                     //极坐标系径向轴 必须有
            axisLine: {                    //坐标轴轴线相关设置。
                lineStyle: {
                    color: '#cccccc'      //坐标轴颜色
                }
            },
            axisTick: { show: true },      //坐标轴刻度相关设置。
            axisLabel: {
                show: true,
                color: '#fff',
                fontSize:10
            }
        },
        series: [{
            name: '领域转化量',
            type: 'bar',
            data:arr2,
            center:['50%','60%'],      //series图的圆心 应该与polar极坐标系的圆心一致  比较特殊 文档没有
            coordinateSystem: 'polar'  //采取极坐标方法 必须有
        }]

    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

</script>
</html>
  • 双轴图

  • 北京地图

  • 全国地图

<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
    <title>全国地图</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script src="../script/map/china.js"></script>
<script type="text/javascript">

    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);

    var option = {
        tooltip: {},
        /*方法一*/
        // geo: {
        //     map: 'china',
        //     roam: true,
        //     zoom: 1.2,
        //     aspectScale: 0.75,
        //     label: {
        //         normal: {
        //             show: true,
        //             textStyle: {
        //                 color: 'rgba(0,0,0,0.4)'
        //             }
        //         }
        //     },
        //     itemStyle: {
        //         normal: {
        //             areaColor: 'rgba(0,255,236,0.1)',
        //             borderColor: 'rgba(118,237,236,1)',
        //         },
        //         emphasis: {
        //             areaColor: 'rgba(118,237,236,0.8)',
        //             shadowOffsetX: 0,
        //             shadowOffsetY: 0,
        //             shadowBlur: 20,
        //             borderWidth: 0,
        //             shadowColor: 'rgba(0, 0, 0, 0.5)'
        //         }
        //     }
        // },
        /*方法二 */
        series: [{
            name: '省',
            type: 'map',
            map: 'china',
            roam: true,
            zoom: 1.2,
            aspectScale: 0.75,
            label: {
                normal: {
                    show: true,
                    textStyle: {
                        color: 'rgba(0,0,0,0.4)'
                    }
                }
            },
            itemStyle: {
                normal: {
                    areaColor: 'rgba(0,255,236,0.1)',
                    borderColor: 'rgba(118,237,236,1)',
                },
                emphasis: {
                    areaColor: 'rgba(118,237,236,0.8)',
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);

    };
</script>

</html>
  • 全国地图发光效果
<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
    <title>全国地图发光效果</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script src="../script/map/china.js"></script>
<script type="text/javascript">
    // 全国地图发光的实现方法 
    // 在geo组件上设置发光的地图
    // series.map设置不发光的地图  
    // 用series.map覆盖geo组件
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    
    function randomValue() {
        return Math.round(Math.random() * 100);
    }

    var option = {
        backgroundColor: '#000', //整体背景
        geo: {
            map: 'china',
            label: { //控制省份名
                normal: { //正常模式
                    show: false
                },
                emphasis: { //hover模式
                    show: false
                }
            },
            zoom: 1.2,
            aspectScale: 0.75,
            itemStyle: {
                normal: {
                    areaColor: 'rgba(2,100,195,0.5)',
                    borderColor: '#02d1fd',
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 120,
                    shadowColor: 'rgb(2,209,253,0.7)'
                }
            }
        },
        series: [{
            name:'省份',
            showLegendSymbol: false,    // 存在legend时不显示 
            type: 'map',
            map: 'china',
            label: { //控制省份名
                normal: { //正常模式
                    show: false
                },
                emphasis: { //hover模式
                    show: false
                }
            },
            zoom: 1.2,
            aspectScale: 0.75,
            itemStyle: {
                normal: {
                    areaColor: 'rgba(2,100,195,0.5)',
                    borderColor: '#02d1fd',
                },
                emphasis: {
                    areaColor: 'rgba(118,237,236,0.8)',
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            },
            zlevel: 1,
            data: [
                {"name": "北京", "value": 395, "percent": "39.3%"},
                {"name": "天津", "value": 17, "percent": "1.7%"},
                {"name": "上海", "value": 210, "percent": "20.9%"},
                {"name": "重庆", "value": 5, "percent": "0.5%"},
                {"name": "河北", "value": 0, "percent": "0%"},
                {"name": "河南", "value": 3, "percent": "0.3%"},
                {"name": "云南", "value": 0, "percent": "0%"},
                {"name": "辽宁", "value": 5, "percent": "0.5%"},
                {"name": "黑龙江", "value": 3, "percent": "0.3%"},
                {"name": "湖南", "value": 0, "percent": "0%"},
                {"name": "安徽", "value": 12, "percent": "1.2%"},
                {"name": "山东", "value": 10, "percent": "1%"},
                {"name": "新疆", "value": 0, "percent": "0%"},
                {"name": "江苏", "value": 42, "percent": "4.2%"},
                {"name": "浙江", "value": 66, "percent": "6.6%"},
                {"name": "江西", "value": 3, "percent": "0.3%"},
                {"name": "湖北", "value": 15, "percent": "1.5%"},
                {"name": "广西", "value": 0, "percent": "0%"},
                {"name": "甘肃", "value": 0, "percent": "0%"},
                {"name": "山西", "value": 0, "percent": "0%"},
                {"name": "内蒙古", "value": 0, "percent": "0%"},
                {"name": "陕西", "value": 17, "percent": "1.7%"},
                {"name": "吉林", "value": 0, "percent": "0%"},
                {"name": "福建", "value": 16, "percent": "1.6%"},
                {"name": "贵州", "value": 0, "percent": "0%"},
                {"name": "广东", "value": 165, "percent": "16.4%"},
                {"name": "青海", "value": 0, "percent": "0%"},
                {"name": "西藏", "value": 0, "percent": "0%"},
                {"name": "四川", "value": 20, "percent": "2%"},
                {"name": "宁夏", "value": 0, "percent": "0%"},
                {"name": "海南", "value": 0, "percent": "0%"},
                {"name": "台湾", "value": 0, "percent": "0%"},
                {"name": "香港", "value": 0, "percent": "0%"},
                {"name": "澳门", "value": 0, "percent": "0%"}
            ]
        }]
    
     }

    if (option && typeof option === "object") {
        myChart.setOption(option, true);

    };
</script>

</html>
  • 全国地图突出北京
<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>全国地图突出北京</title>
    <style>
        #container{
            width: 1000px;
            height: 800px;
        }
    </style>

</head>
<body >
<div id="container"></div>
</body>
<script src="../script/echarts.js"></script>
<script src="../script/map/china.js"></script>
<script type="text/javascript">
    function randomValue() {
        return Math.round(Math.random()*1000);
    }

    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    
    var option = {
        backgroundColor: '#404a59',  //整体背景
        title: {                     //标题
            text: '成果/需求对接分布图',
            left: 'center',
            top:40,
            textStyle: {
                color: '#fff'
            }
        },
        legend: {   //导航
            orient: 'vertical',
            y: 'bottom',
            x: 'right',
            data: ['已对接成果','未对接成果','已对接需求','未对接需求'],    //必须与series一一对应
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {                   //提示框组件。 hover导航框
            trigger: 'item',

        },
        /*方法一*/
        geo: {  //公共的地图geo组件
            map: 'china',             //中国地图
            label: {                  //控制省份名
                normal: {             //正常模式
                    show:false,
                },
                emphasis: {           //hover模式
                    show: false,
                }
            },
            roam: false, //是否开启平移和缩放
//            zoom:1.2,
            itemStyle: {              //控制省份区域(省份块)
                normal: {
                    areaColor: '#323c48',
                    borderColor: '#111',
                },
                emphasis: {
                    areaColor: '#2a333d'
                }
            },
            regions: [{   //突出北京
                name: '北京',
                itemStyle: {
                    normal: {
                        areaColor: 'red',
                        color: 'red'
                    }
                }
            }]
        },
        /*方法二 */
//        series: [
//            {
//                name: '中国',
//                type: 'map',
//                map: 'china',
//                label: {
//                    normal: {
//                        show: true
//                    },
//                    emphasis: {
//                        show: true
//                    }
//                },
//                data:[
//                    {name:'北京', selected:true},
//                ]
//            }
//        ]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }
</script>
</html>```

- 热力图
- 环形图

```javascript
<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>环形图</title>
    <style>
        #left{
            width: 473px;
            height: 306px;
        }
    </style>
</head>
<body >

<div id="left"></div>
</body>
<script src="../script/echarts.js"></script>
<script type="text/javascript">

    var dom = document.getElementById("left");
    var myChart = echarts.init(dom);

    var option = {
        backgroundColor: '#404a59',  //整体背景
        title: {                     //标题
            text: '成果/需求地域分布图',
            left: 'center',
            top:10,
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} 
{b}: {c} ({d}%)"
}, legend: { orient: 'vertical', x: 'right', y:'bottom', textStyle: { color: '#fff' }, data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎'] }, series: [ { name:'访问来源', type:'pie', radius: ['50%', '70%'], //小圆半径 大圆半径 avoidLabelOverlap: false, center:['center',170], //设置圆心位置 // label: { //一种方式 // normal: { // show: false, // position: 'center' // }, // emphasis: { // show: true, // textStyle: { // fontSize: '30', // fontWeight: 'bold' // } // } // }, label: { //二种方式 normal: { show: true, formatter:'{d}%', position: 'center' //标签的位置 outside } }, labelLine: { normal: { smooth: 0.2, length: 10, length2: 10 } }, data:[ {value:335, name:'直接访问'}, {value:310, name:'邮件营销', itemStyle:{ normal: { color: 'blue' //圆点颜色 } }}, {value:234, name:'联盟广告'}, {value:135, name:'视频广告'}, {value:1548, name:'搜索引擎'} ], animationType: 'scale', animationEasing: 'elasticOut' } ] }; if (option && typeof option === "object") { myChart.setOption(option, true); } </script> </html>``` - 象形柱图 - 路线图 - 雷达图 ```javascript <!DOCTYPE html> <html style="height: 100%"> <head> <meta charset="utf-8"> <title>雷达图</title> <style> #container{ width: 1000px; height: 800px; } </style> </head> <body > <div id="container"></div> </body> <script src="../script/echarts.js"></script> <script type="text/javascript"> // http://www.echartsjs.com/gallery/editor.html?c=radar-aqi var dom = document.getElementById("container"); var myChart = echarts.init(dom); var option = { backgroundColor: '#161627', title: { text: '雷达图' }, tooltip: { trigger: 'item' }, radar:{ //雷达图使用 radar 组件作为其坐标系 indicator: [ //雷达图的指示器 {name: '外观', max: 100}, {name: '拍照', max: 100}, {name: '系统', max: 100}, {name: '性能', max: 100}, {name: '屏幕', max: 100} ], name: { //雷达图每个指示器名称的配置项。 color: 'rgb(238, 197, 102)' }, nameGap:5, //指示器名称和指示器轴的距离。 splitLine: { //坐标轴在 grid 区域中的分隔线样式。 lineStyle: { color: [ 'rgba(238, 197, 102, 0.2)', 'rgba(238, 197, 102, 0.3)', 'rgba(238, 197, 102, 0.4)', 'rgba(238, 197, 102, 0.6)', 'rgba(238, 197, 102, 0.8)', 'rgba(238, 197, 102, 1)' ].reverse() } }, splitArea: { //不显示区域 show: false }, axisLine : { //刻度线样式 lineStyle: { color : 'rgb(238, 197, 102)' } }, shape:'circle', //雷达图绘制类型 支持 'polygon' 和 'circle' center: ['50%','50%'], radius: '80%', startAngle: 90 }, series: [ { name:'雷达', type: 'radar', symbol:'circle', //标记的图形。 itemStyle: { //折线拐点标记的样式。 normal: { color: '#B3E4A1' } }, lineStyle:{ //线条样式。 normal: { type:'dotted', width: 1, opacity: 0.8 } }, areaStyle: { //区域填充样式。 normal: { opacity: 0.8 } }, label:{ //图形上的文本标签,可用于说明图形的一些数据信息 normal: { show:false } }, data: [ { value: [85, 90, 90, 95, 95], name: '某手机' } ] } ] }; if (option && typeof option === "object") { myChart.setOption(option, true); }; </script> </html>``` ---

你可能感兴趣的:(echarts,前端,javascript)