我一直在处理一些导入到html表中的数据库数据。然后我决定我需要把这些数据放到条形图上。
有办法吗?如果是,你能告诉我怎么做吗?
html(警告代码片段在这里实际上不起作用,但在我的应用程序中起作用):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<div>
<a href="http://localhost:8088">Go Back</a>
</div>
</head>
<body>
<table id = "tableContent">
<thead>
<tr>
<th>Region</th>
<th>Total Cases</th>
</tr>
</thead>
<tbody>
<c:forEach var = "covid_table" items ="${covidapi}">
<tr>
<td>${covid_table.getName()}</td>
<td>${covid_table.getTotal_cases()}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
这是我在工作版本中使用的html代码
新html代码:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<div>
<a href="http://localhost:8088">Go Back</a>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script type="text/javascript">
$(function() {
Highcharts.chart('container', {
data: {
table: 'tableContent'
},
chart: {
type: 'column'
},
title: {
text: 'Data extracted from a HTML table in the page'
},
yAxis: {
allowDecimals: false,
title: {
text: 'Units'
}
},
tooltip: {
formatter: function() {
return '<b>' + this.series.name + '</b><br/>' +
this.point.y + ' ' + this.point.name.toLowerCase();
}
}
});
});
</script>
</head>
<body>
<div id="container" style="width: 100%; height: 400px;"> </div>
<table id = "tableContent">
<thead>
<tr>
<th>Region</th>
<th>Total Cases</th>
</tr>
</thead>
<tbody>
<c:forEach var = "covid_table" items ="${covidapi}">
<tr>
<td>${covid_table.getName()}</td>
<td>${covid_table.getTotal_cases()}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
1条答案
按热度按时间jhiyze9q1#
如果您有来自api的数据,那么您需要更改的是表示层。
下面是一个处理一组数据的小片段(这是一个完整的javascript解决方案):