<!-- chart.jsp-->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
window.onload = function() {
var dps = [[]];
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light2", // "light1", "dark1", "dark2"
animationEnabled: true,
exportEnabled: true,
title: {
text: "NIKE Inc. Stock Price"
},
subtitles: [{
text: "January 2018"
}],
axisX: {
valueFormatString: "DD MMM"
},
axisY: {
title: "Price (in USD)",
prefix: "$"
},
data: [{
type: "ohlc",
xValueType: "dateTime",
xValueFormatString: "DD MMM",
yValueFormatString: "$#,##0.00",
dataPoints: dps[0]
}]
});
var yValue;
var xValue;
<c:forEach items="${dataPointsList}" var="dataPoints" varStatus="loop">
<c:forEach items="${dataPoints}" var="dataPoint">
yValue = [parseFloat("${dataPoint.y[0]}"), parseFloat("${dataPoint.y[1]}"), parseFloat("${dataPoint.y[2]}"), parseFloat("${dataPoint.y[3]}")];
xValue = parseFloat("${dataPoint.x}");
dps[parseInt("${loop.index}")].push({
x : xValue,
y : yValue,
});
</c:forEach>
</c:forEach>
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>
//CanvasjsChartData.java
package com.canvasjs.chart.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CanvasjsChartData {
static Map<Object,Object> map = null;
static List<List<Map<Object,Object>>> list = new ArrayList<List<Map<Object,Object>>>();
static List<Map<Object,Object>> dataPoints1 = new ArrayList<Map<Object,Object>>();
static {
map = new HashMap<Object,Object>(); map.put("x", 1514831400000L); map.put("y", new Double[] {62.84, 63.49, 62.84, 63.49});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1514917800000L); map.put("y", new Double[] {63.48, 63.66, 62.75, 63.48});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515004200000L); map.put("y", new Double[] {63.40, 63.54, 62.54, 63.43});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515090600000L); map.put("y", new Double[] {63.70, 64.30, 63.47, 63.98});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515349800000L); map.put("y", new Double[] {64.15, 64.70, 63.98, 64.55});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515436200000L); map.put("y", new Double[] {64.23, 64.72, 63.47, 64.08});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515522600000L); map.put("y", new Double[] {63.88, 64.23, 63.43, 64.22});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515609000000L); map.put("y", new Double[] {64.02, 64.30, 63.77, 64.29});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1515695400000L); map.put("y", new Double[] {64.50, 64.72, 64.32, 64.66});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516041000000L); map.put("y", new Double[] {64.77, 65.36, 63.36, 63.41});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516127400000L); map.put("y", new Double[] {63.66, 64.01, 63.08, 63.81});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516213800000L); map.put("y", new Double[] {64.00, 64.20, 63.54, 64.11});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516300200000L); map.put("y", new Double[] {65.30, 67.23, 65.12, 67.20});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516559400000L); map.put("y", new Double[] {66.55, 66.83, 65.76, 66.38});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516645800000L); map.put("y", new Double[] {66.52, 67.33, 66.44, 67.13});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516732200000L); map.put("y", new Double[] {67.33, 68.18, 67.07, 68.00});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516818600000L); map.put("y", new Double[] {68.12, 68.63, 67.44, 67.70});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1516905000000L); map.put("y", new Double[] {68.19, 68.63, 67.91, 68.04});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1517164200000L); map.put("y", new Double[] {67.82, 68.13, 67.41, 67.58});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1517250600000L); map.put("y", new Double[] {67.50, 68.30, 67.16, 67.33});dataPoints1.add(map);
map = new HashMap<Object,Object>(); map.put("x", 1517337000000L); map.put("y", new Double[] {67.50, 68.83, 67.47, 68.22});dataPoints1.add(map);
list.add(dataPoints1);
}
public static List<List<Map<Object, Object>>> getCanvasjsDataList() {
return list;
}
}