nas-denar/views/partial/barchart.ejs
2017-09-14 20:06:51 +02:00

355 lines
13 KiB
Plaintext

<script>
<% if(narociladelez_organ.length > 0) { %>
var config5 = {
type: 'pie',
data: {
datasets: [{
data: [ /* vsotanarocil = <%= vsotanarocil %> */
<%
var znesek_ostalih = vsotanarocil;
for(var i = 0; i < narociladelez_organ.length; i++) {
znesek_ostalih -= narociladelez_organ[i].znesek;
%>
<%= narociladelez_organ[i].znesek %>,
<% } %>
<%= znesek_ostalih %>
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Deleži naročil'
}],
labels: [
<% for(var i = 0; i < narociladelez_organ.length; i++) { %>
'<%= narociladelez_organ[i].ponudnik.replace('&', ' in ').substring(0,30) + '...' %>',
<% } %>
'ostali'
]
},
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Naročila <%= vsotanarocil %> €'
}
}
}
<% } %>
<% if(narociladelez_podj.length > 0) { %>
var config6 = {
type: 'pie',
data: {
datasets: [{
data: [ /* vsotanarocil = <%= vsotanarocil %> */
<%
var znesek_ostalih = vsotanarocil;
for(var i = 0; i < narociladelez_podj.length; i++) {
znesek_ostalih -= narociladelez_podj[i].znesek;
%>
<%= narociladelez_podj[i].znesek %>,
<% } %>
<%= znesek_ostalih %>
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Deleži naročil'
}],
labels: [
<% for(var i = 0; i < narociladelez_podj.length; i++) { %>
'<%= narociladelez_podj[i].narocnik.replace('&', ' in ').substring(0,30) + '...' %>',
<% } %>
'ostali'
]
},
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Naročila <%= vsotanarocil %> €'
}
}
}
<% } %>
<% if(dutbdelez.length > 0) { %>
var config = {
type: 'pie',
data: {
datasets: [{
data: [
<% for(var i = 0; i < dutbdelez.length; i++) { %>
<%= dutbdelez[i].znesek %>,
<% } %>
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Deleži financiranja slabih kreditov'
}],
labels: [
<% for(var i = 0; i < dutbdelez.length; i++) { %>
'<%= dutbdelez[i].kreditodajalec %>',
<% } %>
]
},
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Slabi krediti'
}
}
}
<% } %>
<% if(tecajnica.length > 0) { %>
var config4 = {
type: 'line',
backgroundColor: "rgba(220,220,220,0.2)",
data: {
labels: [
<% for(var i = 0; i < tecajnica.length; i++) { %>
'<%= tecajnica[i].datum_tecajnice %>',
<% } %>
],
datasets: [{
label: "Tečajnica",
data: [
<% for(var i = 0; i < tecajnica.length; i++) { %>
'<%= tecajnica[i].tocke %>',
<% } %>
],
//fill: false,
//strokeColor: "rgba(106,94,119,0.9)",
pointRadius : 0,
strokeColor: "rgba(151,187,205,1)",
fillColor: "rgba(151,187,205,0.2)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
//datasetFill : true,
//bezierCurve : false,
//borderDash: [5, 5],
//point: {
beginAtZero: false,
radius: 0,
borderWidth: 0,
hitRadius: 0,
hoverRadius: 0,
hoverBorderWidth: 0,
borderColor: "rgba(151,187,205,1)",
fillColor: "rgba(151,187,205,0.2)",
backgroundColor: "rgba(220,220,220,0.2)",
//},
}]
},
options: {
responsive: true,
tooltips: {
mode: 'label',
callbacks: {
//beforeTitle: function() {
// return '...beforeTitle';
//},
//afterTitle: function() {
// return '...afterTitle';
//},
//beforeBody: function() {
// return '...beforeBody';
//},
//afterBody: function() {
// return '...afterBody';
//},
//beforeFooter: function() {
// return '...beforeFooter';
//},
//footer: function() {
// return 'Footer';
//},
//afterFooter: function() {
// return '...afterFooter';
//},
}
},
hover: {
mode: 'dataset'
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
show: true,
labelString: 'Dan'
}
}],
yAxes: [{
display: true,
scaleLabel: {
show: true,
labelString: 'Vrednost'
},
ticks: {
beginAtZero: false,
//suggestedMin: -10,
//suggestedMax: 250,
}
}]
}
}
};
<% } %>
<% if(grafEvidence.length > 0) { %>
var config2 = {
type: 'pie',
data: {
datasets: [{
data: [
<% for(var i = 0; i < grafEvidence.length; i++) { %>
<%= grafEvidence[i].globa %>,
<% } %>
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Deleži glob'
}],
labels: [
<% for(var i = 0; i < grafEvidence.length; i++) { %>
'<%= grafEvidence[i].organ %>',
<% } %>
]
},
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Globe'
}
}
}
<% } %>
<%
if(transakcije.length > 31) {
var mesec = ["jan", "feb", "mar", "apr", "maj", "jun", "jul", "avg", "sep", "okt", "nov", "dec"];
var labels = [];
var trenutnoLeto = new Date().getFullYear();
var trenutniMesec = ((new Date().getFullYear() - 2003) * 12 + new Date().getMonth()) + 1;
for (var i = 0; i < trenutniMesec; i++) {
if(i%12 == 0) {
labels.push((Math.round(i/12) + 2003).toString() + ' ' + (mesec[i%12]).toString());
} else labels.push((mesec[i%12]).toString());
}
} else {
var labels = [];
for (var i = 0; i < 31; i++) {
labels.push((i+1).toString());
}
}
%>
var barChartData = {
labels:
<%- JSON.stringify(labels) %>,
datasets: [{
label: 'Transakcije',
backgroundColor: "rgba(106,94,119,0.9)",
data: <%- JSON.stringify(transakcije) %>
}]
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
var elmnt = document.getElementById("transakcije-graf");
ctx.canvas.height = 500;
ctx.canvas.width = elmnt.clientWidth;
window.myBar = new Chart(ctx, {
type: 'bar',
dutbdelez: <%= transakcije.length %>,
data: barChartData,
options: {
tooltips: {
mode: 'label'
},
responsive: true,
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true
}]
}
}
});
<% if(transakcije.length > 31 && sifrapu != -1 && davcna != -1) { %>
var holder = document.getElementById('canvas');
holder.onclick = function(evt) {
var activePoints = myBar.getElementAtEvent(evt);
//var activeBars = window.myBar.getBarsAtEvent(evt);
//alert("Index = " + activePoints[0]._index);
window.location = "/mesec/"+activePoints[0]._index+'/<%= sifrapu %>/<%= davcna %>';
}
<% } %>
////////////////////////////////////////////////////////
// Doughnut chart
////////////////////////////////////////////////////////
<% if(narociladelez_organ.length > 0) { %>
var ctx2 = document.getElementById("chart-narocila").getContext("2d");
window.myDoughnut = new Chart(ctx2, config5);
<% } %>
<% if(narociladelez_podj.length > 0) { %>
var ctx2 = document.getElementById("chart-narocila").getContext("2d");
window.myDoughnut = new Chart(ctx2, config6);
<% } %>
<% if(dutbdelez.length > 0) { %>
var ctx2 = document.getElementById("chart-area").getContext("2d");
window.myDoughnut = new Chart(ctx2, config);
<% } %>
<% if(grafEvidence.length > 0) { %>
var ctx3 = document.getElementById("chart-area2").getContext("2d");
window.myDoughnut2 = new Chart(ctx3, config2);
<% } %>
<% if(tecajnica.length > 0) { %>
var ctx4 = document.getElementById("chart-tecajnica").getContext("2d");
window.myDoughnut3 = new Chart(ctx4, config4);
<% } %>
<% if((grafEvidence.length > 0) || (dutbdelez.length > 0) || (tecajnica.length > 0)) { %>
//updateLegend();
<% } %>
};
</script>