React HeatGrid is a versatile and customizable heatmap component for React applications.
![HeatGrid Demo](https://private-user-images.githubusercontent.com/104687128/266774261-81268e28-2c18-431b-8945-ce22295d4077.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NTcyOTQsIm5iZiI6MTczODk1Njk5NCwicGF0aCI6Ii8xMDQ2ODcxMjgvMjY2Nzc0MjYxLTgxMjY4ZTI4LTJjMTgtNDMxYi04OTQ1LWNlMjIyOTVkNDA3Ny5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxOTM2MzRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNzUwZGYyMmVjNzgzNDgzMjg5YzY3ODc5ODEwMjBlNjdkZTczMWY2Y2RhOTU3YjQ0YmI3NjZkMDkyZWU5ZTNhJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.GKaCd9SjHYhlJ6sFgoNM8aiwZt8lsz-lToDNmt2S74I)
ToolTip when hover on each grid.
![HeatGrid Demo](https://private-user-images.githubusercontent.com/104687128/266774448-60e4a279-e7b1-4274-9679-fa1b6fe70c3c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NTcyOTQsIm5iZiI6MTczODk1Njk5NCwicGF0aCI6Ii8xMDQ2ODcxMjgvMjY2Nzc0NDQ4LTYwZTRhMjc5LWU3YjEtNDI3NC05Njc5LWZhMWI2ZmU3MGMzYy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxOTM2MzRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iYzFhM2UzNTViNGI5MTM4ZDdlODU4MWY1N2VhYTE0ZTY4MTliNjAwZWJmOTA3NjM5ODFmZGZlNmZjMWRlNjAwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.yJBJL2jUFuZXL3ynm2hCRstU2smChGxKw7iKQE6NS_0)
You can install React HeatGrid via npm or yarn:
npm i react-heatgrid --save
To use the Calendar
component from the react-heatgrid
package, you need to import it and pass the required props. Below is an example of how to use the Calendar
component along with an explanation of its props:
import React from 'react';
import { Calendar } from 'react-heatgrid';
const MyCalendar = () => {
const calendarData = [
{ value: 9, day: '2023-08-23' },
{ value: 20, day: '2023-08-10' },
{ value: 49, day: '2023-07-17' },
{ value: 45, day: '2023-08-21' },
{ value: 7, day: '2023-07-23' },
{ value: 11, day: '2023-08-15' },
{ value: 28, day: '2023-08-26' },
{ value: 11, day: '2023-09-07' },
{ value: 27, day: '2023-09-08' },
// you can add random day, skip a day and day can be date format like...
{ value: 27, day: new Date('2023-09-09') },
];
const heatmapColors = ["#161b22","#0e4429","#006d32","#26a641","#39d353"];
return (
<div>
<h1>My Calendar Heatmap</h1>
<Calendar
months={3} {/* Number of months to display */}
data={calendarData} {/* Array of data objects */}
colors={heatmapColors} {/* Array of heatmap colors */}
tooltipLabel="activity" {/* Tooltip label */}
/>
</div>
);
};
export default MyCalendar;
Prop | Description | Default Value |
---|---|---|
months |
The number of months to display in the calendar. | 3 |
gridSize |
The size of each grid cell in the calendar. | "20px" |
gap |
The gap between grid cells in the calendar. | "2px" |
data |
An array of data objects representing each day in the calendar. Each object should have a 'value' (number) and 'day' (string) property. | Required |
colors |
An array of colors from low intensity to high. e.g ["#161b22","#0e4429","#006d32","#26a641","#39d353"] | Required |
fontSize |
Size of text throughout the calendar. | "12px" |
fontColor |
Color of the text | "black" |
DisabledToolTip |
Disable tooltips for grid cells. | false |
DisabledLegend |
Disable the legend of chart | false |
placement |
The placement of tooltips relative to the grid cell ("top" or "bottom"). | "top" |
tooltipBg |
The background color of tooltips. | "#303030" |
tooltipTextColor |
The text color of tooltips. | "white" |
tooltipLabel |
The label for the tooltip, which can be one of "activity", "contributions", or a custom string. | "activity" |
tooltipStyle |
Additional CSS styles to apply to the tooltip. e.g {border:"1px solid red"} | None |
dateFormat |
Either "yyyy-mm-dd" (e.g 2023-01-31) or "WeekDay, Month Date, Year" (e.g Tue, Jan 31, 2023) | "yyyy-mm-dd" |