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

Spring Boot 數(shù)據(jù)可視化與圖表集成問題解析

 更新時間:2026年03月21日 10:39:19   作者:星辰徐哥  
本章我們學習了Spring Boot數(shù)據(jù)可視化與圖表集成,包括數(shù)據(jù)可視化的定義與特點、圖表工具的定義與特點、Spring Boot與圖表工具的集成、Spring Boot的實際應用場景,學會了在實際開發(fā)中處理數(shù)據(jù)可視化與圖表集成問題,感興趣的朋友跟隨小編一起看看吧

Spring Boot 數(shù)據(jù)可視化與圖表集成

27.1 學習目標與重點提示

學習目標:掌握Spring Boot數(shù)據(jù)可視化與圖表集成的核心概念與使用方法,包括數(shù)據(jù)可視化的定義與特點、圖表工具的定義與特點、Spring Boot與圖表工具的集成、Spring Boot的實際應用場景,學會在實際開發(fā)中處理數(shù)據(jù)可視化與圖表集成問題。
重點:數(shù)據(jù)可視化的定義與特點圖表工具的定義與特點Spring Boot與圖表工具的集成、Spring Boot的實際應用場景。

27.2 數(shù)據(jù)可視化與圖表工具概述

數(shù)據(jù)可視化與圖表工具是Java開發(fā)中的重要組件。

27.2.1 數(shù)據(jù)可視化的定義

定義:數(shù)據(jù)可視化是指將數(shù)據(jù)通過圖表、地圖、儀表盤等形式直觀地展示出來,幫助用戶更好地理解和分析數(shù)據(jù)。
作用

  • 提高數(shù)據(jù)的可讀性。
  • 幫助用戶發(fā)現(xiàn)數(shù)據(jù)中的規(guī)律。
  • 支持快速決策。

常見的數(shù)據(jù)可視化工具

  • ECharts:ECharts是百度開源的一個數(shù)據(jù)可視化庫。
  • Highcharts:Highcharts是一個基于JavaScript的數(shù)據(jù)可視化庫。
  • D3.js:D3.js是一個基于JavaScript的數(shù)據(jù)可視化庫。
  • Tableau:Tableau是一個商業(yè)數(shù)據(jù)可視化工具。

? 結論:數(shù)據(jù)可視化是指將數(shù)據(jù)通過圖表、地圖、儀表盤等形式直觀地展示出來,作用是提高數(shù)據(jù)的可讀性、幫助用戶發(fā)現(xiàn)數(shù)據(jù)中的規(guī)律、支持快速決策。

27.2.2 圖表工具的定義

定義:圖表工具是一種用于創(chuàng)建和展示圖表的軟件工具,用于數(shù)據(jù)可視化。
作用

  • 實現(xiàn)圖表的創(chuàng)建。
  • 實現(xiàn)圖表的展示。
  • 提高數(shù)據(jù)的可視化效果。

常見的圖表工具

  • ECharts:ECharts是百度開源的一個數(shù)據(jù)可視化庫。
  • Highcharts:Highcharts是一個基于JavaScript的數(shù)據(jù)可視化庫。
  • D3.js:D3.js是一個基于JavaScript的數(shù)據(jù)可視化庫。
  • Tableau:Tableau是一個商業(yè)數(shù)據(jù)可視化工具。

? 結論:圖表工具是一種用于創(chuàng)建和展示圖表的軟件工具,作用是實現(xiàn)圖表的創(chuàng)建、展示、提高數(shù)據(jù)的可視化效果。

27.3 Spring Boot與圖表工具的集成

Spring Boot與圖表工具的集成是Java開發(fā)中的重要內容。

27.3.1 集成ECharts的步驟

定義:集成ECharts的步驟是指使用Spring Boot與ECharts集成的方法。
步驟

  1. 創(chuàng)建Spring Boot項目。
  2. 添加所需的依賴。
  3. 配置ECharts。
  4. 創(chuàng)建數(shù)據(jù)訪問層。
  5. 創(chuàng)建業(yè)務層。
  6. 創(chuàng)建控制器類。
  7. 創(chuàng)建前端頁面。
  8. 測試應用。

示例
pom.xml文件中的依賴:

<dependencies>
    <!-- Web依賴 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- Thymeleaf依賴 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- 測試依賴 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

application.properties文件中的配置:

# 服務器端口
server.port=8080
# Thymeleaf配置
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.suffix=.html
spring.thymeleaf.prefix=classpath:/templates/

實體類:

public class Product {
    private Long id;
    private String productId;
    private String productName;
    private double price;
    private int sales;
    public Product() {
    }
    public Product(Long id, String productId, String productName, double price, int sales) {
        this.id = id;
        this.productId = productId;
        this.productName = productName;
        this.price = price;
        this.sales = sales;
    }
    // Getter和Setter方法
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }
    public String getProductName() {
        return productName;
    }
    public void setProductName(String productName) {
        this.productName = productName;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public int getSales() {
        return sales;
    }
    public void setSales(int sales) {
        this.sales = sales;
    }
    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", productId='" + productId + '\'' +
                ", productName='" + productName + '\'' +
                ", price=" + price +
                ", sales=" + sales +
                '}';
    }
}

Repository接口:

import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Repository
public class ProductRepository {
    private List<Product> products = new ArrayList<>();
    public ProductRepository() {
        products.add(new Product(1L, "P001", "手機", 1000.0, 100));
        products.add(new Product(2L, "P002", "電腦", 5000.0, 50));
        products.add(new Product(3L, "P003", "電視", 3000.0, 80));
        products.add(new Product(4L, "P004", "手表", 500.0, 200));
        products.add(new Product(5L, "P005", "耳機", 300.0, 150));
    }
    public List<Product> getAllProducts() {
        return products;
    }
    public Product getProductById(Long id) {
        return products.stream().filter(product -> product.getId().equals(id)).findFirst().orElse(null);
    }
    public void addProduct(Product product) {
        product.setId((long) (products.size() + 1));
        products.add(product);
    }
    public void updateProduct(Product product) {
        Product existingProduct = getProductById(product.getId());
        if (existingProduct != null) {
            existingProduct.setProductId(product.getProductId());
            existingProduct.setProductName(product.getProductName());
            existingProduct.setPrice(product.getPrice());
            existingProduct.setSales(product.getSales());
        }
    }
    public void deleteProduct(Long id) {
        products.removeIf(product -> product.getId().equals(id));
    }
}

Service類:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProductService {
    @Autowired
    private ProductRepository productRepository;
    public List<Product> getAllProducts() {
        return productRepository.getAllProducts();
    }
    public Product getProductById(Long id) {
        return productRepository.getProductById(id);
    }
    public void addProduct(Product product) {
        productRepository.addProduct(product);
    }
    public void updateProduct(Product product) {
        productRepository.updateProduct(product);
    }
    public void deleteProduct(Long id) {
        productRepository.deleteProduct(id);
    }
}

控制器類:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@RequestMapping("/api/products")
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/")
    public String getAllProducts(Model model) {
        List<Product> products = productService.getAllProducts();
        model.addAttribute("products", products);
        return "product-list";
    }
    @GetMapping("/{id}")
    public String getProductById(@PathVariable Long id, Model model) {
        Product product = productService.getProductById(id);
        model.addAttribute("product", product);
        return "product-detail";
    }
    @GetMapping("/add")
    public String addProductForm(Model model) {
        model.addAttribute("product", new Product());
        return "product-form";
    }
    @PostMapping("/add")
    public String addProduct(@ModelAttribute Product product) {
        productService.addProduct(product);
        return "redirect:/api/products/";
    }
    @GetMapping("/edit/{id}")
    public String editProductForm(@PathVariable Long id, Model model) {
        Product product = productService.getProductById(id);
        model.addAttribute("product", product);
        return "product-form";
    }
    @PostMapping("/edit/{id}")
    public String editProduct(@PathVariable Long id, @ModelAttribute Product product) {
        product.setId(id);
        productService.updateProduct(product);
        return "redirect:/api/products/";
    }
    @GetMapping("/delete/{id}")
    public String deleteProduct(@PathVariable Long id) {
        productService.deleteProduct(id);
        return "redirect:/api/products/";
    }
}

前端頁面(product-list.html):

<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>產品列表</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.2/dist/echarts.min.js"></script>
</head>
<body>
    <h1>產品列表</h1>
    <a href="/api/products/add" rel="external nofollow" >添加產品</a>
    <table border="1">
        <thead>
            <tr>
                <th>ID</th>
                <th>產品ID</th>
                <th>產品名稱</th>
                <th>價格</th>
                <th>銷量</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr th:each="product : ${products}">
                <td th:text="${product.id}"></td>
                <td th:text="${product.productId}"></td>
                <td th:text="${product.productName}"></td>
                <td th:text="${product.price}"></td>
                <td th:text="${product.sales}"></td>
                <td>
                    <a th:href="@{/api/products/edit/{id}(id=${product.id})}" rel="external nofollow" >編輯</a>
                    <a th:href="@{/api/products/delete/{id}(id=${product.id})}" rel="external nofollow" >刪除</a>
                </td>
            </tr>
        </tbody>
    </table>
    <h2>產品銷量圖表</h2>
    <div id="salesChart" style="width: 800px; height: 400px;"></div>
    <script>
        // 初始化圖表
        var chartDom = document.getElementById('salesChart');
        var myChart = echarts.init(chartDom);
        var option;
        // 準備數(shù)據(jù)
        var productNames = [];
        var productSales = [];
        <th:block th:each="product : ${products}">
            productNames.push('[(' + product.productName + ')]');
            productSales.push('[(' + product.sales + ')]');
        </th:block>
        // 配置圖表
        option = {
            title: {
                text: '產品銷量圖表',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                right: 10,
                top: 'center'
            },
            series: [
                {
                    name: '銷量',
                    type: 'pie',
                    radius: ['40%', '70%'],
                    avoidLabelOverlap: false,
                    itemStyle: {
                        borderRadius: 10,
                        borderColor: '#fff',
                        borderWidth: 2
                    },
                    label: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        label: {
                            show: true,
                            fontSize: 20,
                            fontWeight: 'bold'
                        }
                    },
                    labelLine: {
                        show: false
                    },
                    data: [
                        <th:block th:each="product : ${products}">
                            {value: [(' + product.sales + ')], name: '[(' + product.productName + ')']},
                        </th:block>
                    ]
                }
            ]
        };
        // 渲染圖表
        option && myChart.setOption(option);
    </script>
</body>
</html>

應用啟動類:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EChartsApplication {
    public static void main(String[] args) {
        SpringApplication.run(EChartsApplication.class, args);
    }
}

測試類:

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class EChartsApplicationTests {
    @LocalServerPort
    private int port;
    @Autowired
    private TestRestTemplate restTemplate;
    @Test
    void contextLoads() {
    }
    @Test
    void testGetAllProducts() {
        String response = restTemplate.getForObject("http://localhost:" + port + "/api/products/", String.class);
        assertThat(response).contains("產品列表");
    }
}

? 結論:集成ECharts的步驟包括創(chuàng)建Spring Boot項目、添加所需的依賴、配置ECharts、創(chuàng)建數(shù)據(jù)訪問層、創(chuàng)建業(yè)務層、創(chuàng)建控制器類、創(chuàng)建前端頁面、測試應用。

27.4 Spring Boot的實際應用場景

在實際開發(fā)中,Spring Boot數(shù)據(jù)可視化與圖表集成的應用場景非常廣泛,如:

  • 實現(xiàn)產品信息的圖表展示。
  • 實現(xiàn)用戶信息的圖表展示。
  • 實現(xiàn)訂單信息的圖表展示。
  • 實現(xiàn)銷售數(shù)據(jù)的圖表展示。

示例

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@RequestMapping("/api/products")
class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/")
    public String getAllProducts(Model model) {
        List<Product> products = productService.getAllProducts();
        model.addAttribute("products", products);
        return "product-list";
    }
    @GetMapping("/{id}")
    public String getProductById(@PathVariable Long id, Model model) {
        Product product = productService.getProductById(id);
        model.addAttribute("product", product);
        return "product-detail";
    }
    @GetMapping("/add")
    public String addProductForm(Model model) {
        model.addAttribute("product", new Product());
        return "product-form";
    }
    @PostMapping("/add")
    public String addProduct(@ModelAttribute Product product) {
        productService.addProduct(product);
        return "redirect:/api/products/";
    }
    @GetMapping("/edit/{id}")
    public String editProductForm(@PathVariable Long id, Model model) {
        Product product = productService.getProductById(id);
        model.addAttribute("product", product);
        return "product-form";
    }
    @PostMapping("/edit/{id}")
    public String editProduct(@PathVariable Long id, @ModelAttribute Product product) {
        product.setId(id);
        productService.updateProduct(product);
        return "redirect:/api/products/";
    }
    @GetMapping("/delete/{id}")
    public String deleteProduct(@PathVariable Long id) {
        productService.deleteProduct(id);
        return "redirect:/api/products/";
    }
}
@Service
class ProductService {
    @Autowired
    private ProductRepository productRepository;
    public List<Product> getAllProducts() {
        return productRepository.getAllProducts();
    }
    public Product getProductById(Long id) {
        return productRepository.getProductById(id);
    }
    public void addProduct(Product product) {
        productRepository.addProduct(product);
    }
    public void updateProduct(Product product) {
        productRepository.updateProduct(product);
    }
    public void deleteProduct(Long id) {
        productRepository.deleteProduct(id);
    }
}
@Repository
class ProductRepository {
    private List<Product> products = new ArrayList<>();
    public ProductRepository() {
        products.add(new Product(1L, "P001", "手機", 1000.0, 100));
        products.add(new Product(2L, "P002", "電腦", 5000.0, 50));
        products.add(new Product(3L, "P003", "電視", 3000.0, 80));
        products.add(new Product(4L, "P004", "手表", 500.0, 200));
        products.add(new Product(5L, "P005", "耳機", 300.0, 150));
    }
    public List<Product> getAllProducts() {
        return products;
    }
    public Product getProductById(Long id) {
        return products.stream().filter(product -> product.getId().equals(id)).findFirst().orElse(null);
    }
    public void addProduct(Product product) {
        product.setId((long) (products.size() + 1));
        products.add(product);
    }
    public void updateProduct(Product product) {
        Product existingProduct = getProductById(product.getId());
        if (existingProduct != null) {
            existingProduct.setProductId(product.getProductId());
            existingProduct.setProductName(product.getProductName());
            existingProduct.setPrice(product.getPrice());
            existingProduct.setSales(product.getSales());
        }
    }
    public void deleteProduct(Long id) {
        products.removeIf(product -> product.getId().equals(id));
    }
}
@SpringBootApplication
public class EChartsApplication {
    public static void main(String[] args) {
        SpringApplication.run(EChartsApplication.class, args);
    }
}
// 測試類
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class EChartsApplicationTests {
    @LocalServerPort
    private int port;
    @Autowired
    private TestRestTemplate restTemplate;
    @Test
    void contextLoads() {
    }
    @Test
    void testGetAllProducts() {
        String response = restTemplate.getForObject("http://localhost:" + port + "/api/products/", String.class);
        assertThat(response).contains("產品列表");
    }
}

輸出結果

  • 訪問http://localhost:8080/api/products/:返回產品列表頁面,包含產品銷量圖表。
  • 點擊“添加產品”:跳轉到添加產品頁面。
  • 點擊“編輯”:跳轉到編輯產品頁面。
  • 點擊“刪除”:刪除產品。

? 結論:在實際開發(fā)中,Spring Boot數(shù)據(jù)可視化與圖表集成的應用場景非常廣泛,需要根據(jù)實際問題選擇合適的圖表工具。

總結

本章我們學習了Spring Boot數(shù)據(jù)可視化與圖表集成,包括數(shù)據(jù)可視化的定義與特點、圖表工具的定義與特點、Spring Boot與圖表工具的集成、Spring Boot的實際應用場景,學會了在實際開發(fā)中處理數(shù)據(jù)可視化與圖表集成問題。其中,數(shù)據(jù)可視化的定義與特點、圖表工具的定義與特點、Spring Boot與圖表工具的集成、Spring Boot的實際應用場景是本章的重點內容。從下一章開始,我們將學習Spring Boot的其他組件、微服務等內容。

到此這篇關于Spring Boot 數(shù)據(jù)可視化與圖表集成問題解析的文章就介紹到這了,更多相關springboot數(shù)據(jù)可視化與圖表集成內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Spring如何基于Proxy及cglib實現(xiàn)動態(tài)代理

    Spring如何基于Proxy及cglib實現(xiàn)動態(tài)代理

    這篇文章主要介紹了Spring如何基于Proxy及cglib實現(xiàn)動態(tài)代理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06
  • SpringBoot前后端分離項目之打包、部署到服務器詳細圖文流程

    SpringBoot前后端分離項目之打包、部署到服務器詳細圖文流程

    作為后臺開發(fā),項目打包部署是經常性的操作,下面這篇文章主要給大家介紹了關于SpringBoot前后端分離項目之打包、部署到服務器的相關資料,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下
    2023-12-12
  • Java實現(xiàn)學生管理系統(tǒng)(IO版)

    Java實現(xiàn)學生管理系統(tǒng)(IO版)

    這篇文章主要為大家詳細介紹了Java實現(xiàn)學生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • RustFS接口實戰(zhàn)之Java+Docker實現(xiàn)實時上傳下載功能

    RustFS接口實戰(zhàn)之Java+Docker實現(xiàn)實時上傳下載功能

    本文詳細介紹了如何使用Java和Docker實現(xiàn)RustFS的實時上傳下載功能,提供了完整的代碼示例和配置步驟,幫助開發(fā)者快速集成對象存儲功能,適用場景廣泛,適合單體應用和微服務架構,感興趣的朋友跟隨小編一起看看吧
    2026-01-01
  • Java多線程 volatile關鍵字詳解

    Java多線程 volatile關鍵字詳解

    這篇文章主要介紹了Java多線程 volatile關鍵字詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • 深入了解java中的string對象

    深入了解java中的string對象

    這篇文章主要介紹了java中的string對象,String對象是Java中使用最頻繁的對象之一,所以Java開發(fā)者們也在不斷地對String對象的實現(xiàn)進行優(yōu)化,以便提升String對象的性能。對此感興趣的朋友跟隨小編一起看看吧
    2019-11-11
  • Java用自帶的Image IO給圖片添加水印

    Java用自帶的Image IO給圖片添加水印

    本文主要介紹了如何采用Java自帶的Image IO實現(xiàn)圖片添加水印的需求,并整合了一些其他功能,感興趣的朋友可以參考下
    2021-06-06
  • java批量解析微信dat文件

    java批量解析微信dat文件

    這篇文章主要為大家詳細介紹了java批量解析微信dat文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Mybatis千萬級數(shù)據(jù)查詢的解決方式,避免OOM問題

    Mybatis千萬級數(shù)據(jù)查詢的解決方式,避免OOM問題

    這篇文章主要介紹了Mybatis千萬級數(shù)據(jù)查詢的解決方式,避免OOM問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 詳解springboot整合Listener的兩種方式

    詳解springboot整合Listener的兩種方式

    這篇文章主要介紹了springboot整合Listener的兩種方式,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-12-12

最新評論

无为县| 淅川县| 华蓥市| 瓦房店市| 长丰县| 夏津县| 葫芦岛市| 溧水县| 江华| 阿拉善左旗| 尖扎县| 阜康市| 禹州市| 南通市| 滦南县| 江口县| 大新县| 马公市| 广灵县| 赣榆县| 崇仁县| 通山县| 天峻县| 威远县| 扬中市| 汶川县| 房产| 应用必备| 凉城县| 夏邑县| 阳城县| 哈密市| 施秉县| 固安县| 文昌市| 山西省| 贵州省| 阿坝| 民乐县| 射洪县| 禹城市|