欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Springboot項(xiàng)目中運(yùn)用vue+ElementUI+echarts前后端交互實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)圖(推薦)

 更新時(shí)間:2021年06月19日 16:00:57   作者:沉默著忍受  
今天給大家?guī)?lái)一篇教程關(guān)于Springboot項(xiàng)目中運(yùn)用vue+ElementUI+echarts前后端交互實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)圖的技能,包括環(huán)境配置及圓環(huán)圖前端后端實(shí)現(xiàn)代碼,感興趣的朋友一起看看吧

如何運(yùn)用vue+echarts前后端交互實(shí)現(xiàn)動(dòng)態(tài)餅圖

前言

我們做項(xiàng)目的時(shí)候,常常需要一些統(tǒng)計(jì)圖來(lái)展示我們的數(shù)據(jù),作為web開(kāi)發(fā)人員,會(huì)實(shí)現(xiàn)統(tǒng)計(jì)圖是我們必會(huì)的技能。我將帶大家來(lái)實(shí)現(xiàn)動(dòng)態(tài)餅圖的實(shí)現(xiàn)

一、環(huán)境配置

1.1 安裝acharts

//npm也一樣
cnpm install echarts --save

1.2 全局引用

main.js中配置

//引入 echarts
import echarts from 'echarts'
//注冊(cè)組件
Vue.prototype.$echarts = echarts

全局注冊(cè)好組件之后就讓我們進(jìn)入正題吧,第一步先繪制圓環(huán)圖吧。先上結(jié)果圖:

在這里插入圖片描述

二、圓環(huán)圖前端實(shí)現(xiàn)

 2.1 先在vue頁(yè)面添加渲染盒子

<template>
  <div class="test2" style="width:600px;height:400px;">
      <div id="myChart" style="width:100%;height:278px;float:left;"></div>
  </div>
</template>

2.2 前端邏輯實(shí)現(xiàn)部分

引入echart

import * as echarts from 'echarts'

注意:這里有一個(gè)大坑,如果你安裝的是高版本的echarts,一定要按我這個(gè)來(lái),import echarts from 'echarts'網(wǎng)上很多人都這么分享會(huì)發(fā)生init函數(shù)初始化錯(cuò)誤

<script>
     import * as echarts from 'echarts'
     export default {
       name: 'test2',
       data () {
         return {
         queryInfo: {
         query: "",
         pageNum: 1,
         pageSize: 4,//后端請(qǐng)求的數(shù)據(jù)類別4個(gè),如果你有多個(gè),就更改這個(gè)參數(shù)
       },
       queryInfof: {
         query: "",
         pageNum: 1,
         pageSize: 100,
       },
           myChart: '',
           opinionData2: [
           
           {"itemStyle":"#3F8FFF","name":"威脅攻擊日志","value":200},
           {"itemStyle":"#6DC8EC","name":"審計(jì)url異常","value":388},  
           {"itemStyle":"#1FC48D","name":"正常網(wǎng)絡(luò)日志","value":5287},         
           {"itemStyle":"red","name":"流量日志異常","value":320}      
           ]
         }
       },
       mounted: function () {
          this.drawLine();

       },
     
       methods: {
          async  drawLine () {
              // 調(diào)用post請(qǐng)求
     /* const { data: res } = await this.$http.get("alldate", {
        params: this.queryInfo
      });
      if (res.flag != "success") {
        return this.$message.error("該數(shù)據(jù)獲取失?。。?!");
      }

      console.log(res.flag)
       this.opinionData2 = res.opinionData2; // 將返回?cái)?shù)據(jù)賦值*/
           this.myChart = echarts.init(document.getElementById('myChart'))
           this.myChart.setOption({
             title: {
               text: '網(wǎng)絡(luò)日志異常流量分析', // 主標(biāo)題
               subtext: '', // 副標(biāo)題
               x: 'left' // x軸方向?qū)R方式
             },
             grid: { containLabel: true },
             tooltip: {
               trigger: 'item',
               formatter: '{a} <br/> : vvxyksv9kd%'
             },
             // color: ['#1FC48D', '#F5A60A', '#6DC8EC', '#3F8FFF'],
             color: ['#1FC48D', 'red', '#6DC8EC', '#3F8FFF'],
             // backgroundColor: '#ffffff',
             legend: {
               orient: 'vertical',
               icon: 'circle',
               align: 'left',
               x: 'right',
               y: 'bottom',
               data: ['審計(jì)url異常', '正常網(wǎng)絡(luò)日志', '流量日志異常', '威脅攻擊日志']
             },
             series: [
               {
                 name: '網(wǎng)絡(luò)日志狀態(tài)',
                 type: 'pie',
                 radius: ['50%', '70%'],
                 avoidLabelOverlap: false,
                 center: ['40%', '50%'],
                 itemStyle: {
                   emphasis: {
                     shadowBlur: 10,
                     shadowOffsetX: 0,
                     shadowColor: 'rgba(0, 0, 0, 0.5)'
                   },
                   color: function (params) {
                     // 自定義顏色
                     var colorList = ['#1FC48D', 'red', '#6DC8EC', '#3F8FFF']
                     return colorList[params.dataIndex]
                   }
                 },
                 data: this.opinionData2
               }
             ]
           })
         },
       }
     }
     </script>

2.3 展示(可按自己需求更改前端樣式)

在這里插入圖片描述

三、前后端數(shù)據(jù)交互實(shí)現(xiàn)

3.1 創(chuàng)建數(shù)據(jù)庫(kù)

表結(jié)構(gòu):(根據(jù)你的業(yè)務(wù)需要?jiǎng)?chuàng)建)

在這里插入圖片描述

表數(shù)據(jù)

在這里插入圖片描述

3.2 后臺(tái)代碼的編寫

3.2.1 在bean包下創(chuàng)建QueryInfo類

該類實(shí)現(xiàn)得到前端請(qǐng)求的數(shù)據(jù)條數(shù)。相當(dāng)于分頁(yè)功能。

public class QueryInfo {
    private String query;
    private int pageNum=1;
    private int pageSize=1;

    public QueryInfo() {
    }

    public QueryInfo(String query, int pageNum, int pageSize) {
        this.query = query;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public String getQuery() {
        return query;
    }

    public int getPageNum() {
        return pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public String toString() {
        return "QueryInfo{" +
                "query='" + query + '\'' +
                ", pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                '}';
    }
}

3.2.2 在bean包下創(chuàng)建Showdate類

public class Showdate {
    private  String name;
    private  String itemStyle;
    private  int value;


    public Showdate() {

    }

    public Showdate(String name, String itemStyle, int value) {
        this.name = name;
        this.itemStyle = itemStyle;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName1(String name) {
        this.name= name;
    }

    public String getItemStyle() {
        return itemStyle;
    }

    public void setItemStyle(String itemStyle) {
        this.itemStyle = itemStyle;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return "Showdate{" +
                "name='" + name + '\'' +
                ", itemStyle='" + itemStyle + '\'' +
                ", value=" + value +
                '}';
    }
}

3.2.3 在resources下創(chuàng)建Mapper

1.在Mapper中創(chuàng)建ShowDataMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.naughty.userlogin02.dao.ShowdateDao">


    <select id="getAlldate" resultType="com.naughty.userlogin02.bean.Showdate">
        SELECT * FROM date1
        <if test="name!=null ">
            WHERE name like #{name}
        </if>
        LIMIT #{pageStart},#{pageSize}
    </select>

    <update id="updatenew">
        UPDATE date1 SET value = #{count} WHERE name = #{name}
    </update>


</mapper>

2.在resources下創(chuàng)建application.yml用于配置數(shù)據(jù)庫(kù)和端口號(hào)

# mysql
spring:
  datasource:
    #MySQL配置
    driverClassName:  com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/weblog?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
    username: root
    password: root

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.example.demo.model
server:
  port: 9000

3.2.4 在Dao下創(chuàng)建ShowdateDao

里面有兩個(gè)接口,如果你需要操作數(shù)據(jù)庫(kù),就需要在ShowdateDao中編寫接口方法;
在ShowDataMapper.xml中編寫sql語(yǔ)句。
我這里實(shí)現(xiàn)了修改和查找;

import com.naughty.userlogin02.bean.Showdate;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface ShowdateDao {

    public List<Showdate> getAlldate(@Param("name") String name, @Param("pageStart") int pageStart, @Param("pageSize") int pageSize);

    public int updatenew(String name, int count);
}

3.2.5 在Controller下創(chuàng)建ShowdateController

在ShowdateController中要注解使用空間

 @Autowired
    ShowdateDao showdateDao;//你需要傳給前端的數(shù)據(jù)庫(kù)表
    @Autowired
    FlowDao flowDao;//你的數(shù)據(jù)來(lái)源的效果數(shù)據(jù)庫(kù)表
package com.naughty.userlogin02.controller;

import com.alibaba.fastjson.JSON;
import com.naughty.userlogin02.bean.*;
import com.naughty.userlogin02.dao.CheckDao;
import com.naughty.userlogin02.dao.FlowDao;
import com.naughty.userlogin02.dao.SafeDao;
import com.naughty.userlogin02.dao.ShowdateDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Stack;

@RestController
public class ShowdateController {

    @Autowired
    ShowdateDao showdateDao;
    @Autowired
    FlowDao flowDao;
//前臺(tái)刷新日志數(shù)據(jù)
    @CrossOrigin
    @RequestMapping("/alldate")//前端請(qǐng)求通道
    public String getAlldateList(QueryInfo queryInfo){
        System.out.println(queryInfo);
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<Showdate> dates = showdateDao.getAlldate("%"+queryInfo.getQuery()+"%",pageStart,queryInfo.getPageSize());
   
      for(int i =0;i<dates.size();i++){
          System.out.println(dates.get(i).toString());
      }
        //校驗(yàn)
        //封裝校驗(yàn)后的流量日志
        HashMap<String, Object> res = new HashMap<>();
        res.put("flag","success");
        res.put("opinionData2",dates );
        String date_json= JSON.toJSONString(res);
        System.out.println(date_json.toString());
        return date_json;
    }

//數(shù)據(jù)庫(kù)數(shù)據(jù)來(lái)源的實(shí)現(xiàn)方法,就是改變數(shù)據(jù)庫(kù)表Date1中得數(shù)據(jù)
    @RequestMapping("/getupdata")
    public String updateDate(QueryInfo queryInfo){

        String s = "流量日志異常";
        String s1 ="審計(jì)url異常";
        String s2 ="威脅攻擊日志";
        String s3 ="正常網(wǎng)絡(luò)日志";
        /*int count = getUserList(queryInfo);
        int count1 =getChickList(queryInfo);  //四個(gè)方法需要你自己根據(jù)具體業(yè)務(wù)實(shí)現(xiàn)
        int count2 =getSafeDate(queryInfo);
        int count3 =allBlognum(queryInfo)-(count+count1+count2);*/
        showdateDao.updatenew(s,count);
        showdateDao.updatenew(s1,count1);
        showdateDao.updatenew(s2,count2);
        int i= showdateDao.updatenew(s3,count3);
        System.out.println("異常類型:"+s);
        System.out.println("異常日志數(shù)量:"+count);
        String str = i >0?"success":"error";
        return str;
    }

}

3.2.6 修改前端接口

Js全部代碼:

 <script>
     import * as echarts from 'echarts'
     export default {
       name: 'test2',
       data () {
         return {
         queryInfo: {
         query: "",
         pageNum: 1,
         pageSize: 4,
       },
       queryInfof: {
         query: "",
         pageNum: 1,
         pageSize: 100,
       },
           myChart: '',
           opinionData2: [
     
//清空前端測(cè)試數(shù)據(jù)
           ]
         }
       },
       mounted: function () {
          this.drawLine();

       },
       created() {
         this.getdateList();  //每次進(jìn)入頁(yè)面刷新數(shù)據(jù)庫(kù)數(shù)據(jù)實(shí)現(xiàn)動(dòng)態(tài)數(shù)據(jù)綁定
      },
       methods: {
          async  drawLine () {
              // 調(diào)用post請(qǐng)求,獲得后臺(tái)數(shù)據(jù)庫(kù)的數(shù)值
      const { data: res } = await this.$http.get("alldate", {
        params: this.queryInfo
      });
      if (res.flag != "success") {
        return this.$message.error("該數(shù)據(jù)獲取失敗?。?!");
      }

      console.log(res.flag)
       this.opinionData2 = res.opinionData2; // 將返回?cái)?shù)據(jù)賦值
           this.myChart = echarts.init(document.getElementById('myChart'))
           this.myChart.setOption({
             title: {
               text: '網(wǎng)絡(luò)日志異常流量分析', // 主標(biāo)題
               subtext: '', // 副標(biāo)題
               x: 'left' // x軸方向?qū)R方式
             },
             grid: { containLabel: true },
             tooltip: {
               trigger: 'item',
               formatter: '{a} <br/> : vvxyksv9kd%'
             },
             // color: ['#1FC48D', '#F5A60A', '#6DC8EC', '#3F8FFF'],
             color: ['#1FC48D', 'red', '#6DC8EC', '#3F8FFF'],
             // backgroundColor: '#ffffff',
             legend: {
               orient: 'vertical',
               icon: 'circle',
               align: 'left',
               x: 'right',
               y: 'bottom',
               data: ['審計(jì)url異常', '正常網(wǎng)絡(luò)日志', '流量日志異常', '威脅攻擊日志']
             },
             series: [
               {
                 name: '網(wǎng)絡(luò)日志狀態(tài)',
                 type: 'pie',
                 radius: ['50%', '70%'],
                 avoidLabelOverlap: false,
                 center: ['40%', '50%'],
                 itemStyle: {
                   emphasis: {
                     shadowBlur: 10,
                     shadowOffsetX: 0,
                     shadowColor: 'rgba(0, 0, 0, 0.5)'
                   },
                   color: function (params) {
                     // 自定義顏色
                     var colorList = ['#1FC48D', 'red', '#6DC8EC', '#3F8FFF']
                     return colorList[params.dataIndex]
                   }
                 },
                 data: this.opinionData2
               }
             ]
           })
         },
         async getdateList() {
      // 調(diào)用post請(qǐng)求
      const { data: res } = await this.$http.get("getupdata", {
        params: this.queryInfof
      });
      if (res != "success") {
        return this.$message.error("該數(shù)據(jù)獲取失?。。?!");
      }
      console.log(res)
        },
       }
     }
     </script>

在這里插入圖片描述

后臺(tái)返回?cái)?shù)據(jù):

在這里插入圖片描述

以上就是Springboot項(xiàng)目中運(yùn)用vue+ElementUI+echarts前后端交互實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)圖的詳細(xì)內(nèi)容,更多關(guān)于Springboot動(dòng)態(tài)圓環(huán)圖的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • springboot控制層傳遞參數(shù)為非必填值的操作

    springboot控制層傳遞參數(shù)為非必填值的操作

    這篇文章主要介紹了springboot控制層傳遞參數(shù)為非必填值的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java Math.round函數(shù)詳解

    Java Math.round函數(shù)詳解

    這篇文章主要介紹了Java Math.round函數(shù)詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • springboot使用mybatis一對(duì)多的關(guān)聯(lián)查詢問(wèn)題記錄

    springboot使用mybatis一對(duì)多的關(guān)聯(lián)查詢問(wèn)題記錄

    這篇文章主要介紹了springboot使用mybatis一對(duì)多的關(guān)聯(lián)查詢問(wèn)題記錄,剛好最近有個(gè)需求需要做到關(guān)聯(lián)的查詢,時(shí)間也算充足,所以用sql來(lái)寫,于是踩了很久坑,終于跳出來(lái)了,小小記錄一下
    2022-01-01
  • Java都有哪些創(chuàng)建線程的方法

    Java都有哪些創(chuàng)建線程的方法

    這篇文章主要介紹了Java都有哪些創(chuàng)建線程的方法,文章分享Java創(chuàng)建線程得幾種方法及推薦使用哪種方法,下面詳細(xì)內(nèi)容需要的小伙伴可以參考一下
    2022-05-05
  • 關(guān)于IDEA 2020.3 多窗口視圖丟失的問(wèn)題

    關(guān)于IDEA 2020.3 多窗口視圖丟失的問(wèn)題

    這篇文章主要介紹了關(guān)于IDEA 2020.3 多窗口視圖丟失的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • SpringBoot初步連接redis詳解

    SpringBoot初步連接redis詳解

    這篇文章主要介紹了SpringBoot初步連接redis詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12
  • springboot+mybatis-plus實(shí)現(xiàn)自動(dòng)建表的示例

    springboot+mybatis-plus實(shí)現(xiàn)自動(dòng)建表的示例

    本文主要介紹了springboot+mybatis-plus實(shí)現(xiàn)自動(dòng)建表的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-06-06
  • SpringBoot使用Validation包進(jìn)行輸入?yún)?shù)校驗(yàn)

    SpringBoot使用Validation包進(jìn)行輸入?yún)?shù)校驗(yàn)

    Spring Boot 自帶的 spring-boot-starter-validation 包支持以標(biāo)準(zhǔn)注解的方式進(jìn)行輸入?yún)?shù)校驗(yàn),本文即關(guān)注 spring-boot-starter-validation 包所涵蓋的標(biāo)準(zhǔn)注解的使用、校驗(yàn)異常的捕獲與展示、分組校驗(yàn)功能的使用,以及自定義校驗(yàn)器的使用,需要的朋友可以參考下
    2024-05-05
  • SpringCloud中的Stream服務(wù)間消息傳遞詳解

    SpringCloud中的Stream服務(wù)間消息傳遞詳解

    這篇文章主要介紹了SpringCloud中的Stream服務(wù)間消息傳遞詳解,Stream 就是在消息隊(duì)列的基礎(chǔ)上,對(duì)其進(jìn)行封裝,可以是我們更方便的去使用,Stream應(yīng)用由第三方的中間件組成,應(yīng)用間的通信通過(guò)輸入通道和輸出通道完成,需要的朋友可以參考下
    2024-01-01
  • Java同步框架AbstractQueuedSynchronizer詳解

    Java同步框架AbstractQueuedSynchronizer詳解

    本篇文章主要介紹了Java同步框架AbstractQueuedSynchronizer詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10

最新評(píng)論