<%@ 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", "Two Seaters"); map.put("y", new Integer[] {600,4200}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Minicompact Cars"); map.put("y", new Integer[] {1450,3550}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Subcompact Cars"); map.put("y", new Integer[] {550,3370}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Compact Cars"); map.put("y", new Integer[] {800,2750}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Midsize Cars"); map.put("y", new Integer[] {500,3250}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Large Cars"); map.put("y", new Integer[] {650,3300}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Small Station Wagons"); map.put("y", new Integer[] {550,2100}); list.add(map); map = new HashMap<Object,Object>(); map.put("label", "Midsize Station Wagons"); map.put("y", new Integer[] {1600,2550}); 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: "Annual Fuel Cost Ranges" }, subtitles: [{ text: "Based on Vehicle Classes" }], axisY: { title: "Annual Fuel Cost", prefix: "$", lineThickness: 1 }, data: [{ type: "rangeBar", indexLabel: "{y[#index]}", yValueFormatString: "$#,##0", 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>