2021-09-06 11:17:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$chartOptions = $chartOptions ?? [];
|
|
|
|
$chartData = $chartData ?? [];
|
|
|
|
$seed = mt_rand();
|
|
|
|
$chartId = "chart-{$seed}";
|
|
|
|
|
|
|
|
// Transform the chart data into the expected format
|
|
|
|
$data = [];
|
|
|
|
foreach ($chartData as $i => $entry) {
|
|
|
|
$data[] = $entry['count'];
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<div id="<?= $chartId ?>"></div>
|
|
|
|
|
|
|
|
<script>
|
2021-09-07 09:59:36 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
const passedOptions = <?= json_encode($chartOptions) ?>;
|
|
|
|
const defaultOptions = {
|
|
|
|
chart: {
|
|
|
|
id: '<?= $chartId ?>',
|
|
|
|
type: 'bar',
|
|
|
|
sparkline: {
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
dropShadow: {
|
|
|
|
enabled: true,
|
|
|
|
top: 1,
|
|
|
|
left: 1,
|
|
|
|
blur: 2,
|
|
|
|
opacity: 0.2,
|
|
|
|
},
|
|
|
|
animations: {
|
|
|
|
enabled: false
|
|
|
|
},
|
2021-09-06 11:17:25 +02:00
|
|
|
},
|
2021-09-07 09:59:36 +02:00
|
|
|
series: [{
|
|
|
|
data: <?= json_encode($data) ?>,
|
|
|
|
}],
|
|
|
|
colors: ['var(--success)'],
|
|
|
|
tooltip: {
|
|
|
|
x: {
|
|
|
|
show: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
title: {
|
|
|
|
formatter: function formatter(val) {
|
|
|
|
return '';
|
|
|
|
}
|
2021-09-06 11:17:25 +02:00
|
|
|
}
|
2021-09-07 09:59:36 +02:00
|
|
|
},
|
|
|
|
theme: '<?= !empty($darkMode) ? 'dark' : 'light' ?>'
|
2021-09-06 11:17:25 +02:00
|
|
|
},
|
2021-09-07 09:59:36 +02:00
|
|
|
}
|
|
|
|
const chartOptions = Object.assign({}, defaultOptions, passedOptions)
|
|
|
|
new ApexCharts(document.querySelector('#<?= $chartId ?>'), chartOptions).render();
|
|
|
|
})
|
2021-09-06 11:35:09 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.apexcharts-tooltip.apexcharts-theme-light {
|
|
|
|
color: black !important
|
|
|
|
}
|
|
|
|
</style>
|