<%@ 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("x", 0); map.put("y", 3); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.02); map.put("y", 4); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.06); map.put("y", 5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.11); map.put("y", 6); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.17); map.put("y", 7); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.33); map.put("y", 6); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.4); map.put("y", 5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.45); map.put("y", 4); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.5); map.put("y", 3); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.55); map.put("y", 2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.6); map.put("y", 1); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.67); map.put("y", 0); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.83); map.put("y", 1); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.89); map.put("y", 2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 0.93); map.put("y", 3); 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", { title: { text: "Output of 3 Bit Analog to Digital Converter" }, axisX: { title: "Timestamp (in ms)" }, axisY: { title: "Quantized Levels", labelFormatter: function(e){ return CanvasJS.formatNumber(parseInt(e.value, 10).toString(2), "000"); }, maximum: 7.1, interval: 1 }, toolTip: { contentFormatter: function (e){ return "<b>" + e.entries[0].dataPoint.x + "ms</b>: " + CanvasJS.formatNumber(parseInt(e.entries[0].dataPoint.y, 10).toString(2), "000"); } }, data: [{ type: "stepLine", 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>