<%@ 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", 4.36); map.put("y", 16.9); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 4.054); map.put("y", 15.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.605); map.put("y", 19.2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.94); map.put("y", 18.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.155); map.put("y", 30); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.56); map.put("y", 27.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.3); map.put("y", 27.2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.23); map.put("y", 30.9); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.83); map.put("y", 20.3); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.14); map.put("y", 19.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.795); map.put("y", 21.6); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.41); map.put("y", 16.2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.38); map.put("y", 20.6); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.07); map.put("y", 20.8); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.62); map.put("y", 18.6); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.41); map.put("y", 18.1); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.84); map.put("y", 17); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.725); map.put("y", 17.6); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.955); map.put("y", 16.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 3.83); map.put("y", 18.2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.585); map.put("y", 26.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.91); map.put("y", 21.9); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 1.975); map.put("y", 34.1); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 1.915); map.put("y", 35.1); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.67); map.put("y", 27.4); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 1.99); map.put("y", 31.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.135); map.put("y", 29.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.67); map.put("y", 28.4); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.595); map.put("y", 28.8); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.7); map.put("y", 26.8); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.556); map.put("y", 33.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.2); map.put("y", 34.2); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.02); map.put("y", 31.8); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.13); map.put("y", 37.3); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.19); map.put("y", 30.5); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.815); map.put("y", 22); list.add(map); map = new HashMap<Object,Object>(); map.put("x", 2.6); map.put("y", 21.5); 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", { animationEnabled: true, theme: "light2", title: { text: "Relationship b/w Weight and Fuel Economy of Cars" }, subtitles: [{ text: "Fuel Economy in Miles per Gallon(MPG)" }], axisY: { title: "Fuel Economy", includeZero: true }, axisX: { title: "Weight (in Thousand Pounds)" }, data: [{ type: "scatter", xValueFormatString: "#,##0.00 Thousand Pounds", yValueFormatString: "#,##0.00 Miles per Gallon", toolTipContent: "<b>Weight:</b> {x}, <br><b>Fuel Economy:</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>