添加图表

This commit is contained in:
Strange 2024-02-13 20:42:41 +08:00
parent bf87f96d63
commit 3884696c7d
10 changed files with 156 additions and 2 deletions

1
.gitignore vendored
View File

@ -60,3 +60,4 @@ nbdist/
!*/build/*.java
!*/build/*.html
!*/build/*.xml

View File

@ -177,6 +177,8 @@
<version>${ruoyi.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -64,7 +64,11 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-generator</artifactId>
</dependency>
<!--thymeleaf启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,39 @@
package com.ruoyi.web.controller.chart;
import com.ruoyi.app.system.domain.ChatDomain;
import com.ruoyi.app.system.mapper.ChatMapper;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Controller
@Anonymous
@RequestMapping("/chat")
public class chat {
@Resource
private ChatMapper chatMapper;
@GetMapping("/PolylineChat")
// @ResponseBody
public String Polyline(Model model){
List<ChatDomain> dataList = chatMapper.pyline();
List<BigDecimal> moneyList = new ArrayList<>();
List<Integer> monthList = new ArrayList<>();
for (ChatDomain chatDomain:dataList){
moneyList.add(chatDomain.getTotal_money());
monthList.add(chatDomain.getMonth());
}
model.addAttribute("moneyList",moneyList);
model.addAttribute("monthList",monthList);
return "/polyline";
}
}

View File

@ -8,7 +8,7 @@ spring:
master:
url: jdbc:mysql://localhost:3306/jizhang?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: jieyi123
password: 336699
# 从库数据源
slave:
# 从数据源开关/默认关闭

View File

@ -60,11 +60,18 @@ spring:
max-file-size: 10MB
# 设置总上传的文件大小
max-request-size: 20MB
thymeleaf:
cache: false
prefix: classpath:/templates/
encoding: UTF-8 #编码
suffix: .html #模板后缀
mode: HTML #模板
# 服务模块
devtools:
restart:
# 热部署开关
enabled: true
# redis 配置
redis:
# 地址

View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Line Chart</title>
<style>
canvas {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="line-chart" width="400" height="300"></canvas>
<script src="
https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js
"></script>
<script th:inline="javascript">
// 获取 canvas 元素
var myChart = echarts.init(document.getElementById("line-chart"));
// 定义从后端传递过来的数据
var monthList = /*[[${monthList}]]*/ [];
var moneyList = /*[[${moneyList}]]*/ [];
// 指定图表的配置项和数据
option = {
xAxis: {
type: 'category',
data: monthList // 使用从后端传递过来的月份数据
},
yAxis: {},
series: [
{
data: moneyList, // 使用从后端传递过来的金额数据
type: 'line'
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
</body>
</html>

View File

@ -24,5 +24,6 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,35 @@
package com.ruoyi.app.system.domain;
import java.math.BigDecimal;
public class ChatDomain {
private Integer id;
private BigDecimal total_money;
private Integer month;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public BigDecimal getTotal_money() {
return total_money;
}
public void setTotal_money(BigDecimal total_money) {
this.total_money = total_money;
}
public Integer getMonth() {
return month;
}
public void setMonth(Integer month) {
this.month = month;
}
}

View File

@ -0,0 +1,19 @@
package com.ruoyi.app.system.mapper;
import com.ruoyi.app.system.domain.ChatDomain;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface ChatMapper {
@Select("SELECT SUM(money) AS total_money, month \n" +
"FROM accounttb \n" +
"WHERE `month` IS NOT NULL\n" +
"GROUP BY month \n" +
"ORDER BY month;\n")
public List<ChatDomain> pyline();
}