I want to create a chart with Chart.bundle.js. The data in the graph must come from the database. A servlet sends the data to the JSP. My problem is how to put the data received from the servlet into "labels" and "data". My example is below.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<input type="hidden" name="donnee" id="donnee" value="${donnees }" />
<c:out value="${donnees }"></c:out>
<input type="hidden" name="etiquete" id="etiquete" value="${etiquetes}" />
<c:out value="${etiquetes }"></c:out>
<div style="width:80%">
<canvas id="myChart" ></canvas>
</div>
<script>
var donnees=document.getElementById("donnee");
var etiquetes=document.getElementById("etiquete");
var myContext = document.getElementById("myChart");
var myChartConfig = {
type: 'bar',
data: {
labels:etiquetes,
datasets: [
{
label: "etiquette n°1",
data:donnees,
backgroundColor: ['green','yellow','red'],
},
]
}
}
var myChart = new Chart(myContext, myChartConfig);
</script>