<%@ 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", "2000"); map.put("y", 43); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2001"); map.put("y", 49); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2002"); map.put("y", 59); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2003"); map.put("y", 62); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2004"); map.put("y", 65); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2005"); map.put("y", 68); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2006"); map.put("y", 69); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2007"); map.put("y", 75); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2008"); map.put("y", 74); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2009"); map.put("y", 71); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2010"); map.put("y", 72); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2011"); map.put("y", 70); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2012"); map.put("y", 75); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2013"); map.put("y", 72); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2014"); map.put("y", 73); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2015"); map.put("y", 75); list.add(map); String dataPoints = 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", { theme: "light2", title: { text: "Internet Use in United States" }, subtitles: [{ text: "2000 to 2015" }], axisY:{ title: "Percent of Population", suffix: "%" }, data: [{ type: "spline", toolTipContent: "<b>{label}</b>: {y}%", dataPoints: <%out.print(dataPoints);%> }] }); 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>