Convertir du code du jstl avec javascript en thymeleaf
Bonjour ,
J'utilise le framework thymeleaf avec spring boot et j'ai trouvé un morceau du code qui m'intersse mais il est en javascript avec du jsp, jstl .
J'aimerais savoir si qq'un saura m'aider a convertir ce bout de code de la vue en thymeleaf : J'ai des problemes avec les boucles surtout
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <!-- chart.jsp-->
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
window.onload = function() {
var dps = [[]];
var chart = new CanvasJS.Chart("chartContainer", {
exportEnabled: true,
animationEnabled: true,
theme: "light2", // "light1", "dark1", "dark2"
title: {
text: "Visitor Demographics of a Website"
},
subtitles: [{
text: "Age Groups of Visitors"
}],
data: [{
type: "pie",
yValueFormatString: "#,##0\"%\"",
indexLabel: "{label} - {y}",
dataPoints: dps[0]
}]
});
var yValue;
var label;
<c:forEach items="${dataPointsList}" var="dataPoints" varStatus="loop">
<c:forEach items="${dataPoints}" var="dataPoint">
yValue = parseFloat("${dataPoint.y}");
label = "${dataPoint.label}";
dps[parseInt("${loop.index}")].push({
label : label,
y : yValue,
});
</c:forEach>
</c:forEach>
chart.render();
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
@Controller
@RequestMapping("/canvasjschart")
public class CanvasjsChartController {
@Autowired
private CanvasjsChartService canvasjsChartService;
@RequestMapping(method = RequestMethod.GET)
public String springMVC(ModelMap modelMap) {
List<List<Map<Object, Object>>> canvasjsDataList = canvasjsChartService.getCanvasjsChartData();
modelMap.addAttribute("dataPointsList", canvasjsDataList);
return "chart";
}
} |
Merci beaucoup pour votre aide