PHP and JS help with the data for the graph
Taking data from the database
<?php
$bds = $db->Query("SELECT hashrate,date FROM miner ORDER BY id DESC LIMIT 7");
$result = $bds;
# Этот цикл while - форматирует и помещает все полученные данные в виде ['hashrate', 'date']
while ($row = $result->fetch_assoc()) {
echo "".$row['hashrate'].", ";
echo "".$row['date'].", ";
}
?>
<script>
( function ( $ ) {
"use strict";
//Team chart
var ctx = document.getElementById( "team-chart" );
ctx.height = 150;
var myChart = new Chart( ctx, {
type: 'line',
data: {
labels: [ "27/09/2021", "27/09/2011", "27/09/2012", "27/09/2013", "27/09/2014", "27/09/2015", "27/09/2016" ],
type: 'line',
defaultFontFamily: 'Montserrat',
datasets: [ {
data: [ 1, 2, 3, 4, 5, 6, 7 ],
label: "Expense",
backgroundColor: 'rgba(0,103,255,.15)',
borderColor: 'rgba(0,103,255,0.5)',
borderWidth: 3.5,
pointStyle: 'circle',
pointRadius: 5,
pointBorderColor: 'transparent',
pointBackgroundColor: 'rgba(0,103,255,0.5)',
}, ]
},
options: {
responsive: true,
tooltips: {
mode: 'index',
titleFontSize: 12,
titleFontColor: '#000',
bodyFontColor: '#000',
backgroundColor: '#fff',
titleFontFamily: 'Montserrat',
bodyFontFamily: 'Montserrat',
cornerRadius: 3,
intersect: false,
},
legend: {
display: false,
position: 'top',
labels: {
usePointStyle: true,
fontFamily: 'Montserrat',
},
},
scales: {
xAxes: [ {
display: true,
gridLines: {
display: false,
drawBorder: false
},
scaleLabel: {
display: false,
labelString: 'Month'
}
} ],
yAxes: [ {
display: true,
gridLines: {
display: false,
drawBorder: false
},
scaleLabel: {
display: true,
labelString: 'Value'
}
} ]
},
title: {
display: false,
}
}
} );
} )( jQuery );
</script>
Question how to place labels: [ "27/09/2021", "27/09/2011", "27/09/2012", "27/09/2013", "27/09/2014", "27/09/2015", "27/09/2016" ], put the data $row['date'] . And to the place of data: [ 1, 2, 3, 4, 5, 6, 7 ], put the data $row['hashrate']