使用回调

我有一个存储数据发送时间的数组。我试图在图表中的点上打印数组的每个元素,因为图表中点的顺序与发送时间完全相同。但是,当我尝试使用循环或类似的方式时,它也在所有其他点都进行了循环,因此我需要时间只出现在该特定点上。这些图像可以帮助我解释我的问题:

使用回调

使用回调

如您所见,它以这种方式显示,但我只需要在每个块中显示红色的信息即可。

这是我存储日期的一部分:

if ($resultCheck > 0)
      {
        while ($row = mysqli_fetch_assoc($result))
        {
          $horario = (date('H:i:s',strtotime(str_replace('.','-',$row['dias']))));    

          $tempo[] = explode(',',$horario);

          $geral = $geral .'"'.(date('d/m/y',$row['dias'])))). '",';
        }
      }

      $labels = trim($geral,",");

这是我的图表:

<script>
    var lbl = [<?php echo $labels; ?>];
    var ctx1 = document.getElementById('mychart1');

    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',]            
        },plugins: [

        ],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: {
            enabled: true,backgroundColor: 'black',titleFontFamily: "'Arial'",titleFontSize: 14,titleFontStyle: 'bold',titleAlign: 'center',titleSpacing: 4,titleMarginBottom: 10,bodyFontFamily: "'Mukta'",bodyFontSize: 14,borderWidth: 2,borderColor: 'grey',callbacks:{
                title: function(tooltipItem,data) {
                    return data.labels[tooltipItem[0].index];
                },afterTitle: function(tooltipItem,data) {
                  return '<?php print_r($tempo[$mudarHorario][0]);?>';                   

                },label: function(tooltipItem,data) {
                      var label = data.datasets[tooltipItem.datasetIndex].label || '';                  
                      if (label) {
                          label += ': ';
                      }
                      label += (tooltipItem.yLabel)+"A";                  
                      return label;
                }              
            }
          },aspectRatio: 1,maintainAspectRatio: false
        }
    });
    </script>

您可以在回调中看到我用来显示数组的代码。

只是尝试使用新代码来循环抛出工具提示,但并未起作用:

callbacks:{
                title: function(tooltipItem,data) {
                      var label = data.datasets[tooltipItem.datasetIndex].label || '';                  
                      if (label) {
                          label += ': ';
                      }
                      label += (tooltipItem.yLabel)+"A";                  
                      return label;
                }
ahuo1987 回答:使用回调

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3163553.html

大家都在问