<%@ 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", "Q1"); map.put("y", 48); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q2"); map.put("y", 82); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q3"); map.put("y", 61); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q4"); map.put("y", 64); list.add(map); String dataPoints1 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "Q1"); map.put("y", 43); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q2"); map.put("y", 31); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q3"); map.put("y", 41); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q4"); map.put("y", 71); list.add(map); String dataPoints2 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "Q1"); map.put("y", 23); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q2"); map.put("y", 42); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q3"); map.put("y", 32); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q4"); map.put("y", 34); list.add(map); String dataPoints3 = gsonObj.toJson(list); list = new ArrayList<Map<Object,Object>>(); map = new HashMap<Object,Object>(); map.put("label", "Q1"); map.put("y", 17); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q2"); map.put("y", 52); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q3"); map.put("y", 25); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Q4"); map.put("y", 34); 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, title:{ text: "Sales of ACME" }, subtitles: [{ text: "Based on Sales-Channels" }], axisY: { suffix: "%" }, toolTip: { shared: true, reversed: true }, legend: { reversed: true, horizontalAlign: "right", verticalAlign: "center" }, data: [{ type: "stackedColumn100", name: "WholeSale", showInLegend: true, yValueFormatString: "#,##0\"%\"", dataPoints: <%out.print(dataPoints1);%> }, { type: "stackedColumn100", name: "Retail", showInLegend: true, yValueFormatString: "#,##0\"%\"", dataPoints: <%out.print(dataPoints2);%> }, { type: "stackedColumn100", name: "Inside Sales", showInLegend: true, yValueFormatString: "#,##0\"%\"", dataPoints: <%out.print(dataPoints3);%> }, { type: "stackedColumn100", name: "Mail Order", showInLegend: true, yValueFormatString: "#,##0\"%\"", dataPoints: <%out.print(dataPoints4);%> }] }); 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>