我正在尝试在chart.js的主要数据下添加其他信息(日期)。我想在主要信息下显示日期。我尝试在while循环中使用数组,但这样做时,它将所有数据添加到数组中的位置[0]上,我不知道该如何解决...
这是我的图表:
<script>
var lbl = [<?php echo $labels; ?>];
var ctx1 = document.getElementById('mychart1');
var ctx2 = document.getElementById('mychart2');
var myLineChart = new Chart(ctx1,{
type: 'line',data: {
labels: lbl,datasets: [
{
label: "Corrente 1",data: [
<?php
echo $datacor1;
?>
],borderWidht: 6,borderColor: 'red',backgroundColor: 'transparent'
},{
label: "Corrente 2",data: [<?php echo $datacor2; ?>],borderColor: 'blue',{
label: "Corrente 3",data: [<?php echo $datacor3; ?>],borderColor: 'green',{
label: "Corrente Total",data: [<?php echo $datatotcor; ?>],borderColor: 'black',]
},options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}],xAxes: [{
gridLines: {
display: false
}
}]
},title: {
display: true,fontSize: 20,text: "Gráfico das Correntes"
},labels: {
fontStyle: "bold",},layout: {
padding: {
left: 0,right: 0,top: 0,bottom: 0
}
},tooltips: {
callbacks:{
//This is the part that I tried
label: function(tooltipItems,data) {
return tooltipItems.yLabel + ' $tempo';
}
}
},aspectRatio: 1,maintainAspectRatio: false
}
});
这是我从数据库中的日期获取信息的部分:
if ($resultCheck > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
$horario = $horario .'"'.(date('H:i:s',strtotime(str_replace('.','-',$row['dias'])))). '",';
$geral = $geral .'"'.(date('d/m/y',';
$tempo = trim($horario,",");
}
}
$labels = trim($geral,");
$tempo = trim($horario,");
目前我正在得到这样的东西:
19/10/30
总数:19
我想得到这个
19/10/30
总数:19
Horario:18:04:23