-
Notifications
You must be signed in to change notification settings - Fork 0
/
risk_scores_chart.html
102 lines (95 loc) · 2.34 KB
/
risk_scores_chart.html
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
<!doctype html>
<html>
<head>
<title>Line Chart</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.2/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div style="width:80%;">
<canvas id="canvas"></canvas>
</div>
<br>
<br>
<script>
var timeFormat = 'MM/DD/YYYY HH:mm';
//Declare functions for generating random colors
function randomColorFactor() {
return Math.round(Math.random() * 255);
}
function randomColor(opacity) {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
}
//Begin reading in the data
$.getJSON('sample_risk_score_data.json')
.done(function(data){
var config = {
type: 'line',
data: {datasets: []},
options: {
responsive: true,
title:{
display:true,
text:"Risk Score vs. Time for Various Hosts"
},
scales: {
xAxes: [{
type: "time",
time: {
format: timeFormat,
tooltipFormat: 'll HH:mm'
},
scaleLabel: {
display: true,
labelString: 'Date/Time'
}
}, ],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Risk score'
}
}]
},
}
};
var ctx = document.getElementById("canvas").getContext("2d");
var myLine = new Chart(ctx, config);
//Create new dataset
$.each(data, function(asset_id, asset_data) {
var color = randomColor(0.6);
scores = asset_data["risk_scores"];
var newDataset = {
label: 'Asset ' + asset_id,
borderColor: color,
backgroundColor: color,
pointBorderColor: color,
pointBackgroundColor: color,
pointBorderWidth: 1,
fill: false,
lineTension: 0,
data: [],
};
//Populate the dataset
for (var i = 0; i < scores.length; ++i) {
newDataset.data.push({
x: Date.parse(scores[i][0]),
y: scores[i][1],
});
}
//Add the dataset to config
config.data.datasets.push(newDataset);
myLine.update();
})
});
</script>
</body>
</html>