<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="com.google.gson.Gson"%> <%@ page import="com.google.gson.JsonObject"%> <% Gson gsonObj = new Gson(); Map<Object,Object> map = null; List<Map<Object,Object>> list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "Jan"); map.put("y", 3.69); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Feb"); map.put("y", 3.06); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Mar"); map.put("y", 4.08); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Apr"); map.put("y", 4.06); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "May"); map.put("y", 4.48); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Jun"); map.put("y", 3.45); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Jul"); map.put("y", 4.17); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Aug"); map.put("y", 4.05); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Sep"); map.put("y", 4.05); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Oct"); map.put("y", 3.5); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Nov"); map.put("y", 4); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Dec"); map.put("y", 3.86); list.add(map); String dataPoints1 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "Jan"); map.put("y", new Double[] {3.6,3.8}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Feb"); map.put("y", new Double[] {3.0,3.4}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Mar"); map.put("y", new Double[] {3.8,4.3}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Apr"); map.put("y", new Double[] {3.9,4.2}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "May"); map.put("y", new Double[] {4.3,4.6}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Jun"); map.put("y", new Double[] {3.3,3.6}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Jul"); map.put("y", new Double[] {4.0,4.4}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Aug"); map.put("y", new Double[] {3.9,4.3}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Sep"); map.put("y", new Double[] {3.8,4.2}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Oct"); map.put("y", new Double[] {3.4,3.7}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Nov"); map.put("y", new Double[] {3.8,4.2}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Dec"); map.put("y", new Double[] {3.7,4.0}); list.add(map); String dataPoints2 = gsonObj.toJson(list); %> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"> window.onload = function() { var chart = new CanvasJS.Chart("chartContainer", { animationEnabled: true, theme: "light2", title:{ text: "Predicted Rainfall - 2018" }, axisX: { interval: 1 }, axisY:{ title: "Precipitation (in inches)", suffix: " in" }, toolTip: { shared: true }, data: [{ type: "line", name: "Predicted", toolTipContent: "<b>{label}</b><br>{name}: {y} in", markerType: "none", dataPoints: <%out.print(dataPoints1);%> }, { type: "error", name: "Error Range", toolTipContent: "{name}: {y[0]} in - {y[1]} in", dataPoints: <%out.print(dataPoints2);%> }] }); chart.render(); } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script> </body> </html>