{"temperature": "25.0", "humidity": "36.0", "time": "2023-05-08 14:09:01.509578"}
<body>
<h1>DATA</h1>
<p><span class="icon temperature-icon"></span>Temperature: {{ temperature }} C</p>
<p><span class="icon humidity-icon"></span>Humidity: {{ humidity }} %</p>
<p>Last Updated: {{ current_time }}</p>
<canvas id="myChart"></canvas>
</body>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
fetch('../data.json')
.then(response => response.json())
.then(data => {
const labels = data.map(obj => obj.time);
const tempData = data.map(obj => obj.temperature);
const humData = data.map(obj => obj.humidity);
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: 'Temperature',
data: tempData,
fill: false,
borderColor: 'rgb(255, 99, 132)',
tension: 0.1
},
{
label: 'Humidity',
data: humData,
fill: false,
borderColor: 'rgb(54, 162, 235)',
tension: 0.1
}
]
},
options: {
scales: {
x: {
type: 'time',
time: {
parser: 'YYYY-MM-DD HH:mm:ss.SSSSSS',
tooltipFormat: 'll HH:mm:ss.SSS',
unit: 'second',
round: 'second',
displayFormats: {
second: 'HH:mm:ss'
}
},
ticks: {
source: 'auto'
}
}
}
}
});
})
.catch(error => console.error(error));
</script>
(индекс):97 Error: This method is not implemented: Check that a complete date adapter is provided.
at Tn (chart.js:19:103030)
at Ln.formats (chart.js:19:103248)
at No.init (chart.js:19:152863)
at chart.js:19:92454
at u (chart.js:13:1237)
at On.buildOrUpdateScales (chart.js:19:92179)
at On._updateScales (chart.js:19:94913)
at On.update (chart.js:19:94076)
at On.<anonymous> (chart.js:19:90448)
at On._doResize (chart.js:13:5520)
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<script>
fetch('../data.json')
.then(response => response.json())
.then(data => {
const labels = data.map(obj => obj.time);
const tempData = data.map(obj => obj.temperature);
const humData = data.map(obj => obj.humidity);
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: 'Temperature',
data: tempData,
fill: false,
borderColor: 'rgb(255, 99, 132)',
tension: 0.1
},
{
label: 'Humidity',
data: humData,
fill: false,
borderColor: 'rgb(54, 162, 235)',
tension: 0.1
}
]
},
options: {
scales: {
x: {
type: 'time',
time: {
parser: 'yyyy-MM-dd HH:mm:ss.SSSSSS',
tooltipFormat: 'l\l HH:mm:ss.SSS',
unit: 'second',
round: 'second',
displayFormats: {
second: 'HH:mm:ss'
}
},
ticks: {
source: 'auto'
}
}
}
}
});
})
.catch(error => console.error(error));
</script>
</head>
<body>
<h1>DATA</h1>
<p><span class="icon temperature-icon"></span>Temperature: {{ temperature }} C</p>
<p><span class="icon humidity-icon"></span>Humidity: {{ humidity }} %</p>
<p>Last Updated: {{ current_time }}</p>
<canvas id="myChart"></canvas>
</body>
</html>