areaCharts.vue 4.76 KB
<template>
    <div class="_chart">
        <div class="_chartTitle">
            <h3>地域分布</h3>
            <span>展示近30天销售地域分布数据</span>
        </div>
    </div>
    <div class="_mainChart" style="margin-bottom: 0">
        <div id="yohoTop" style="width: 500px;height:400px;float: left;margin-left: 80px"></div>
        <div id="shopTop" style="width: 500px;height:400px;float: left;margin-left: 150px"></div>
        <div class="clearfix"></div>
    </div>
</template>

<script type="text/javascript">
    var echarts = require('echarts');
    import util from 'util';

    module.exports = {
        data:function() {
            return {}
        },
        ready:function(){
            this.getData();
        },
        methods:{
            getData(){
                this.$http.post("/chart/getShopTopArea", {
                    dateId: util.dateFormat(new Date(),"YYYYMMdd")
                }).then(function (response) {
                    var data = response.data.data;
                    //全站销售地域                    
                    var yohoTop = echarts.init(document.getElementById('yohoTop'));
                    if(data.yoho.y.length==0){
                        var yohoOption = this.getXOption(data.yoho.x, data.yoho.y, "全站销售地域Top10:暂无数据");
                    }else{
                        var yohoOption = this.getXOption(data.yoho.x, data.yoho.y, "全站销售地域Top10:");
                    }                        
                    yohoTop.setOption(yohoOption);                                
                    

                    //店铺销售地域                
                    var shopTop = echarts.init(document.getElementById('shopTop'));
                    if(data.shop.y.length==0){
                        var shopOption = this.getXOption(data.shop.x, data.shop.y, "店铺销售地域Top10:暂无数据");
                    }else{
                        var shopOption = this.getXOption(data.shop.x, data.shop.y, "店铺销售地域Top10:");
                    }                    
                    shopTop.setOption(shopOption);

                });         
            },
            getXOption(provinces, data, title){
                var option = {
                    title : {
                        show: true,
                        text: title,
                        x:'center'
                    },
                    xAxis : [
                        {
                            type:'value',
                            show:false
                        }
                    ],
                    yAxis : [
                        {
                            type:'category',
                            data:provinces,
                            axisLine:{
                                show:false
                            },
                            axisTick:{
                                show:false
                            },
                            splitLine:{
                                show:false
                            }
                        }
                    ],
                    series : [
                        {
                            name:'销量',
                            type:'bar',
                            data:data,
                            itemStyle: {
                                normal: {
                                    color: '#999999',
                                    label : {
                                        show: true,
                                        position: 'right',
                                        textStyle:{
                                            color:"#585858",
                                            align:"right"
                                        },
                                        formatter:function (params) {
                                            return params.value + '%';
                                        }
                                    }
                                }
                            }
                        }
                    ]
                };
                return option;
            }
        }
    }
</script>

<style>
    ._chart{
        clear: both;
        width: 100%;
        font-family: 'microsoft yahei';
        color: #585858;
    }
    ._chartTitle{
        width: 100%;
        padding: 0 20px;
        height: 40px;
        background-color: #ccc;
    }
    ._chartTitle h3{
        float: left;
        line-height: 40px;
        font-size: 20px;
        margin: 0;
        font-weight: bold
    }
    ._chartTitle span{
        display: block;
        float: right;
        line-height: 40px;
        font-size: 14px;
    }
    ._mainChart{
        margin: 20px 0;
    }
</style>