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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
// Funkcija za graf pri kvizu
function init_quiz_results_chart(all, correct, incorrect, correct_title, incorrect_title){
var horizontalBarChartData = {
datasets: [{
label: correct_title,
backgroundColor: "rgba(102, 194, 74, 0.8)",
borderColor: "rgba(102, 194, 74, 0.8)",
borderWidth: 1,
data: [correct]
}, {
label: incorrect_title,
backgroundColor: "rgba(220, 0, 0, 0.7)",
borderColor: "rgba(220, 0, 0, 0.7)",
data: [incorrect]
}]
};
// Define a plugin to provide data labels
Chart.plugins.register({
afterDatasetsDraw: function(chart, easing) {
// To only draw at the end of animation, check for easing === 1
var ctx = chart.ctx;
chart.data.datasets.forEach(function (dataset, i) {
var meta = chart.getDatasetMeta(i);
if (!meta.hidden) {
meta.data.forEach(function(element, index) {
// Draw the text in black, with the specified font
ctx.fillStyle = 'rgb(0, 0, 0)';
var fontSize = 15;
var fontStyle = 'bold';
var fontFamily = 'Arial';
ctx.font = Chart.helpers.fontString(fontSize, fontStyle, fontFamily);
// Just naively convert to string for now
var dataString = dataset.data[index].toString() + ' (' + Math.round((dataset.data[index] / all * 1000) / 10) + '%)';
// Make sure alignment settings are correct
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
var padding = 0;
var position = element.tooltipPosition();
var x_pos = position.x / 2;
if(x_pos < 10)
x_pos = 45;
var y_pos = position.y - (fontSize / 2) - padding + 10;
ctx.fillText(dataString, x_pos, y_pos);
});
}
});
}
});
var ctx = document.getElementById("quiz_results_chart").getContext("2d");
window.myHorizontalBar = new Chart(ctx, {
type: 'horizontalBar',
data: horizontalBarChartData,
options: {
elements: {
rectangle: {
borderWidth: 1,
}
},
responsive: true,
maintainAspectRatio: false,
scales: {
xAxes: [{
ticks: {
//display: false,
padding: 5,
min: 0,
max: all,
stepSize: 1,
mirror: true
}
}]
},
legend: {
display: false
}
}
});
}
// Funkcija za poseben modul excelleration matrix
function init_excell_matrix(x_axis, y_axis, rad){
// Radius prilagodimo ce je prevelik/premajhen
var radius = rad / 12.5;
if(radius > 80)
radius = 80;
if(radius < 8)
radius = 8;
// Inicializiramo graf
var ctx = document.getElementById("excell_matrix_chart");
// Nastavimo podatke
var popData = {
datasets: [{
label: ['Blagovna znamka'],
data: [{
x: x_axis,
y: y_axis,
r: radius
}],
backgroundColor: "rgba(220, 0, 0, 0.7)",
hoverBackgroundColor: "rgba(220, 0, 0, 0.8)",
}]
};
var myChart = new Chart(ctx, {
type: 'bubble',
data: popData,
options: {
tooltips: {
custom: function(tooltip) {
if (!tooltip) return;
// disable displaying the color box;
tooltip.displayColors = false;
},
callbacks: {
label: function(t, d) {
//var multistringText = ['Blagovna znamka:'];
//multistringText.push(' Excelleration: ' + x_axis);
var multistringText = ['Odličnost: ' + x_axis];
multistringText.push('Marža: ' + y_axis);
multistringText.push('Letni promet: ' + rad);
return multistringText;
/*/return 'Blagovna znamka:<br > ' + x_axis + ', ' + y_axis + ', ' + rad;*/
/*return d.datasets[t.datasetIndex].label +
': (Day:' + t.xLabel + ', Total:' + t.rLabel + ')';*/
}
}
},
scales: {
yAxes: [{
ticks: {
display: false,
padding: 5,
min: 0,
max: 6,
stepSize: 0.5,
/*min: 0,
max: 6,*/
callback: function(value, index, values) {
if(value == 3)
return value;
else
return;
}
},
scaleLabel: {
display: true,
labelString: 'Odličnost blagovne znamke',
fontStyle: 'bold',
fontSize: '14',
},
gridLines: {
color: "rgba(10, 10, 10, 1)",
drawBorder: false
},
position: 'right'
}],
xAxes: [{
ticks: {
display: false,
padding: 5,
min: 0,
max: 6,
stepSize: 0.5,
/*min: 0,
max: 6,*/
callback: function(value, index, values) {
if(value == 3)
return value;
else
return;
}
},
scaleLabel: {
display: true,
labelString: 'Marža blagovne znamke',
fontStyle: 'bold',
fontSize: '14'
},
gridLines: {
color: "rgba(10, 10, 10, 1)",
drawBorder: false
},
position: 'top'
}]
},
legend: {
display: false
},
layout: {
padding: {
left: 20,
right: 40,
top: 30,
bottom: 30
}
}
}
});
}
// Funkcija za poseben modul radar chart - skavti
function init_skavti_radar(labels, pohvale, izzivi){
// Inicializiramo graf
var ctx = document.getElementById("skavti_radar_chart");
// Podatki grafa
var data = {
labels: labels,
datasets: [{
data: pohvale,
label: "Pohvale",
backgroundColor: "rgba(30,136,229,0.6)"
},
{
data: izzivi,
label: "Izzivi",
backgroundColor: "rgba(200,0,0,0.5)"
}]
};
// Nastavitve grafa
var options = {
scale: {
angleLines: {
display: false
},
ticks: {
max: 10,
min: 0,
stepSize: 1
},
}
};
/*Chart.defaults.global.defaultFontSize = 15;*/
var radarChart = new Chart(ctx, {
type: 'radar',
data: data,
options: options
});
}
|