Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (157).NET Core  (28).NET MAUI  (36)Angular  (65)ASP.NET  (48)ASP.NET Core  (73)ASP.NET MVC  (88)Azure  (31)Blazor  (134)DocIO  (22)Essential JS 2  (76)Essential Studio  (169)File Formats  (25)Flutter  (121)JavaScript  (167)Microsoft  (109)PDF  (64)React  (47)Succinctly series  (126)Syncfusion  (550)TypeScript  (30)Uno Platform  (3)UWP  (4)Vue  (34)Webinar  (30)Windows Forms  (57)WinUI  (40)WPF  (131)Xamarin  (148)XlsIO  (25)Other CategoriesBarcode  (5)BI  (29)Bold BI  (4)Build conference  (6)Business intelligence  (53)Button  (4)C#  (115)Chart  (56)Cloud  (11)Company  (445)Dashboard  (7)Data Science  (3)Data Validation  (6)DataGrid  (53)Development  (335)Doc  (7)DockingManager  (1)eBook  (95)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (22)Extensions  (17)File Manager  (4)Gantt  (11)Gauge  (9)Git  (4)Grid  (27)HTML  (9)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (277)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (28)Performance  (8)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (7)Road Map  (10)Scheduler  (34)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (21)Solution Services  (2)Spreadsheet  (11)SQL  (8)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (11)Tips and Tricks  (88)UI  (190)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (1)Visual Studio  (23)Visual Studio Code  (14)Web  (302)What's new  (179)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
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:

Share on twitter
Share on facebook
Share on linkedin
Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top