echarts实现中国地图轮播省份地图(vue)

代码如下:

<div class="map-container">
     <div ref="chinaMap" id="chinaMap"></div>
</div>
<script>
import * as echarts from 'echarts'
import china from '../../../assets/json/china.json'
export default {
    data() {
        return {
            myChart: null,
            myTime: '',
        }
    },
    mounted() {
        window.exposedGoPath = (data)=> {
            this.$router.push({
                name: 'classification',
                params: {
                    areaType: data
                }
            })
        }
        window.addEventListener("resize", () => {
            this.myChart.resize();
        });
        echarts.registerMap('china', china)
        this.initEchartMap()
    },
    methods: {
        initEchartMap(){
            let areaLists = this.areaLists
            let maxValue = 0
            let maxObj = null
            for (let i = 0; i < areaLists.length; i++) {
                if (areaLists[i].value > maxValue) {
                    maxValue = areaLists[i].value;
                    maxObj = areaLists[i];
                }
            }
            let domEcharts = document.querySelector('#chinaMap')
            if(domEcharts) {
                this.myChart = echarts.init(domEcharts);
            }
            var options= {
                tooltip: {
                    show: true,
                    trigger: 'item',
                    enterable: true,
                    transitionDuration: 1,
                    textStyle:{
                        color:'#000000',
                        fontSize:13
                    },
                    extraCssText: `
                        min-width: 284px;
                        min-height: 212px;
                        border-radius: 0;
                        background: url(${require('../../../assets/frame/images/pic_frame.png')}) no-repeat center center;
                        background-size: 100% 100%;
                        padding: 30px;
                        box-sizing: border-box;
                    `,
                    formatter: (params)=> {
                        if (!params.data) return '';
                        const { titleStr, tm, yw, cnt } = params.data;
                        const commonStyles = `
                            .item-p {
                                text-align: center;
                                background: url(${require('../../../assets/frame/images/pic_gezi.png')}) no-repeat center center;
                                background-size: 100% 100%;
                                font-family: HCBBXJ-2019;
                                color: #333333;
                            }
                            .item-77 {
                                width: 77px;
                                height: 77px;
                                line-height: 74px;
                                font-size: 59px;
                            }
                            .item-55 {
                                width: 55px;
                                height: 55px;
                                line-height: 55px;
                                font-size: 40px;
                            }
                            .data-container span {
                                font-size: 16px;
                                line-height: 30px;
                            }
                            .btn-link {
                                width: 64px;
                                height: 24px;
                                background: #378398;
                                margin: 6px 0 0 10px;
                                padding: 2px 18px;
                                box-sizing: border-box;
                                cursor: pointer;
                            }
                            .btn-link img {
                                width: 28px;
                                height: 12px;
                                margin: 0 auto;
                            }
                        `;
                        let itemsHtml = '';
                        if (titleStr && titleStr.length > 0) {
                            const itemClass = titleStr.length < 3 ? 'item-77' : 'item-55';
                            itemsHtml = titleStr.map(item => `
                                <p class="item-p ${itemClass}">${item}</p>
                            `).join('');
                        }
                        const context = `
                            <style>${commonStyles}</style>
                            <div style="display: flex;">
                                <div>${itemsHtml}</div>
                                <div style="width: calc(100% - 147px); height: 100%; margin-left: 10px">
                                    <div class="data-container">
                                        <div><span>【目录数】</span><span>${tm}</span></div>
                                        <div><span>【原文数】</span><span>${yw}</span></div>
                                        <div><span>【检索数】</span><span>${cnt}</span></div>
                                        <div><span>【村庄数】</span><span>${cnt}</span></div>
                                    </div>
                                    <div class="btn-link" onclick="exposedGoPath('${params.name}')">
                                        <img src="${require('../../../assets/frame/images/arrows.png')}" alt="">
                                    </div>
                                </div>
                            </div>
                        `;
                        return context;
                    },
                },
                visualMap: {
                    show: false,
                    min: 0,
                    max: maxObj && maxObj.value,
                    realtime: false,
                    calculable: true,
                    inRange: {
                        color: ['#aed1db', '#215b6b']
                    }, 
                },
                geo: {
                    map: "china",
                    scaleLimit: {
                        min: 1,
                        max: 2
                    },
                    zoom: 1.3,
                    top: 120,
                    layoutSize: "100%", //保持地图宽高比
                    label: {
                        normal: {
                            show: true,
                            fontSize: "14",
                            color: "rgba(0,0,0,0.7)"
                        },
                        emphasis: {
                            show: true,
                            textStyle: {
                                color: '#FFF'
                            }
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: "#FFF",
                            areaColor: '#aed1db',
                        },
                        emphasis: {
                            areaColor: "#ffdf33",
                            shadowOffsetX: 0,
                            shadowOffsetY: 0,
                            borderWidth: 0
                        }
                    },
                    regions: [
                        {
                            name: "南海诸岛",
                            itemStyle: {
                            // 隐藏地图
                            normal: {
                                opacity: 0, // 为 0 时不绘制该图形
                            }
                            },
                            label: {
                                show: false // 隐藏文字
                            }
                        }
                    ]
                },
                series: [
                    {
                        name: "地图",
                        type: "map",
                        geoIndex: 0,
                        data: areaLists
                    }
                ]  
            }
            this.myChart && this.myChart.setOption(options);
            var count = 0;
            var timeTicket = null;
            var dataLength = options.series[0].data.length;
            timeTicket && clearInterval(timeTicket);
            timeTicket = setInterval(()=> {
                this.myChart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                });
                this.myChart.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                this.myChart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                count++;
            }, 1000);

            this.myChart.on('mouseover', (params)=> {
                clearInterval(timeTicket);
                this.myChart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0
                });
                this.myChart.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: params.dataIndex
                });
                this.myChart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: params.dataIndex,
                });
            });
            this.myChart.on('mouseout', (params)=> {
                timeTicket && clearInterval(timeTicket);
                timeTicket = setInterval(()=> {
                    this.myChart.dispatchAction({
                        type: 'downplay',
                        seriesIndex: 0,
                    });
                    this.myChart.dispatchAction({
                        type: 'highlight',
                        seriesIndex: 0,
                        dataIndex: (count) % dataLength
                    });
                    this.myChart.dispatchAction({
                        type: 'showTip',
                        seriesIndex: 0,
                        dataIndex: (count) % dataLength
                    });
                    count++;
                }, 2000);
            });
        },
    },
}
</script>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中使用echarts获取省份地图,你可以按照以下步骤进行操作。 首先,你需要引入需要的echarts包和对应的省份地图。你可以使用import语句引入echarts包,并在Vue的组件中使用import语句引入对应的省份地图。例如,你可以使用以下代码引入echarts和湖北省的地图: ```javascript import echarts from "echarts/lib/echarts" import "echarts/map/js/province/hubei.js"; ``` 接下来,你需要在main.js文件中引入echarts并将其挂载到Vue的原型上。你可以使用以下代码实现: ```javascript import * as echarts from 'echarts' Vue.prototype.$echarts = echarts ``` 这样,你就可以在Vue组件中通过`this.$echarts`来使用echarts。 然后,你可以在Vue组件中使用echarts实现获取省份地图的功能。你可以在该组件的方法中使用echarts的相关API来绘制地图和处理交互。具体的实现方式可以参考echarts官方文档的示例和地图相关的API。你可以在echarts官网的示例页面(https://echarts.apache.org/examples/zh/index.html)和地图相关的API文档(https://echarts.apache.org/zh/option.html#series-map)中找到更多的参考资料。 总结起来,你需要引入echarts包和对应的省份地图,将echarts挂载到Vue的原型上,并在Vue组件中使用echarts的API来实现获取省份地图的功能。希望这些信息对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vue - vue使用echarts实现中国地图和点击省份进行查看](https://blog.csdn.net/qq_43886365/article/details/128102076)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [vue echarts 3D地图+省+弹窗](https://blog.csdn.net/coldriversnow/article/details/117927061)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值