数据可视化项目---订单分类占比图

效果如下
在这里插入图片描述

订单分类占比图—组件代码

<!--订单分类占比图-->
<template>
    <div class="com-container">
        <div class="com-chart" ref="hot_ref"></div>
        <span class="iconfont arr-left" @click="toLeft" :style="comStyle">&#xe6ef;</span>
        <span class="iconfont arr-right"@click="toRight" :style="comStyle">&#xe6ed;</span>
        <span class="cat-name" :style="comStyle">{{catName}}</span>
    </div>
</template>

<script>
    export default {
        name: "Hot",
        data() {
            return {
                chartInstance:null,
                allData:null,
                currentIndex:0,//当前所展示的占比图的数据
                titleFontSize:0,
            }
        },
        computed:{
            catName(){
                if (this.allData==null){
                    return ''
                }else {
                    return this.allData[this.currentIndex].name
                }
            },
            comStyle() {
                return {
                    fontSize:this.titleFontSize+'px'
                };
            }
        },
        mounted(){
            this.initChart();
            this.getData();
            window.addEventListener('resize',this.screenAdapter);
            //在页面加载完成忠厚,主动进行屏幕的适配
            this.screenAdapter();
        },
        destroy(){
            //在组件销毁的时候,将窗口监听器取消掉
            window.removeEventListener('resize',this.screenAdapter);
        },
        methods: {
            //初始化echartInstance对象
            initChart(){
                this.chartInstance=this.echarts.init(this.$refs.hot_ref,'chalk');
                const initOption={
                    title:{
                        text:'┃ 订单分类占比',
                        left:20,
                        top:20,
                    },
                    legend:{
                        top:'15%',
                        icon:'circle',
                    },
                    tooltip:{
                        show:true,
                        formatter:(arg)=>{
                            if (this.currentIndex==0){
                                return arg.name+":00点 : "+arg.percent+" %"
                            }
                            return arg.name+" : "+arg.percent+" %"
                        }
                    },
                    series:[
                        {
                            type:'pie',
                            label:{
                                show:false
                            },
                            emphasis:{
                                label:{
                                    show:true
                                },
                                labelLine:{
                                    show:false
                                }
                            }
                        }
                    ]
                };
                this.chartInstance.setOption(initOption);
            },
            //获取服务器数据
            async getData(){
                await this.axios.get("/chart/hot").then(res=>{
                    this.allData=res.data;
                });
                this.updateChart();
            },
            //处理数据
            updateChart(){
                const legendData=this.allData[this.currentIndex].children.map(item=>{
                    return item.name;
                });
                const seriesData=this.allData[this.currentIndex].children.map(item=>{
                   return{
                       name:item.name,
                       value:item.value,
                   }
                });
                const dataOption={
                    legend:{
                        data:legendData,
                    },
                    series:[
                        {
                            data:seriesData
                        }
                    ]
                };
                this.chartInstance.setOption(dataOption);
            },
            //当浏览器的大小发生变化的时候,调用该方法,来完成屏幕的适配
            screenAdapter(){
                this.titleFontSize=this.$refs.hot_ref.offsetWidth/100*3.6;
                //和分辨率大小相关的配置项
                const adapterOption={
                    title:{
                        textStyle:{
                            fontSize:this.titleFontSize
                        }
                    },
                    legend:{
                        itemWidth:this.titleFontSize,
                        itemHeight:this.titleFontSize,
                        itemGap:this.titleFontSize/2,
                        textStyle:{
                            fontSize:this.titleFontSize/2
                        }
                    },
                    series:[
                        {
                            radius:this.titleFontSize * 4.5,
                            center:['50%','60%']
                        }
                    ]
                };
                this.chartInstance.setOption(adapterOption);
                //手动的调用图表的resize方法
                this.chartInstance.resize();
            },
            toLeft(){
                this.currentIndex--;
                if (this.currentIndex < 0) {
                    this.currentIndex=this.allData.length-1;
                }
                this.updateChart();
            },
            toRight(){
                this.currentIndex++;
                if (this.currentIndex > this.allData.length-1) {
                    this.currentIndex=0;
                }
                this.updateChart();
            }
        }
    }

</script>

<style scoped>
    .com-container{
        width: 100%;
        height: 100%;
        overflow: hidden;
        position: relative;
    }
    .com-chart{
        width: 100%;
        height: 100%;
        overflow: hidden;
        border-radius: 20px;
    }
    .arr-left{
        position: absolute;
        left: 10%;
        top:50%;
        transform: translateY(-50%);
        cursor: pointer;
        color: white;
    }
    .arr-right{
        position: absolute;
        right: 10%;
        top:50%;
        transform: translateY(-50%);
        cursor: pointer;
        color: white;
    }
    .cat-name{
        position: absolute;
        left: 80%;
        bottom: 20px;
        color: white;
    }
</style>

订单分类占比图—接口数据

[{"name":"出发时间","children":[{"name":"8","value":"82"},{"name":"11","value":"802"},{"name":"17","value":"215"},{"name":"21","value":"6"},{"name":"22","value":"3"},{"name":"23","value":"12"}]},{"name":"地区销量","children":[{"name":"周口中心站","value":"14"},{"name":"周口市中心站","value":"218"},{"name":"周口市淮阳","value":"230"},{"name":"周口市项城","value":"85"},{"name":"周口火车站","value":"567"},{"name":"周口项城","value":"6"}]},{"name":"售票员业绩","children":[{"name":"刘总","value":"1105"},{"name":"刘师傅","value":"6"},{"name":"小陈","value":"5"},{"name":"小丁","value":"4"}]},{"name":"客源分析","children":[{"name":"周口中心站","value":"204"},{"name":"河南交通学院","value":"233"},{"name":"郑州工商学院","value":"470"},{"name":"郑州旅游学院","value":"213"}]}]

订单分类占比图—设计流程

参考https://blog.csdn.net/liudachu/article/details/109273102

下一篇:数据可视化项目—车辆实时信息图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
平台销售数据的可视化分析可以使用Python的matplotlib、seaborn、plotly等库来实现。这里以matplotlib为例进行说明。 假设我们有一个销售数据的Excel表格,其中包含订单号、销售额、订单日期等信息。首先,使用pandas读取Excel文件: ```python import pandas as pd data = pd.read_excel('sales_data.xlsx') ``` 接下来,我们可以绘制一些常见的数据可视化图表,如柱状图、饼图、折线图等。以柱状图为例,我们可以绘制每个月的销售额: ```python import matplotlib.pyplot as plt # 按月份统计销售额 monthly_sales = data.groupby(data['订单日期'].dt.month)['销售额'].sum() # 绘制柱状图 plt.bar(monthly_sales.index, monthly_sales.values) plt.xlabel('Month') plt.ylabel('Sales') plt.title('Monthly Sales') plt.show() ``` 如果我们想要更直观地看到不同产品类别的销售情况,可以绘制堆叠柱状图: ```python # 按产品类别和月份统计销售额 monthly_sales_by_category = data.groupby([data['订单日期'].dt.month, '产品类别'])['销售额'].sum().unstack() # 绘制堆叠柱状图 monthly_sales_by_category.plot(kind='bar', stacked=True) plt.xlabel('Month') plt.ylabel('Sales') plt.title('Monthly Sales by Category') plt.show() ``` 除了柱状图,我们还可以绘制饼图、折线图等其他类型的图表,以更全面地了解销售数据的情况。例如,我们可以绘制每个季度的销售额比饼图: ```python # 按季度统计销售额 quarterly_sales = data.groupby(data['订单日期'].dt.quarter)['销售额'].sum() # 绘制饼图 plt.pie(quarterly_sales.values, labels=quarterly_sales.index, autopct='%1.1f%%') plt.title('Quarterly Sales Proportion') plt.show() ``` 以上仅是销售数据可视化的一部分,根据实际需要可以进行更多的数据分析和绘图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值