1.效果展示

1.树状

2.扇形图 

 2.实现步骤

1.数据库结构

2.pom.xml文件 

  <dependencies>
        <dependency>
            <groupId&gt;com.baomidou</groupId&gt;
            <artifactId&gt;mybatis-plus-boot-starter</artifactId&gt;
            <version&gt;3.5.2</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
       
    </dependencies>

3.项目结构

用不了这么多,这些主要是用Mybatisplus生成的 

主要是这个我是和导入导出一起写的 所以有这么多东西,类和方法都是放在一起了,博客我却分开发了 谅解一下

4.实体类(主要用的是name属性count属性

 5.controller

 

一个返回数据的,两个跳转页面

6.service层 

service接口 

service实现类

 7.mapper

8.mapper.xml

 9.html页面

形图

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<div id="main" style="width: 600px; height: 400px;"></div>
</body>
<script type="text/javascript">
    //初始化echarts
    function init(myChart){
        let option = {
            title:{
                text:'ECharts 数据统计'
            },
            series:[{
                name:'访问量',
                type:'pie',
                radius:'50%',
                data:[
                    {value:0,name:'无'},
                ]
            }]
        };

        myChart.setOption(option);
    }
    //从数据库读取数据赋值echarts
    function show(myChart){
        $.ajax({
            contentType : "application/json",
            type : "GET",
            url : "/tubiao1",
            dataType : "json",
            success : function(data) {
                //创建个数组,
                let Chart=[];
                for(let i=0;i<data.length;i++){
                    let obj={};
                    obj.name=data[i].name;
                    obj.value=data[i].count;
                    Chart[i]=obj;
                }

                myChart.setOption({
                    title:{
                        text:'商品库存'
                    },
                    tooltip:{},
                    series:[{
                        name:'数量',
                        type:'pie',
                        // radius:'10%',
                        data:Chart,
                    }]

                });

            }
        });
    }

    //初始化echarts实例
    let myChart = echarts.init(document.getElementById("main"));
    init(myChart);
    show(myChart);

</script>
</html>

 树状图:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<div id="main" style="height: 40em"></div>
</body>
<script type="text/javascript">
    var myChart = echarts.init(document.getElementById('main'));

    $.ajax({
        contentType: "application/json",
        type: "GET",
        url: "/tubiao1",
        dataType: "json",
        success: function (data) {

            let x = [];
            let y = [];

            for (let i = 0; i < data.length; i++) {
                //x[i]获取json的姓名,y[i]获取json的值
                x[i] = data[i].name;
                y[i] = data[i].count;


            }

            myChart.setOption({

                tooltip: {},
                label: {
                    show: true,
                    position:'top',
                },
                legend: {},
                xAxis: {
                    data: x
                },
                yAxis: {},
                series: [
                    {
                        colorBy:'data',
                        name: '商品库存',
                        type: 'bar',
                        data: y

                    }
                ]
            });

        },
        error: function () {

        }
    })

</script>

</html>

都是通过ajax后台拿数据

html页面时候别忘了这两个东西

是不是很简单

总结制作不易,如果帮助到你 请点赞收藏支持一下

 如果还有纰漏请及时告知 感谢观看

 

原文地址:https://blog.csdn.net/weixin_61307867/article/details/128102904

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_43876.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注