-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartjs_example.js
111 lines (104 loc) · 3.45 KB
/
chartjs_example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
chartJS references:
https://www.chartjs.org/docs/latest/getting-started/installation.html
https://cdnjs.com/libraries/Chart.js
*/
/*
html:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js" integrity="sha512-CQBWl4fJHWbryGE+Pc7UAxWMUMNMWzWxF4SQo9CgkJIN1kx6djDQZjh3Y8SZ1d+6I+1zze6Z7kHXO7q3UyZAWw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<canvas id="cve-chart"></canvas>
*/
const CHART_DATA_CVE = 'https://files.oxl.at/data/cve_statistics.json';
var CHART_CVE_LABELS = [];
var CHART_CVE_COUNT = [];
var CHART_CVE_LOW = [];
var CHART_CVE_MED = [];
var CHART_CVE_HIGH = [];
var CHART_CVE_CRIT = [];
function fetchChartData(url, callback) {
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
let resp = JSON.parse(this.responseText);
callback(resp);
}
};
http.open("GET", url, true);
http.send();
}
function renderCVEChart() {
var mixChart = new Chart(document.getElementById("cve-chart").getContext('2d'), {
type: 'bar',
data: {
labels: CHART_CVE_LABELS,
datasets: [
{
type: 'line',
label: "Low",
data: CHART_CVE_LOW,
borderColor: 'rgba(238, 210, 2, 0.9)',
backgroundColor: 'rgba(238, 210, 2, 0.9)',
},
{
type: 'line',
label: "Medium",
data: CHART_CVE_MED,
borderColor: 'rgba(255, 120, 0, 0.9)',
backgroundColor: 'rgba(255, 120, 0, 0.9)',
},
{
type: 'line',
label: "High",
data: CHART_CVE_HIGH,
borderColor: 'rgba(237, 67, 55, 0.9)',
backgroundColor: 'rgba(237, 67, 55, 0.9)',
},
{
type: 'line',
label: "Critical",
data: CHART_CVE_CRIT,
borderColor: 'rgba(139, 0, 0, 0.9)',
backgroundColor: 'rgba(139, 0, 0, 0.9)',
},
{
label: "Overall",
data: CHART_CVE_COUNT,
borderColor: 'rgba(0, 0, 0, 0)',
backgroundColor: 'rgba(244, 233, 140, 0.8)',
}
]
},
options: {
responsive: true,
title: {
display: true,
text: 'Reported Vulnerabilities'
},
tooltips: {
mode: 'index',
intersect: true
},
scales: {
xAxes: [{
stacked: true,
}]
}
}
});
}
function updateCVEChart(resp) {
for (let [year, values] of Object.entries(resp)) {
CHART_CVE_LABELS.push(year);
CHART_CVE_COUNT.push(values.count);
CHART_CVE_LOW.push(values.count_severity.low);
CHART_CVE_MED.push(values.count_severity.med);
CHART_CVE_HIGH.push(values.count_severity.high);
CHART_CVE_CRIT.push(values.count_severity.crit + values.count_severity.dis);
console.log(year, values);
}
renderCVEChart();
}
function buildCVEChart() {
fetchChartData(CHART_DATA_CVE, updateCVEChart);
}
buildCVEChart();