Home forums Using CanvasJS Transform jstl view code to thymeleaf code

This topic contains 2 replies, has 2 voices, and was last updated by  Priyanka M S 3 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21956

    taszta
    Member

    Hello everybody,

    I’m using Thymeleaf template in place of jsp and i woul like to convert this code of the view in thymeleaf code .

    thank you in advance for any advice

    <!– 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>

    #21957

    taszta
    Member

    #21960

    Priyanka M S
    Member

    @taszta,

    Passing dataPoints to charts in the above thymeleaf code should work fine in your case.

    Here is a thread which might be of help.

    __
    Priyanka M S
    Team CanvasJS

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.