Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ajvanho's avatar
Level 14

chart.js labels

Does anyone knowing how to show every 7th date on labels, instead 30 dates?

0 likes
4 replies
Ajvanho's avatar
Level 14

Thank you, but it does not work. I have a blank page, the graphic is completely lost.

MarianoMoreyra's avatar

@ivanradojevic please consider that it's an example extracted from documentation, that probably doesn't have anything to do with your case, as you didn't posted any code.

So, you have to adapt that example to your needs.

If you post your configuration, maybe I could help you

1 like
Ajvanho's avatar
Level 14
$(function () {

    var areaChartCanvas = $('#areaChart').get(0).getContext('2d')

    var areaChartData = {
      labels  : [
      @foreach ($result as $key => $value)
                  "{{ $key }}",				//30 dates
      @endforeach
                ],
      datasets: [
        {
          label               : 'Value',
          backgroundColor     : 'rgba(60,141,188,0.9)',
          borderColor         : 'rgba(60,141,188,0.8)',
          pointRadius          : false,
          pointColor          : '#3b8bba',
          pointStrokeColor    : 'rgba(60,141,188,1)',
          pointHighlightFill  : '#fff',
          pointHighlightStroke: 'rgba(60,141,188,1)',
          data                : [
       @foreach ($result as $key => $value)
                  "{{ $value }}",	//30 values
       @endforeach
          ]
        },       
      ]
    }

    var areaChartOptions = {
      maintainAspectRatio : false,
      responsive : true,
      legend: {
        display: false
      },
      scales: {
        xAxes: [{
         

 gridLines : {
            display : false,
          },
          

     

        }],
        yAxes: [{
          gridLines : {
            display : false,
          }
        }]
      }
    }

    
    var areaChart       = new Chart(areaChartCanvas, { 
      type: 'line',
      data: areaChartData, 
      options: areaChartOptions
    })




 });

Please or to participate in this conversation.