<!-- 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,
theme : "light2", // "light1", "dark1", "dark2"
title : {
text : "Deforestation in Brazilian Amazon"
},
axisY : {
title : "Annual Forest Loss (in sq. km)",
labelFormatter : addSymbols
},
data : [ {
type : "area",
markerSize : 0,
yValueFormatString : "#,##0 sq. km",
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();
function addSymbols(e) {
var suffixes = [ "", "K", "M", "B" ];
var order = Math.max(Math.floor(Math.log(Math.abs(e.value)) / Math.log(1000)), 0);
if (order > suffixes.length - 1)
order = suffixes.length - 1;
var suffix = suffixes[order];
return CanvasJS.formatNumber(e.value / Math.pow(1000, order)) + suffix;
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
</body>
</html>
//CanvasjsChartData.java
package com.canvasjs.chart.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CanvasjsChartData {
static Map<Object,Object> map = null;
static List<List<Map<Object,Object>>> list = new ArrayList<List<Map<Object,Object>>>();
static List<Map<Object,Object>> dataPoints1 = new ArrayList<Map<Object,Object>>();
static {
map = new HashMap<Object,Object>(); map.put("label", "1988"); map.put("y", 21050);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1989"); map.put("y", 17770);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1990"); map.put("y", 13730);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1991"); map.put("y", 11030);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1992"); map.put("y", 13786);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1993"); map.put("y", 14896);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1994"); map.put("y", 14896);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1995"); map.put("y", 29059);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1996"); map.put("y", 18161);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1997"); map.put("y", 13227);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1998"); map.put("y", 17383);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "1999"); map.put("y", 17259);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2000"); map.put("y", 18226);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2001"); map.put("y", 18165);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2002"); map.put("y", 21651);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2003"); map.put("y", 25396);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2004"); map.put("y", 27772);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2005"); map.put("y", 19014);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2006"); map.put("y", 14285);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2007"); map.put("y", 11651);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2008"); map.put("y", 12911);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2009"); map.put("y", 7464);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2010"); map.put("y", 7000);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2011"); map.put("y", 6418);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2012"); map.put("y", 4571);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2013"); map.put("y", 5891);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2014"); map.put("y", 5012);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2015"); map.put("y", 6207);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2016"); map.put("y", 7893);dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("label", "2017"); map.put("y", 6624);dataPoints1.add(map);
list.add(dataPoints1);
}
public static List<List<Map<Object, Object>>> getCanvasjsDataList() {
return list;
}
}