NDOJ/templates/stats/media-js.html

111 lines
2.6 KiB
HTML
Raw Permalink Normal View History

2020-01-21 06:35:58 +00:00
<script type="text/javascript" src="{{ static('libs/chart.js/Chart.js') }}"></script>
<script type="text/javascript">
2023-01-27 23:11:10 +00:00
function draw_pie_chart(data, $chart) {
var ctx = $chart.find('canvas')[0].getContext('2d');
var chart = new Chart(ctx, {
type: 'pie',
data: data,
options: {
maintainAspectRatio: false,
responsive: false,
animation: false,
legend: {
position: 'right',
labels: {
fontColor: 'black',
boxWidth: 20,
},
},
},
});
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function draw_bar_chart(data, $chart) {
var ctx = $chart.find('canvas')[0].getContext('2d');
ctx.canvas.height = 20 * data.labels.length + 100;
var chart = new Chart(ctx, {
type: 'horizontalBar',
data: data,
options: {
maintainAspectRatio: false,
legend: {
display: false,
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
return (Math.round(tooltipItem.value * 100) / 100) + '%';
2020-01-21 06:35:58 +00:00
},
2023-01-27 23:11:10 +00:00
},
},
},
});
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function draw_stacked_bar_chart(data, $chart) {
var ctx = $chart.find('canvas')[0].getContext('2d');
ctx.canvas.height = 20 * data.labels.length + 100;
var chart = new Chart(ctx, {
type: 'horizontalBar',
data: data,
options: {
maintainAspectRatio: false,
tooltips: {
mode: 'index',
intersect: false,
},
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true,
}],
},
},
});
}
function draw_histogram(data, $chart) {
var ctx = $chart.find('canvas')[0].getContext('2d');
ctx.canvas.height = 20 * data.labels.length + 100;
var chart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
maintainAspectRatio: false,
legend: {
display: false,
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
return tooltipItem.value;
2021-06-02 00:20:39 +00:00
},
2023-01-27 23:11:10 +00:00
},
},
},
});
return chart;
}
2022-09-23 00:23:41 +00:00
2023-01-27 23:11:10 +00:00
function draw_timeline(data, $chart) {
var ctx = $chart.find('canvas')[0].getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
maintainAspectRatio: false,
legend: {
display: false,
},
scales: {
xAxes: [{
type: 'time',
}]
},
},
});
return chart;
}
2020-01-21 06:35:58 +00:00
</script>