<%@ 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", "Leads"); map.put("y", 1400); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Initial Communication"); map.put("y", 1212); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Customer Evaluation"); map.put("y", 1080); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Negotiation"); map.put("y", 665); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Order Received"); map.put("y", 578); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Payment"); map.put("y", 549); 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", //"light1", "dark1", "dark2" title:{ text: "Sales Analysis - 2017" }, data: [{ type: "funnel", toolTipContent: "<b>{label}</b>: {y} <b>({percentage}%)</b>", indexLabel: "{label} ({percentage}%)", neckHeight: 0, dataPoints : <%out.print(dataPoints);%> }] }); calculatePercentage(); chart.render(); function calculatePercentage() { var dataPoint = chart.options.data[0].dataPoints; var total = dataPoint[0].y; for(var i = 0; i < dataPoint.length; i++) { if(i == 0) { chart.options.data[0].dataPoints[i].percentage = 100; } else { chart.options.data[0].dataPoints[i].percentage = ((dataPoint[i].y / total) * 100).toFixed(2); } } } } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script> </body> </html>