16、vue引入echarts,划中国地图

vue引入echarts

npm install echarts --save

main.js引入

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

划中国地图

引入中国地图数据

import 'echarts/map/js/china.js'

<template>
    <div>
        <div id="myChart"></div>
    </div>

</template>
<script>
export default {
    data() {
        return {
           mydata: []
        }
    },
    mounted() {
        this.drawLine()
    
      },
    methods:{
               drawLine() {
          this.mydata = [  
                { name: '北京', value: '100' }, { name: '天津', value: this.randomData() },  
                { name: '上海', value: this.randomData() }, { name: '重庆', value: this.randomData() },  
                { name: '河北', value: this.randomData() }, { name: '河南', value: this.randomData() },  
                { name: '云南', value: this.randomData() }, { name: '辽宁', value: this.randomData() }  
                // {name: '黑龙江',value: this.randomData() },{name: '湖南',value: this.randomData() },  
                // {name: '安徽',value: this.randomData() },{name: '山东',value: this.randomData() },  
                // {name: '新疆',value: this.randomData() },{name: '江苏',value: this.randomData() },  
                // {name: '浙江',value: this.randomData() },{name: '江西',value: this.randomData() },  
                // {name: '湖北',value: this.randomData() },{name: '广西',value: this.randomData() },  
                // {name: '甘肃',value: this.randomData() },{name: '山西',value: this.randomData() },  
                // {name: '内蒙古',value: this.randomData() },{name: '陕西',value: this.randomData() },  
                // {name: '吉林',value: this.randomData() },{name: '福建',value: this.randomData() },  
                // {name: '贵州',value: this.randomData() },{name: '广东',value: this.randomData() },  
                // {name: '青海',value: this.randomData() },{name: '西藏',value: this.randomData() },  
                // {name: '四川',value: this.randomData() },{name: '宁夏',value: this.randomData() },  
                // {name: '海南',value: this.randomData() },{name: '台湾',value: this.randomData() },  
                // {name: '香港',value: this.randomData() },{name: '澳门',value: this.randomData() }  
            ]
        // 基于准备好的dom,初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('myChart'))
        // 绘制图表
        myChart.setOption({
            backgroundColor: '#F7F7F7',
            title: {
                text: '中国地图',
                subtext: '中国地图'
                // sublink: 'http://zh.wikipedia.org/wiki/%E9%A6%99%E6%B8%AF%E8%A1%8C%E6%94%BF%E5%8D%80%E5%8A%83#cite_note-12'
            },
            tooltip: {
                trigger: 'item',
                formatter: '{b}<br/>{c} '
            },
            // toolbox: {
            //     show: true,
            //     orient: 'vertical',
            //     left: 'right',
            //     top: 'center'
            //     // feature: {
            //     //     dataView: {readOnly: false},
            //     //     restore: {},
            //     //     saveAsImage: {}
            //     // }
            // },
            visualMap: {
                max: 500,
                min: 0,
                text: ['高', '低'],
                realtime: false,
                calculable: false,
                itemHeight: '200',
                inverse: true, // 翻转
                orient: 'horizontal',
                inRange: {
                    color: ['#DDDDDD', '#026FDD']
                }
            },
            series: [
                {
                    name: '损失统计',
                    type: 'map',
                    mapType: 'china', // 自定义扩展图表类型
                    itemStyle: {
                        normal: { label: { show: true } },
                        emphasis: { label: { show: true } }
                    },
                    data: this.mydata
                }
            ]
        })
    },
    randomData() {  
     return Math.round(Math.random() * 500);  
    } 
             
    },


}
</script>

image

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值