Skip to content

Commit c772a9a

Browse files
committed
chart js embedded HTML
Invoice summary chart
1 parent 60e87e0 commit c772a9a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

example/src/main/webapp/chart.html

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
7+
</head>
8+
<body>
9+
10+
<script>
11+
12+
13+
fetch("http://localhost:8080/InvoiceSummaryServlet", {
14+
method: "GET",
15+
headers: new Headers({'content-type': 'application/json'}),
16+
mode: "no-cors"
17+
}).then(function (data) {//first function gets the data
18+
return data.json();
19+
}).then(function (myJson) {
20+
var data = myJson;
21+
var ctx = document.getElementById('myChart').getContext('2d');
22+
23+
var chart = new Chart(ctx, {
24+
// The type of chart we want to create
25+
type: 'line',
26+
27+
// The data for our dataset
28+
data: {
29+
labels: Object.keys(data),
30+
datasets: [{
31+
label: 'My First dataset',
32+
backgroundColor: 'rgb(39,29,255)',
33+
borderColor: 'rgb(39,29,255)',
34+
data: Object.values(data)
35+
}]
36+
},
37+
38+
// Configuration options go here
39+
options: {}
40+
});
41+
});
42+
</script>
43+
44+
45+
<canvas id="myChart"></canvas>
46+
47+
48+
</body>
49+
</html>

0 commit comments

Comments
 (0)