SpringBoot整合Echarts繪制靜態(tài)數(shù)據(jù)柱狀圖和餅圖
idea創(chuàng)建spring boot項(xiàng)目



下載echarts

把echarts.min.js文件放到項(xiàng)目中。
項(xiàng)目目錄

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sid.spark</groupId>
<artifactId>webspark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>webspark</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>application.properties
配置項(xiàng)目訪問端口9999,配置前綴/sid
server.port=9999 server.servlet.context-path=/sid
HelloSpringBoot.java
package com.sid.spark.webspark;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController
public class HelloSpringBoot {
@RequestMapping(value="/hello",method = RequestMethod.GET)
public String sayHello(){
return "Hello Spring Boot!";
}
@RequestMapping(value="/first",method = RequestMethod.GET)
public ModelAndView firstDemo(){
return new ModelAndView("test");//跟templates文件夾下的test.html名字一樣,返回這個(gè)界面
}
@RequestMapping(value="/courseClickCount",method = RequestMethod.GET)
public ModelAndView courseClickCountStat(){
return new ModelAndView("demo");//跟templates文件夾下的demo.html名字一樣,返回這個(gè)界面
}
}test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- 引入 ECharts 文件 -->
<script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 為 ECharts 準(zhǔn)備一個(gè)具備大?。▽捀撸┑?DOM -->
<div id="main" style="width: 600px;height:400px;position:absolute;top:50%;left: 50%;margin-top: -200px;margin-left: -300px;"></div>
<script type="text/javascript">
// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例
var myChart = echarts.init(document.getElementById('main'));//main是<div id="main" style="width: 600px;height:400px;"></div>的id
// 指定圖表的配置項(xiàng)和數(shù)據(jù)
var option = {
title: {
text: 'ECharts 入門示例'
},
tooltip: {},
legend: {
data:['銷量']
},
xAxis: {
data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]
},
yAxis: {},
series: [{
name: '銷量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
// 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。
myChart.setOption(option);
</script>
</body>
</html>demo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<!-- 引入 ECharts 文件 -->
<script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 為 ECharts 準(zhǔn)備一個(gè)具備大?。▽捀撸┑?DOM -->
<div id="main" style="width: 600px;height:400px;position:absolute;top:50%;left: 50%;margin-top: -200px;margin-left: -300px;"></div>
<script type="text/javascript">
// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例
var myChart = echarts.init(document.getElementById('main'));//main是<div id="main" style="width: 600px;height:400px;"></div>的id
// 指定圖表的配置項(xiàng)和數(shù)據(jù)
var option = {
title : {
text: 'Spark Streaming實(shí)戰(zhàn)課程訪問量實(shí)時(shí)統(tǒng)計(jì)',
subtext: '實(shí)戰(zhàn)課程訪問次數(shù)',
x:'center'
},
tooltip : {
trigger: 'item',
formatter: "{a} <br/> : {c} (kgma80u%)"
},
legend: {
orient: 'vertical',
left: 'left',
data: ['Spark SQL實(shí)戰(zhàn)','Hadoop基礎(chǔ)','Storm實(shí)戰(zhàn)','Spark Streaming實(shí)戰(zhàn)','理論']
},
series : [
{
name: '訪問次數(shù)',
type: 'pie',
radius : '55%',
center: ['50%', '60%'],
data:[
{value:3350, name:'Spark SQL實(shí)戰(zhàn)'},
{value:3100, name:'Hadoop基礎(chǔ)'},
{value:2340, name:'Storm實(shí)戰(zhàn)'},
{value:1350, name:'Spark Streaming實(shí)戰(zhàn)'},
{value:15480, name:'理論'}
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。
myChart.setOption(option);
</script>
</body>
</html>運(yùn)行項(xiàng)目

訪問http://localhost:9999/sid/hello

http://localhost:9999/sid/first

http://localhost:9999/sid/courseClickCount

以上就是SpringBoot整合Echarts繪制靜態(tài)數(shù)據(jù)柱狀圖和餅圖的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot Echarts繪制柱狀圖和餅圖的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- springboot如何從數(shù)據(jù)庫獲取數(shù)據(jù),用echarts顯示(數(shù)據(jù)可視化)
- SpringBoot+Thymeleaf+ECharts實(shí)現(xiàn)大數(shù)據(jù)可視化(基礎(chǔ)篇)
- SpringBoot+thymeleaf+Echarts+Mysql 實(shí)現(xiàn)數(shù)據(jù)可視化讀取的示例
- SpringBoot+ECharts是如何實(shí)現(xiàn)數(shù)據(jù)可視化的
- SpringBoot+Echarts實(shí)現(xiàn)請(qǐng)求后臺(tái)數(shù)據(jù)顯示餅狀圖
相關(guān)文章
解決Properties屬性文件中的值有等號(hào)和換行的小問題
這篇文章主要介紹了解決Properties屬性文件中的值有等號(hào)有換行的小問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08
SpringBoot中maven項(xiàng)目打成war包部署在linux服務(wù)器上的方法
這篇文章主要介紹了SpringBoot中maven項(xiàng)目打成war包部署在linux服務(wù)器上的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
SpringBoot使用Redis緩存的實(shí)現(xiàn)方法
這篇文章主要介紹了SpringBoot使用Redis緩存的實(shí)現(xiàn)方法,需要的朋友可以參考下2018-02-02
談?wù)凧ava中整數(shù)類型(short int long)的存儲(chǔ)方式
在java中的整數(shù)類型有四種,分別是byte short in long,本文重點(diǎn)給大家介紹java中的整數(shù)類型(short int long),由于byte只是一個(gè)字節(jié)0或1,在此就不多說了,對(duì)java中的整數(shù)類型感興趣的朋友一起學(xué)習(xí)吧2015-11-11
springboot項(xiàng)目中application.properties無法變成小樹葉問題解決方案
這篇文章主要介紹了springboot項(xiàng)目中application.properties無法變成小樹葉問題解決,本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09
SpringBoot實(shí)現(xiàn)獲取客戶端IP地理位置
在當(dāng)今互聯(lián)的世界中,了解客戶端的地理位置對(duì)于提供個(gè)性化服務(wù)和增強(qiáng)用戶體驗(yàn)至關(guān)重要,使用本文為大家介紹了SpringBoot獲取客戶端IP地理位置的相關(guān)方法,需要的小伙伴可以參考下2023-11-11

