首页 > 其他分享 >echarts中国地图,横柱形图+饼图联动,分省市

echarts中国地图,横柱形图+饼图联动,分省市

时间:2022-08-23 15:25:40浏览次数:81  
标签:name normal color value ele 柱形图 联动 data echarts

 var data = [{
    "time": 1980,
    "data": [{
        "name": "台湾",
        "value": [633.76, 12.28, "台湾"]
    }, {
        "name": "香港",
        "value": [432.47, 8.38, "香港"]
    }, {
        "name": "江苏",
        "value": [319.80, 6.20, "江苏"]
    }, {
        "name": "上海",
        "value": [311.89, 6.05, "上海"]
    }, {
        "name": "山东",
        "value": [292.13, 5.66, "山东"]
    }, {
        "name": "辽宁",
        "value": [281, 5.45, "辽宁"]
    }, {
        "name": "广东",
        "value": [249.65, 4.84, "广东"]
    }, {
        "name": "四川",
        "value": [229.31, 4.44, "四川"]
    }, {
        "name": "河南",
        "value": [229.16, 4.44, "河南"]
    }, {
        "name": "黑龙江",
        "value": [221.00, 4.28, "黑龙江"]
    }]
}, {
    "time": 2000,
    "data": [{
        "name": "台湾",
        "value": [27435.15, 19.47, "台湾"]
    }, {
        "name": "香港",
        "value": [14201.59, 10.08, "香港"]
    }, {
        "name": "广东",
        "value": [10741.25, 7.62, "广东"]
    }, {
        "name": "江苏",
        "value": [8553.69, 6.07, "江苏"]
    }, {
        "name": "山东",
        "value": [8337.47, 5.92, "山东"]
    }, {
        "name": "浙江",
        "value": [6141.03, 4.36, "浙江"]
    }, {
        "name": "河南",
        "value": [5052.99, 3.59, "河南"]
    }, {
        "name": "河北",
        "value": [5043.96, 3.58, "河北"]
    }, {
        "name": "上海",
        "value": [4771.17, 3.39, "上海"]
    }, {
        "name": "辽宁",
        "value": [4669.10, 3.31, "辽宁"]
    }]
},{
    "time": 2005,
    "data": [{
        "name": "台湾",
        "value": [30792.89, 12.52, "台湾"]
    }, {
        "name": "广东",
        "value": [22527.37, 9.16, "广东"]
    }, {
        "name": "江苏",
        "value": [18598.69, 7.56, "江苏"]
    }, {
        "name": "山东",
        "value": [18366.87, 7.47, "山东"]
    }, {
        "name": "香港",
        "value": [14869.68, 6.05, "香港"]
    }, {
        "name": "浙江",
        "value": [13417.68, 5.46, "浙江"]
    }, {
        "name": "河南",
        "value": [10587.42, 4.30, "河南"]
    }, {
        "name": "河北",
        "value": [10043.42, 4.08, "河北"]
    }, {
        "name": "上海",
        "value": [9247.66, 3.76, "上海"]
    }, {
        "name": "辽宁",
        "value": [8047.3, 3.27, "辽宁"]
    }]
} ,{
    "time": 2010,
    "data": [{
        "name": "广东",
        "value": [46036.25, 9.49, "广东"]
    }, {
        "name": "江苏",
        "value": [41425.48, 8.54, "江苏"]
    }, {
        "name": "山东",
        "value": [39169.92, 8.08, "山东"]
    }, {
        "name": "台湾",
        "value": [30205.64, 6.23, "台湾"]
    }, {
        "name": "浙江",
        "value": [27747.65, 5.72, "浙江"]
    }, {
        "name": "河南",
        "value": [23092.36, 4.76, "河南"]
    }, {
        "name": "河北",
        "value": [20394.26, 4.21, "河北"]
    }, {
        "name": "辽宁",
        "value": [18457.3, 3.81, "辽宁"]
    }, {
        "name": "四川",
        "value": [17185.48, 3.54, "四川"]
    }, {
        "name": "上海",
        "value": [17165.98, 3.54, "上海"]
    }]
} ,{
    "time": 2015,
    "data": [{
        "name": "广东",
        "value": [72812.55, 9.35, "广东"]
    }, {
        "name": "江苏",
        "value": [70116.38, 9, "江苏"]
    }, {
        "name": "山东",
        "value": [63002.3, 8.09, "山东"]
    }, {
        "name": "浙江",
        "value": [42886, 5.51, "浙江"]
    }, {
        "name": "河南",
        "value": [37010.25, 4.75, "河南"]
    }, {
        "name": "台湾",
        "value": [32604.52, 4.19, "台湾"]
    }, {
        "name": "四川",
        "value": [30103.1, 3.87, "四川"]
    }, {
        "name": "河北",
        "value": [29806.1, 3.83, "河北"]
    }, {
        "name": "湖北",
        "value": [29550.19, 3.8, "湖北"]
    }, {
        "name": "湖南",
        "value": [29047.20, 3.73, "湖南"]
    }]
} ]


var option = {
    backgroundColor: '#25499F',
    baseOption: {
        animationDurationUpdate: 1000,
        animationEasingUpdate: 'quinticInOut',
        timeline: {
            axisType: 'category',
            orient: 'vertical',
            autoPlay: true,
            inverse: true,
            playInterval: 5000,
            left: null,
            right: 5,
            top: 20,
            bottom: 20,
            width: 46,
            height: null,
            label: {
                normal: {
                    textStyle: {
                        color: '#ddd'
                    }
                },
                emphasis: {
                    textStyle: {
                        color: '#fff'
                    }
                }
            },
            symbol: 'none',
            lineStyle: {
                color: '#555'
            },
            checkpointStyle: {
                color: '#bbb',
                borderColor: '#777',
                borderWidth: 1
            },
            controlStyle: {
                showNextBtn: false,
                showPrevBtn: false,
                normal: {
                    color: '#666',
                    borderColor: '#666'
                },
                emphasis: {
                    color: '#aaa',
                    borderColor: '#aaa'
                }
            },
            data: data.map(function(ele) {
                return ele.time
            })
        },
        backgroundColor: '#25499F',
        title: {
            text: '1980年以来中国各省GDP排名变化情况',
            subtext: 'GDP单位:亿元',
            left: 'center',
            top: 'top',
            textStyle: {
                fontSize: 25,
                color: 'rgba(255,255,255, 0.9)'
            }
        },
        tooltip: {
            formatter: function(params) {
                if ('value' in params.data) {
                    return params.data.value[2] + ': ' + params.data.value[0];
                }
            }
        },
        grid: {
            left: 10,
            right: '45%',
            top: '70%',
            bottom: 5
        },
        xAxis: {},
        yAxis: {},
        series: [{
            id: 'map',
            type: 'map',
            mapType: 'china',
            top: '10%',
            //bottom: '25%',
            //left: '5%',
            //right: '10%',
            itemStyle: {
                normal: {
                    areaColor: '#323c48',
                    borderColor: '#404a59'
                },
                emphasis: {
                    label: {
                        show: true
                    },
                    areaColor: 'rgba(255,255,255, 0.5)'
                }
            },
            data: []
        }, {
            id: 'bar',
            type: 'bar',
            tooltip: {
                show: false
            },
            label: {
                normal: {
                    show: true,
                    position: 'right',
                    textStyle: {
                        color: '#ddd'
                    }
                }
            },
            data: []
        }, {
            id: 'pie',
            type: 'pie',
            radius: ['12%', '20%'],
            center: ['75%', '85%'],
            //roseType: 'area',
            tooltip: {
                formatter: '{b} {d}%'
            },
            data: [],
            label: {
                normal: {
                    textStyle: {
                        color: '#ddd'
                    }
                }
            },
            labelLine: {
                normal: {
                    lineStyle: {
                        color: '#ddd'
                    }
                }
            },
            itemStyle: {
                normal: {
                    borderColor: 'rgba(0,0,0,0.3)',
                    borderSize: 1
                }
            }
        }]
    },
    options: []
}

for (var i = 0; i < data.length; i++) {
    //计算其余省份GDP
    var restPercent = 100;
    var restValue = 0;
    data[i].data.forEach(function(ele) {
        restPercent = restPercent - ele.value[1];
    });
    restValue = data[i].data[0].value[0] * (restPercent / data[i].data[0].value[1]);
    console.log(restPercent);
    console.log(restValue);
    option.options.push({
        visualMap: [{
            //type:'continous',
            //type: 'continuous',
            calculable: true,
            dimension: 0,
            left: 10,
            top: 'center',
            itemWidth: 12,
            min: data[i].data[9].value[0],
            max: data[i].data[0].value[0],
            text: ['High', 'Low'],
            textStyle: {
                color: '#ddd'
            },
            inRange: {
//                color: ['lightskyblue', 'yellow', 'orangered', 'red']
                color: ['lightskyblue', 'yellow', 'orangered']
            }
        }],
        xAxis: {
            type: 'value',
            boundaryGap: [0, 0.1],
            axisLabel: {
                show: false,
            },
            splitLine: {
                show: false
            }
        },
        yAxis: {
            type: 'category',
            axisLabel: {
                show: false,
                textStyle: {
                    color: '#ddd'
                }
            },

            data: data[i].data.map(function(ele) {
                return ele.value[2]
            }).reverse()
        },
        series: [{
            id: 'map',
            data: data[i].data
        }, {
            id: 'bar',
            label: {
                normal: {
                    position: 'right',
                    formatter: '{b} : {c}'
                }
            },
            data: data[i].data.map(function(ele) {
                return ele.value[0]
            }).sort(function(a, b) {
                return a > b
            })
        }, {
            id: 'pie',
            data: data[i].data.map(function(ele) {
                return {
                    name: ele.value[2],
                    value: ele.value
                }
            }).concat({
                name: '其他省份',
                value: restValue
            }),
        }]
    })
}

  

 

标签:name,normal,color,value,ele,柱形图,联动,data,echarts
From: https://www.cnblogs.com/facenano/p/16616280.html

相关文章

  • echarts饼图,半圈半圆,百分比显示
    vardata=[{value:24.5,//正确率的百分比name:'高等教育学'},{value:89,name:'高等教育心理学'},{value:38,name:'综合学科'......
  • echarts刻度盘,半圈半圆,百分比
    vardemoData={name:'城镇化率',value:60,};option={backgroundColor:'#222939',title:{text:'{num|'+demoData.value+'%}'......
  • echarts异形图水滴图,百分比显示,波浪水球
    varvalue=0.45;varvalue1=0.76;vardata=[value,value1];varoption={backgroundColor:'#0F224C',title:[{text:'本......
  • echarts饼图,完整圆形,百分比显示
    option={tooltip:{trigger:'item',formatter:"{a}<br/>{b}:{c}({d}%)"},color:['#8fc31f','#f35833','......
  • echarts环形饼图,完整圆形,百分比分值
    varscale=1;varechartData=[{value:21,name:'市场签约1'},{value:38,name:'市场签约2'},{value:35,name:'市场签约3'},......
  • echarts 数据的各种格式
    数据集数据集(dataset)是专门用来管理数据的组件。虽然每个系列都可以在series.data中设置数据,但是从ECharts4支持数据集开始,更推荐使用数据集来管理数据。因为这样......
  • ECharts 中的样式简介
    ECharts中的样式简介本文主要是大略概述,用哪些方法,可以在ApacheEChartsTM中设置样式,改变图形元素或者文字的颜色、明暗、大小等。为了让表述更通俗易懂,我们在这里用......
  • echarts 图表容器及大小
    图表容器及大小在快速上手中,我们介绍了初始化ECharts的接口echarts.init。API文档中详细介绍了参数的具体含义,建议理解后再阅读本文。下面,我们就常见的几种使用场景,......
  • 学习:python pyecharts数据可视化
    pyecharts数据可视化pyecharts是一个用于生成Echarts图标的类库Echarts是百度开源的一个数据可视化的Js库用Echarts生成的图可视化效果非常棒 新版v1和老版本......
  • 在vue中使用echarts
    1.引入echarts先通过npm安装echartsnpmrunecharts--save2.在main.js中import*asechartsfrom'echarts';Vue.prototype.$echarts=echarts3.在.vue文件中(包括......