how can i draw graph in spring mvc in jsp using highchart
Francisco Gallardo:
i want to draw graph in jsp unsando spring mvc and highchart but i still can't do it, i wait for your answer thanks
My point, this is where I want to draw the graph, but the graph is not showing, it shows nothing
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Chart</title>
<script src="resources/assets/js/highcharts.js"></script>
<script src="resources/assets/js/highcharts-3d.js"></script>
<!-- <script src="resources/assets/js/jquery.js"></script> -->
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
</head>
<body class="page-container-bg-solid">
<div class="page-container">
<div class="page-content-wrapper">
<div class="page-head" style="background-color:#eff3f8;padding-top:40px">
<div class="container">
<div class="row" style="margin-bottom:30px">
<div class="col-md-6">
<h1>my Chart</h1>
</div>
</div>
<div class="row" style="margin-bottom:30px">
<div class="col-md-6" style="margin-top:20px">
<div id="mychart" style="width:100%; height:400px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
drawSalesByTypeChart();
drawSalesByRegionChart();
});
function drawSalesByRegionChart() {
var salesByRegionChart = Highcharts.chart('mychart', {
chart: {
type: 'pie',
margin: 40,
options3d: {
enabled: true,
alpha: 45,
beta: 0
}
},
title: {
text: 'Sales by Region'
},
plotOptions: {
pie: {
allowPointSelect: true,
depth: 35
}
},
series: [{
name: 'Regions',
colorByPoint:true,
data: [{
name: 'Northeast',
y: [[${listGraph}]]
}
]
}]
});
}
</script>
</body>
</html>
my controller
@RequestMapping(value = "/graphReport")
public String combo(QcReport qc, Model model) throws IOException {
List<QcReport> listGraph = assayServ.listGraphAssay();
model.addAttribute("listGraph", listGraph);
return ("graphReport");
}
bkbb:
When I compare your work in the tutorial below:
https://careydevelopment.us/2017/07/01/add-charts-spring-boot-app-highchart/
You are trying to draw a pie chart which expects integer values when passed a list ${listGraph}.
series: [{
name: 'Regions',
colorByPoint:true,
data: [{
name: 'Northeast',
y: [[${listGraph}]]
}
]