PHP code example of blumilksoftware / heatmap

1. Go to this page and download the library: Download blumilksoftware/heatmap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blumilksoftware / heatmap example snippets


$data = [
    ["created_at" => "2025-11-01 00:00:00", /** (...) */],
    ["created_at" => "2025-11-03 00:00:00", /** (...) */],
    ["created_at" => "2025-11-16 00:00:00", /** (...) */],
    ["created_at" => "2025-11-16 00:00:00", /** (...) */],
    ["created_at" => "2025-11-18 00:00:00", /** (...) */],
    ["created_at" => "2025-11-19 00:00:00", /** (...) */],
];

$builder = new HeatmapBuilder();
$result = $builder->build($data);

// Define a custom period for the entire month of January 2025
$period = CarbonPeriod::create(
    Carbon::parse('2025-01-01'),
    '1 day',
    Carbon::parse('2025-01-31')
);

// Instantiate the HeatmapBuilder with the custom period
$builder = new HeatmapBuilder(
    now: Carbon::now(),
    periodInterval: PeriodInterval::Daily,
    period: $period // Include the custom period
);

// Generate the heatmap data
$result = $builder->build($data);
json
[
  {
    "label": "2025-11-16",
    "count": 2,
    "description": ""
  },
  {
    "label": "2025-11-17",
    "count": 0,
    "description": ""
  },
  {
    "label": "2025-11-18",
    "count": 1,
    "description": ""
  },
  {
    "label": "2025-11-19",
    "count": 1,
    "description": ""
  },
  {
    "label": "2025-11-20",
    "count": 0,
    "description": ""
  },
  {
    "label": "2025-11-21",
    "count": 0,
    "description": ""
  },
  {
    "label": "2025-11-22",
    "count": 0,
    "description": ""
  },
  {
    "label": "2025-11-23",
    "count": 0,
    "description": ""
  }
]