Reputation: 231
I have problems with Thymeleaf and I don't know how can I do this.
<!-- 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", {
animationEnabled: true,
exportEnabled: true,
title: {
text: "Simple Column Chart with Index Labels"
},
data: [{
type: "column", //change type to bar, line, area, pie, etc
//indexLabel: "{y}", //Shows y value on all Data Points
indexLabelFontColor: "#5A5757",
dataPoints: dps[0]
}]
});
var xValue;
var yValue;
var indexLabel;
<c:forEach items="${dataPointsList}" var="dataPoints" varStatus="loop">
<c:forEach items="${dataPoints}" var="dataPoint">
xValue = parseInt("${dataPoint.x}");
yValue = parseFloat("${dataPoint.y}");
indexLabel = "${dataPoint.indexLabel}";
dps[parseInt("${loop.index}")].push({
x : xValue,
y : yValue,
indexLabel : indexLabel
});
</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>
I have just started using Thymeleaf, and the JSP format does not work for unknown reasons.
Upvotes: 0
Views: 7275
Reputation: 2511
This answer does not cover all aspect of converting jsp
to thymeleaf
but should give you some direction.
html
file chart.html
and save it under src/main/resource/templates
your html
should start with
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
Your loop will change from
<c:forEach items="${dataPointsList}" var="dataPoints" varStatus="loop">
to th:each="dataPoints:${dataPointsList}"
and <c:forEach items="${dataPoints}" var="dataPoint">
to th:each="dataPoint:${dataPoints}"
Take a look at thymeleaf documentation. They have good documentation.
Upvotes: 6