echarts地图自动轮播

地图自动轮播

需求:地图有数据的置灰并且不轮播,有数据的轮播展示数据

/* 
请勿在原图上直接修改保存
*/
function mapTooltipClick(name) {
    alert(name)
}

function tooltipCharts() {
    console.log(arguments[0]);
    var myChart1 = echarts.init(document.getElementById('tooltipBarId'));
    var option = {
        tooltip: {},
        xAxis: {
            type: 'category',
            interval: true,
            axisLabel: {
                rotate: 45
            },
            axisTick: {
                show: false
            }
        },
        yAxis: {},
        color: ['#4FA8F9', '#F5A623'],
        grid: {
            show: true,
            backgroundColor: '#FAFAFA',
            left: 30,
            right: 20,
            top: 20
        },
        series: [{
            type: 'bar',
            smooth: true,
            seriesLayoutBy: 'row',
            barWidth: 10
        }]
    };
    myChart1.setOption(option);
}
option = {
    visualMap: {
        min: 0,
        max: 1000,
        left: 'left',
        top: 'bottom',
        text: ['高', '低'],
        calculable: false,
        orient: 'horizontal',
        inRange: {
            color: ['#ccc', '#006edd'],
            // symbolSize: [30, 100]
        }
    },
    tooltip: {
        padding:8,
        enterable: true,
        transitionDuration: 1,
        textStyle: {
            color: '#fff',
            decoration: 'none',
        }
    },
    series: [{
        name: '接入医院数量',
        type: 'map',
        mapType: 'china',
        itemStyle: {
            normal: {
                label: {
                    show: false
                }
            },
            emphasis: {
                label: {
                    show: true
                }
            }
        },
        label: {
			normal: { //静态的时候展示样式
				show: true, //是否显示地图省份得名称
				textStyle: {
					color: "#fff",
					fontSize: 12
				}
			},
			emphasis: { //动态展示的样式
				color: '#fff',
			},
		},
        data: [{
                name: '北京',
                value: 50,
            },
            {
                name: '天津',
                value: 100,
            },
            {
                name: '上海',
                value: 200,
            },
            {
                name: '重庆',
                value: 300,
            },
            {
                name: '河北',
                value: 400,
            },
            {
                name: '河南',
                value: 500,
            },
            {
                name: '云南',
                value: 600,
            },
            {
                name: '辽宁',
                value: 700,
            },
            {
                name: '黑龙江',
                value: 800,
            },
            {
                name: '湖南',
                value:900,
            },
            {
                name: '安徽',
                value: 1000,
            }
        ]
    }, ]
}
var count = 0;
var timeTicket = null;
var dataLength = option.series[0].data.length;
timeTicket && clearInterval(timeTicket);
timeTicket = setInterval(function() {
    myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
    });
    myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: (count) % dataLength
    });
    myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: (count) % dataLength
    });
    count++;
}, 2000);

myChart.on('mouseover', function(params) {
    console.log(params)
    clearInterval(timeTicket);
    myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0
    });
    myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: params.dataIndex
    });
    myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: params.dataIndex,
    });
});
myChart.on('mouseout', function(params) {
    timeTicket && clearInterval(timeTicket);
    timeTicket = setInterval(function() {
        myChart.dispatchAction({
            type: 'downplay',
            seriesIndex: 0,
        });
        myChart.dispatchAction({
            type: 'highlight',
            seriesIndex: 0,
            dataIndex: (count) % dataLength
        });
        myChart.dispatchAction({
            type: 'showTip',
            seriesIndex: 0,
            dataIndex: (count) % dataLength
        });
        count++;
    }, 1000);
});
ECharts 是一个非常强大的数据可视化库,其地图组件提供了丰富的交互功能,包括地图 tooltip(工具提示)。在 ECharts 地图中,tooltip 可以设置为轮播模式,这意味着当鼠标悬停在地图上时,会显示一系列相关的数据点,而不是只显示单个数据点的信息。 轮播 tooltip 的配置通常涉及到以下步骤: 1. **设置 tooltip 类型**:在地图配置中,指定 tooltip 的类型为 `map`,并设置 `show` 为 `true`。 ```javascript option = { tooltip: { type: 'map', show: true, trigger: 'item', // 或者 'emphasis' axisPointer: { // 鼠标移动到地图上时的指示线 type: 'shadow' }, formatter: function (params) { // 自定义 tooltip 内容显示 return params.name + '<br>' + params.value; } }, ... }; ``` 2. **关联地理编码信息**:在地图数据中,每个区域需要有一个 `name` 属性对应地图上的名称,并可能包含其他用于轮播的数据,如 `data` 数组。 ```javascript series: [{ name: '地图数据', type: 'map', mapType: 'yourMapType', // 例如 'world', 'china' 等 data: [ { name: '区域1', value: value1, // 区域1的数据 } { name: '区域2', value: value2, // 区域2的数据 } ... ], ... }] ``` 3. **轮播配置**:ECharts 提供了 `formatter` 函数,你可以自定义这个函数,使其根据数据内容动态展示。如果数据数组较大,你可以控制 tooltip 显示哪些数据点,例如,可以通过索引或轮播显示前几项。 ```javascript formatter: function (params) { let content = ''; for (let i = 0; i < params.data.length && i < 3; i++) { // 轮播3个数据点 content += `<div>${params.data[i].name}: ${params.data[i].value}</div>`; } return content; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值