Custom pages problem

Moderator: leecollings

Post Reply
HvdW
Posts: 539
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Custom pages problem

Post by HvdW »

Code: Select all

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Energy Prices Staafdiagram</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        table, th, td {
            border: 1px solid black;
        }
        th, td {
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #4CAF50; /* Groene achtergrondkleur */
            color: white; /* Witte tekstkleur */
        }
    </style>
    <!-- Verwijzing naar de Chart.js bibliotheek via een CDN -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
    <h1>Energy Prices Staafdiagram</h1>
    <canvas id="energyPricesChart" width="400" height="200"></canvas>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const labels = ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"];
            const data = {
                labels: labels,
                datasets: [{
                    label: 'Eneco',
                    data: [0.278666, 0.270063, 0.269518, 0.263504, 0.264993, 0.270111, 0.27483, 0.29131, 0.299248, 0.298098, 0.292073, 0.283312, 0.285369, 0.280759, 0.287704, 0.301148, 0.310719, 0.321899, 0.322081, 0.319249, 0.311287, 0.301269, 0.304475, 0.296586],
                    backgroundColor: 'rgba(75, 192, 192, 0.2)',
                    borderColor: 'rgba(75, 192, 192, 1)',
                    borderWidth: 1
                }]
            };

            const config = {
                type: 'bar',
                data: data,
                options: {
                    scales: {
                        x: {
                            title: {
                                display: true,
                                text: 'Tijd'
                            }
                        },
                        y: {
                            beginAtZero: true,
                            title: {
                                display: true,
                                text: 'Prijs'
                            }
                        }
                    }
                }
            };

            const ctx = document.getElementById('energyPricesChart').getContext('2d');
            new Chart(ctx, config);
        });
    </script>
</body>
</html>
The above script works when placed in /var/www/html/energy_prices.html
However when placed in ~/domoticz/www/templates it shows the header and nothing else.
How come?
How to resolve it.
Is there something domoticz which stops the script?
Bugs bug me.
User avatar
gizmocuz
Posts: 2394
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Custom pages problem

Post by gizmocuz »

Did you try the two provided template examples? And are they working?
If they are (I suspect so), try to find the difference between yours and the supplied examples
Quality outlives Quantity!
User avatar
gizmocuz
Posts: 2394
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Custom pages problem

Post by gizmocuz »

Open your browsers development console and check for any errors will also help you
Quality outlives Quantity!
lost
Posts: 643
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Custom pages problem

Post by lost »

HvdW wrote: Friday 27 December 2024 23:07 The above script works when placed in /var/www/html/energy_prices.html
However when placed in ~/domoticz/www/templates it shows the header and nothing else.
Take care Domoticz cannot use files out of it's own www root. So if you use files out of ~/domoticz/www/templates (to keep your custom things separate from the web server root: ~/domoticz/www) in your script, you may symlink them there and modify your custom page paths using those files to the simlinked ones.

I do this for my cams last captures jpegs that stays for some time in /tmp (so a tmpfs in ram, to avoid SD card wear) and are made available from a Domoticz custom page, for instance. Using directly /tmp/something.jpg in the page was KO. Using ~/domoticz/www/templates/something.jpg after a "ln -s /tmp/something.jpg ~/domoticz/www/templates" command this was OK.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests