最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot?thymeleaf實現(xiàn)餅狀圖與柱形圖流程介紹

 更新時間:2022年12月02日 14:30:57   作者:披著星光的鯨魚  
這篇文章主要介紹了SpringBoot?thymeleaf實現(xiàn)餅狀圖與柱形圖流程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧

今天給大家?guī)淼氖且粋€用SpringBoot + thymeleaf顯示出餅狀圖和柱形圖

首先我們先創(chuàng)建項目 注意:創(chuàng)建SpringBoot項目時一定要聯(lián)網(wǎng)不然會報錯

項目創(chuàng)建好后我們首先對 application.yml 進(jìn)行編譯

#指定端口號
server:
 port: 8888
#配置mysql數(shù)據(jù)源
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/nba?serverTimezone=Asia/Shanghai
    username: root
    password: root
#配置模板引擎 thymeleaf
  thymeleaf:
    mode: HTML5
    cache: false
    suffix: .html
    prefix: classpath:/templates/
mybatis:
  mapper-locations: classpath:/mapper/*.xml
  type-aliases-package: com.bdqn.springboot  #放包名

接下來我們寫后端代碼

mapper層

package com.bdqn.springbootexcel.mapper;
import com.bdqn.springbootexcel.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface UserMapper {
    @Select("select * from user")
    List<User> find();
    @Insert("insert into user ( name, age, sex) values ( #{name}, #{age}, #{sex})")
    int add(User user);
}

實體類

package com.bdqn.springbootexcel.pojo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class User {
    @ExcelProperty(index = 0,value = "用戶編號")
    private Integer id;
    @ExcelProperty(index = 1,value = "用戶姓名")
    private String name;
    @ExcelProperty(index = 2,value = "用戶年齡")
    private String age;
    @ExcelProperty(index = 3,value = "用戶性別")
    private String sex;
}

現(xiàn)在編寫最重要的前端代碼

index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <!--餅狀圖-->
    <div id="pie" style="width:800px;height:600px;"></div>
    <script th:src="@{https://cdn.bootcdn.net/ajax/libs/echarts/5.4.0/echarts.min.js}"></script>
    <script>
        option = {
            title: {
                text:'餅圖示例',
                subtext:'純屬虛構(gòu)',
                left:'center'
            },
            legend: {
                top: 'bottom'
            },
            tooltip:{
                trigger:'item'
            },
            toolbox: {
                show: true,
                feature: {
                    mark: { show: true },
                    dataView: { show: true, readOnly: false },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
            },
            series: [
                {
                    name: 'Nightingale Chart',
                    type: 'pie',
                    radius: [50, 250],
                    center: ['50%', '50%'],
                    roseType: 'area',
                    itemStyle: {
                        borderRadius: 8
                    },
                    data: [
                    ]
                }
            ]
        };
        var chartDom = document.getElementById('pie');
        var myChart = echarts.init(chartDom);
        fetch("/pojos_bing").then(response => response.json()).then(res => {
            res.forEach(item => {
                //name 和 age 都是數(shù)據(jù)庫中的值
                option.series[0].data.push({name: item.name,value: item.age})
            })
            myChart.setOption(option);
        })
    </script>
    <!--柱狀圖-->
    <div style="height: 50px;"></div>
    <div id="bar" style="width: 1000px;height: 800px;"></div>
    <script>
        barOption = {
            title: {
                text: '柱狀圖'
            },
            legend: {
                top: 'top'
            },
            tooltip: {
                trigger: 'axis'
            },
            xAxis: {
                type: 'category',
                data: []
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '11',
                    data: [],
                    type: 'bar'
                },
                {
                    name: '22',
                    data: [],
                    type: 'bar'
                }
            ]
        };
        var barDom = document.getElementById('bar');
        var barChart = echarts.init(barDom);
        fetch("/pojos_bing").then(response => response.json()).then(res => {
            //name 和 age 都是數(shù)據(jù)庫中的值
            const name= res.map(v => v.name);
            barOption.xAxis.data = name
            const age= res.map(v => v.age);
            barOption.series[0].data = age
            barChart.setOption(barOption)
        })
    </script>
</body>
</html>

現(xiàn)在我們看看前端展示效果

到此這篇關(guān)于SpringBoot thymeleaf實現(xiàn)餅狀圖與柱形圖流程介紹的文章就介紹到這了,更多相關(guān)SpringBoot餅狀圖與柱形圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring實現(xiàn)聲明式事務(wù)的方法詳解

    Spring實現(xiàn)聲明式事務(wù)的方法詳解

    這篇文章主要介紹了Spring實現(xiàn)聲明式事務(wù)的方法詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • Java輸入輸出語句舉例詳解(通俗易懂!)

    Java輸入輸出語句舉例詳解(通俗易懂!)

    這篇文章主要給大家介紹了關(guān)于Java輸入輸出語句的相關(guān)資料,作為一種常用的編程語言,Java提供了多種輸入輸出的方式,用于與用戶進(jìn)行數(shù)據(jù)交互或處理文件數(shù)據(jù),需要的朋友可以參考下
    2023-10-10
  • 使用feign發(fā)送http請求解析報錯的問題

    使用feign發(fā)送http請求解析報錯的問題

    這篇文章主要介紹了使用feign發(fā)送http請求解析報錯的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Spring?Boot深入學(xué)習(xí)數(shù)據(jù)訪問之Spring?Data?JPA與Hibernate的應(yīng)用

    Spring?Boot深入學(xué)習(xí)數(shù)據(jù)訪問之Spring?Data?JPA與Hibernate的應(yīng)用

    Spring?Data?JPA是Spring?Data的子項目,在使用Spring?Data?JPA之前,先了解一下Hibernate,因為Spring?Data?JPA是由Hibernate默認(rèn)實現(xiàn)的
    2022-10-10
  • springbean的八種加載方式匯總

    springbean的八種加載方式匯總

    這篇文章主要介紹了springbean的八種加載方式,一種是XML方式聲明bean,使用@Component及其衍生注解@Controller?、@Service、@Repository定義bean,還有其他方法,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • 關(guān)于SpringMVC對Restful風(fēng)格的支持詳解

    關(guān)于SpringMVC對Restful風(fēng)格的支持詳解

    Restful就是一個資源定位及資源操作的風(fēng)格,不是標(biāo)準(zhǔn)也不是協(xié)議,只是一種風(fēng)格,是對http協(xié)議的詮釋,下面這篇文章主要給大家介紹了關(guān)于SpringMVC對Restful風(fēng)格支持的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • Shell重啟SpringBoot項目腳本的示例代碼(含服務(wù)守護(hù))

    Shell重啟SpringBoot項目腳本的示例代碼(含服務(wù)守護(hù))

    本文介紹了如何使用?Bash?腳本來管理和守護(hù)運(yùn)行服務(wù),將展示一個示例腳本,該腳本可以停止、啟動和守護(hù)運(yùn)行一個服務(wù),并提供了相應(yīng)的解釋和用法說明,文章通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • SpringCloud基于Feign的可編程式接口調(diào)用實現(xiàn)

    SpringCloud基于Feign的可編程式接口調(diào)用實現(xiàn)

    本文主要介紹了SpringCloud基于Feign的可編程式接口調(diào)用實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • java  LinkedList類詳解及實例代碼

    java LinkedList類詳解及實例代碼

    這篇文章主要介紹了java LinkedList類詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • java 生成文字圖片的示例代碼

    java 生成文字圖片的示例代碼

    本篇文章主要介紹了java 生成文字圖片的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08

最新評論

锦州市| 安西县| 敦煌市| 香港| 宜城市| 德州市| 周口市| 五家渠市| 化德县| 股票| 施秉县| 娄烦县| 丰台区| 万山特区| 宁陵县| 文昌市| 丹凤县| 澎湖县| 深水埗区| 岐山县| 汝阳县| 黄陵县| 东阿县| 夏河县| 永济市| 丰都县| 霍林郭勒市| 玉田县| 泸西县| 邢台市| 克拉玛依市| 神池县| 博湖县| 炉霍县| 芮城县| 克拉玛依市| 麟游县| 宣威市| 侯马市| 社旗县| 北京市|