2021-09-06 11:17:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$chartOptions = $chartOptions ?? [];
|
|
|
|
$seed = mt_rand();
|
|
|
|
$chartId = "chart-{$seed}";
|
|
|
|
|
2021-11-12 15:40:03 +01:00
|
|
|
$chartData = $chartData ?? [];
|
|
|
|
$chartSeries = [];
|
|
|
|
if (!empty($series)) {
|
|
|
|
$chartSeries = $series;
|
|
|
|
} else {
|
|
|
|
// Transform the chart data into the expected format
|
|
|
|
$data = [];
|
|
|
|
foreach ($chartData as $i => $entry) {
|
|
|
|
$data[] = $entry['count'];
|
|
|
|
}
|
|
|
|
$chartSeries = [
|
|
|
|
['data' => $data]
|
|
|
|
];
|
2021-09-06 11:17:25 +02:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<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 ?>',
|
2021-11-12 15:40:03 +01:00
|
|
|
type: 'line',
|
2021-09-07 09:59:36 +02:00
|
|
|
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-11-12 15:40:03 +01:00
|
|
|
series: <?= json_encode($chartSeries) ?>,
|
2021-09-07 09:59:36 +02:00
|
|
|
tooltip: {
|
2021-11-12 15:40:03 +01:00
|
|
|
theme: 'dark'
|
2021-09-06 11:17:25 +02:00
|
|
|
},
|
2021-09-07 09:59:36 +02:00
|
|
|
}
|
2021-11-15 11:49:14 +01:00
|
|
|
const chartOptions = mergeDeep({}, defaultOptions, passedOptions)
|
2021-09-07 09:59:36 +02:00
|
|
|
new ApexCharts(document.querySelector('#<?= $chartId ?>'), chartOptions).render();
|
|
|
|
})
|
2021-09-06 11:35:09 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2021-11-17 17:04:39 +01:00
|
|
|
#<?= $chartId ?> .apexcharts-tooltip-y-group {
|
|
|
|
padding: 1px;
|
2021-09-06 11:35:09 +02:00
|
|
|
}
|
|
|
|
</style>
|