<%@ 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", "1 Star"); map.put("y", 8889513); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "2 Star"); map.put("y", 3168220); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "3 Star"); map.put("y", 6611718); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "4 Star"); map.put("y", 11331319); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "5 Star"); map.put("y", 43476553); 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", { theme: "light2", title: { text: "Facebook for Android - App Rating" }, subtitles: [{ text: "December 2017" }], axisY: { title: "Number of Users", labelFormatter: addSymbols }, data: [{ type: "bar", indexLabel: "{y}", indexLabelFontColor: "#444", indexLabelPlacement: "inside", dataPoints: <%out.print(dataPoints);%> }] }); chart.render(); function addSymbols(e) { var suffixes = ["", "K", "M", "B"]; var order = Math.max(Math.floor(Math.log(Math.abs(e.value)) / Math.log(1000)), 0); if(order > suffixes.length - 1) order = suffixes.length - 1; var suffix = suffixes[order]; return CanvasJS.formatNumber(e.value / Math.pow(1000, order)) + suffix; } } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script> </body> </html>