#echarts#折线图#饼图

python 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>折线图</title>
</head>
<body>
    <div id="app" style="width:100%;height:100%;">
        <div id="chart-container" style="width:1000px;height:800px;"></div>
    </div>
    <script src="./vue.js"></script>
    <script src="./echarts.js"></script>
    <script src="./sales.js"></script>
    <script>
        Vue.createApp({
            data(){
                return{
                    salesData:salesData,
                    salesCount:[]
                }
            },
            created(){
                this.salesData.forEach(data => {
                    let item = this.salesCount.find(ele => ele.name==data.storeName)
                    if(item){
                        item.count++
                    } else {
                        this.salesCount.push({
                            name:data.storeName,
                            count:1
                        })
                    }
                });
                console.log(this.salesCount)
            },
            mounted(){
                var chartDom = document.getElementById("chart-container");
                var myChart = echarts.init(chartDom);
                var option = {
                    title:{
                        text : "门店数量",
                        left : "center"
                    },
                    tooltip:{
                        trigger:"item"
                    },
                    xAxis:[{
                        type:"category",
                        data:this.salesCount.map(data => data.name),
                    }],
                    yAxis:[{
                        type:"value"
                    }],
                    series:[{
                        name:"hah",
                        type:"line",
                        data:this.salesCount.map(data => data.count)
                    }]
                };
                option && myChart.setOption(option)
            },
            methods:{}
        }).mount('#app');
    </script>
</body>
</html>

饼图:

python 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>饼图</title>
</head>
<body>
    <div id="app" style="width:100%; height:100%;">
        <div id="chart-container" style="width:500px; height:400px;"></div>
    </div>
    <script src="./vue.js"></script>
    <script src="./echarts.js"></script>
    <script src="./sales.js"></script>
    <script>
        Vue.createApp({
            data() {
                return {
                    salesData:salesData,
                    salesCount: []
                }
            },
            created() {
                this.salesData.forEach(data => {
                    if (data.productType == "家具产品") {
                        let item = this.salesCount.find(ele => ele.name == data.storeName)
                        if(item) {
                            item.value++
                        } else {
                            this.salesCount.push({
                                name:data.storeName,
                                value:1
                            });
                        }
                    }
                })
                console.log(this.salesCount);
            },
            mounted() {
                var chartDom = document.getElementById("chart-container");
                var myChart = echarts.init(chartDom);
                var option = {
                    title:{
                        text:"家具产品门店数",
                        subtext:'',
                        left:"center"
                    },
                    tooltip:{
                        trigger:"item",
                        formatter:'{a} <br/> {b}:{c}({d}%)'
                    },
                    legend:{
                        orient:"vertical",
                        right:"right",
                        top:"middle"
                    },
                    series:[{
                        name:"direct",
                        type:"pie",
                        data:this.salesCount,
                    }]
                };
                option && myChart.setOption(option);
            },
            methods: {}
        }).mount('#app');


    </script>

</body>
</html>
相关推荐
溪语流沙35 分钟前
【每天一个CSS | Day19】流光文字与一笔写成的手写签名
前端·javascript·css
逐光者93341 分钟前
STM32——SPI 屏 · Flash · 高速
java·前端·stm32
To_OC1 小时前
同样是让 AI 写全栈,为什么别人一句话就够了
前端·前端框架·next.js
CDwenhuohuo1 小时前
electron pc项目打包成桌面端
前端·javascript·electron
前端大斗师1 小时前
「大于 1000」把 1000 元那单也算进去了:我在 Vue3 订单页对了 10 句话
前端·人工智能·typescript·大模型·原力计划
Jmyd01232 小时前
用 Web VR 引擎搭建 3D 虚拟展厅:从素材上云到多端实时渲染的完整数据链路
前端·3d·vr·三维数字化
刘天远3 小时前
Agent成本核算实现:事件表、状态分布与Python归集
前端·数据库·人工智能·python
欣欣之王来了3 小时前
开发环境准备:Node.js、npm、VS Code安装配置
前端·学习·架构·项目·vue3教程
xiaolinudao1233 小时前
将多个 Excel 表格中的数据合并到单个表中|6 种实现方案全解析
java·前端·excel
LRL_3 小时前
跨平台 Node 模块安装指南:如何利用 pnpm/npm 配置`supportedArchitectures` 锁定平台依赖
前端·npm·node.js