<%@ 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", "FY10"); map.put("y", 10.51); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY11"); map.put("y", 13.35); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY12"); map.put("y", 15.43); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY13"); map.put("y", 15.74); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY14"); map.put("y", 16.88); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY15"); map.put("y", 18.5); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY16"); map.put("y", 18.83); list.add(map); String dataPoints1 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "FY10"); map.put("y", 0.62); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY11"); map.put("y", 0.8); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY12"); map.put("y", 0.88); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY13"); map.put("y", 0.84); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY14"); map.put("y", 0.83); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY15"); map.put("y", 0.95); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY16"); map.put("y", 0.93); list.add(map); String dataPoints2 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "FY10"); map.put("y", 2.36); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY11"); map.put("y", 2.98); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY12"); map.put("y", 3.15); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY13"); map.put("y", 3.23); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY14"); map.put("y", 3.09); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY15"); map.put("y", 3.22); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY16"); map.put("y", 3.41); list.add(map); String dataPoints3 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "FY10"); map.put("y", 0.57); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY11"); map.put("y", 0.76); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY12"); map.put("y", 0.93); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY13"); map.put("y", 0.83); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY14"); map.put("y", 0.7); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY15"); map.put("y", 0.7); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "FY16"); map.put("y", 0.78); list.add(map); String dataPoints4 = 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: "Total Production of Automobiles in India" }, axisX: { title: "Financial Year" }, axisY: { title: "Production (in million units)" }, toolTip: { shared: true, reversed: true }, legend: { cursor: "pointer", itemclick: toggleDataSeries }, data: [{ type: "stackedArea100", name: "Two Wheelers", showInLegend: true, dataPoints: <%out.print(dataPoints1);%> }, { type: "stackedArea100", name: "Three Wheelers", showInLegend: true, dataPoints: <%out.print(dataPoints2);%> }, { type: "stackedArea100", name: "Passenger Vehicle", showInLegend: true, dataPoints: <%out.print(dataPoints3);%> }, { type: "stackedArea100", name: "Commercial Vehicles", showInLegend: true, dataPoints: <%out.print(dataPoints4);%> }] }); chart.render(); function toggleDataSeries(e) { if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) { e.dataSeries.visible = false; } else { e.dataSeries.visible = true; } e.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>