Designing a Heat Map Calendar Using WinUI Scheduler | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (118)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (914)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Designing a Heat Map Calendar Using WinUI Scheduler

Designing a Heat Map Calendar Using WinUI Scheduler

A heat map is a data visualization tool that uses different colors to display the variation in data.

Nowadays, internet data plays a significant role in our life. We use the internet to browse, download apps, check email, play games, pay bills, and more. This blog will show how to design a heat map calendar based on our daily internet data usage with the Syncfusion WinUI Scheduler control.

WinUI Scheduler

The Syncfusion WinUI Scheduler control is the only tool you need to design a heat map calendar. First, we have to customize the WinUI Scheduler’s month cell using the MonthCellTemplate or MonthCellTemplateSelector properties of the MonthViewSettings class. The DataContext of the MonthCellTemplate or MonthCellTemplateSelector properties is MonthCell.

Note: If you are new to the Scheduler, please read the WinUI Scheduler getting started documentation before proceeding.

Generating internet data usage details

First, generate the internet data usage details. You can use MonthCell data context class properties such as DateText and Appointments to bind the mobile data usage details in the MonthCellTemplate.

To generate the details of Appointments in the MonthCell, you need to create a custom event object to maintain the internet data, such as usage, date, and color. Map these custom event data properties to the Scheduler using the AppointmentMapping property to bind the mobile data usage details in the MonthCellTemplate.

Create an internet data model

Next, create a custom event with the required internet details. Refer to the following code example.

/// <summary>    
/// Represents the Internet data properties.    
/// </summary> 
public class InternetData : NotificationObject
{
    private DateTime date;
    private Brush color;
    private int usage;

    public int Usage
    {
        get { return usage; }
        set
        {
            usage = value;
            RaisePropertyChanged("Usage");
        }
    }

    public DateTime Date
    {
        get { return date; }
        set
        {
            date = value;
            RaisePropertyChanged("Date");
        }
    }

    public Brush Color
    {
        get { return color; }
        set
        {
            color = value;
            RaisePropertyChanged("Color");
        }
    }
}

Create internet data collection

Then, create the collection of internet data objects and assign them to the ItemsSource property to generate the details of Appointments in the MonthCell. The MonthCell property is used to get the internet data usage in the MonthCellTemplate.

We are going to create a custom internet data collection of type ObservableCollection<InternetData> with the required internet data usage details.

public class HeatMapViewModel
{
  public HeatMapViewModel()
  {
     this.GenerateData();
  }

  public ObservableCollection<InternetData> InternetDataUsages { get; set; }

  /// <summary>
  /// Generate random data for heat map calendar based on internet data usage.
  /// </summary>
  private void GenerateData()
  {
     //// Creating an instance for internet data collection.
     InternetDataUsages = new ObservableCollection<InternetData>();
     var startDate = DateTime.Now.Date.AddMonths(-2);
     var random = new Random();

     //// Adding random data to the internet data collection.
     for (int i = 0; i < 200; i++)
     {
	InternetData internetData = new InternetData();
	internetData.Date = startDate.AddDays(i);
	//// Data usage in terms of GB.
	internetData.Usage = random.Next(0, 15);
	internetData.Color = GetColor(internetData.Usage);
	this.InternetDataUsages.Add(internetData);
     }
  }

  /// <summary>
  /// Methods to get the color based on data usage.
  /// </summary>
  /// <param name="data"></param>
  private Brush GetColor(int data)
  {
     //// Data usage in terms of GB.
     if (data < 3)
     {
	return new SolidColorBrush(Color.FromArgb(255, 238, 238, 238));
     }
     else if (data < 6)
     {
	return new SolidColorBrush(Color.FromArgb(255, 198, 228, 139));
     }
     else if (data < 9)
     {
	return new SolidColorBrush(Color.FromArgb(255, 123, 201, 111));
     }
     else if (data < 12)
     {
	return new SolidColorBrush(Color.FromArgb(255, 35, 154, 59));
     }
     else
     {
	return new SolidColorBrush(Color.FromArgb(255, 25, 97, 39));
     }
  }
}

Mapping the internet data object properties

Map the custom internet data object properties to the WinUI Scheduler control by configuring the AppointmentMapping property.

Refer to the following code example.

<Window
  ...
  xmlns:Scheduler="using:Syncfusion.UI.Xaml.Scheduler" >
  <Grid>
     <Grid.DataContext>
         <local:HeatMapViewModel />
     </Grid.DataContext>


     <Scheduler:SfScheduler x:Name="scheduler" 
                              ItemsSource="{Binding InternetDataUsages }"
                              AppointmentEditFlag="None">
         <!--The collection of internet data object can be assigned to the scheduler ItemsSource property in order to generate the details of appointments in the MonthCell which is used to get the details of the internet data usage for the day-->

         <Scheduler:SfScheduler.AppointmentMapping>
            <Scheduler:AppointmentMapping StartTime="Date"
                                          AppointmentBackground="Color"/>
         </Scheduler:SfScheduler.AppointmentMapping>
     </Scheduler:SfScheduler>
  </Grid>

Designing a heat map calendar using WinUI Scheduler

Now, customize the month cell of the WinUI Scheduler control using the MonthCellTemplate property of the MonthViewSettings. Set the AppointmentEditFlag property to None in the Scheduler control to restrict the opening of the editor. Then, set the AppointmentDisplayMode property to None to avoid displaying appointments on the month cells.

Refer to the following code to design a heat map calendar using the MonthCellTemplate.

<Window
  ...
  xmlns:Scheduler="using:Syncfusion.UI.Xaml.Scheduler">

    <Grid>
        <Grid.DataContext>
            <local:HeatMapViewModel />
        </Grid.DataContext>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>
        <Scheduler:SfScheduler x:Name="scheduler" 
                               ItemsSource="{Binding InternetDataUsages}"
                               AppointmentEditFlag="None">
            <!--The collection of internet data object can be assigned to the scheduler ItemsSource property in order to generate the details of appointments in the MonthCell which is used to get the details of the internet data usage for the day-->

            <Scheduler:SfScheduler.AppointmentMapping>
                <Scheduler:AppointmentMapping StartTime="Date"
                                              AppointmentBackground="Color"/>
            </Scheduler:SfScheduler.AppointmentMapping>
            <Scheduler:SfScheduler.MonthViewSettings>
                <Scheduler:MonthViewSettings AppointmentDisplayMode="None">
                    <!--Declare the DataTemplate for the scheduler month cell in order to create the heatmap calendar-->
                    <Scheduler:MonthViewSettings.MonthCellTemplate>
                        <DataTemplate>
                            <Grid Background="{Binding Appointments[0].Data.Color}">
                                <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" Text="{Binding DateText}" />
                            </Grid>
                        </DataTemplate>
                    </Scheduler:MonthViewSettings.MonthCellTemplate>
                </Scheduler:MonthViewSettings>
            </Scheduler:SfScheduler.MonthViewSettings>
        </Scheduler:SfScheduler>     

         <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.1*"/>
                <ColumnDefinition Width="0.8*"/>
                <ColumnDefinition Width="0.1*"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="1" HorizontalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.4*"/>
                    <RowDefinition Height="0.6*"/>
                </Grid.RowDefinitions>

                <TextBlock Text="Less" HorizontalTextAlignment="Start" VerticalAlignment="Bottom" Grid.Row="0">
                <TextBlock Text="More" HorizontalTextAlignment="End" VerticalAlignment="Bottom" Grid.Row="0"/>
                <Border Grid.Row="1" Margin="0,2,0,5" Height="20" MinWidth="500" VerticalAlignment="Top">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="1,1">
                            <LinearGradientBrush.GradientStops>
                                <GradientStopCollection>
                                    <GradientStop Color="#eeeeee" Offset="0.0" />
                                    <GradientStop Color="#c6e48b" Offset="0.3" />
                                    <GradientStop Color="#7bc96f" Offset="0.6" />
                                    <GradientStop Color="#239a3b" Offset="0.8" />
                                    <GradientStop Color="#196127" Offset="1.0" />
                                </GradientStopCollection>
                            </LinearGradientBrush.GradientStops>
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
            </Grid>
        </Grid>
    </Grid>
</Window>
Designing a Heat Map Calendar using the WinUI Scheduler Control
Designing a Heat Map Calendar using the WinUI Scheduler Control

GitHub reference

Refer to the Designing a heat map calendar using the WinUI Scheduler GitHub demo to learn more.

Conclusion

Thanks for reading! This post gave a quick overview of designing a heat map calendar based on internet data usage using the Syncfusion WinUI Scheduler control. With one of these, you can easily understand the trends in data with different color patterns. Try out the steps in this blog post and share your feedback in the comments section!

For existing customers, the new version of Essential Studio is available for download from the License and Downloads page. If you are not yet a Syncfusion customer, you can try our 30-day free trial to check out our available features.

For questions, you can contact us through our support forumsupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed