Chart of the Week: Creating a .NET MAUI Range Column Chart to Compare Average Temperature Variations in Rome
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)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  (508)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  (11)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  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Chart of the Week: Creating a .NET MAUI Range Column Chart to Compare Average Temperature Variations in Rome

Chart of the Week: Creating a .NET MAUI Range Column Chart to Compare Average Temperature Variations in Rome

Welcome to our Chart of the Week blog series!

Today, we’ll analyze and compare average monthly temperature variations in Rome for 2021 and 2022 using the Syncfusion .NET MAUI Range Column Chart.

The .NET MAUI Range Column Chart is a powerful tool for visualizing data ranges. It plots two y-values per data point, representing a column’s upper and lower bounds. This allows for a dynamic and comprehensive view of your data. With features like real-time updates, high performance, and interactive elements such as zooming, panning, trackball, tooltip, and selection, your data analysis becomes an engaging experience.

This versatile control is aesthetically pleasing and compatible with desktop (Windows and Mac Catalyst) and mobile platforms (Android and iOS), making it a go-to choice for cross-platform data visualization needs.

The following image shows the chart we’re going to build..NET MAUI Range Column Chart Comparing Average Temperatures in Rome

Let’s begin creating a range graph that illustrates temperature variations using the Syncfusion .NET MAUI Range Column Chart.

Step 1: Gathering the average temperature data

First, we need to gather data from the Weather Underground website. We’ll focus on obtaining the monthly temperature range in degrees Celsius for Rome (Sallustiano), Italy, for 2021 and 2022. Once we have this data, we will save it as a CSV file. After that, we can create the chart.

Step 2: Preparing the data for the chart

Create the Model class to hold the temperature data with the help of the Month, High2021, Low2021, High2022, and Low2022 properties.

Refer to the following code example.

Public class Model
{
    public Model(string month, double high2021, double low2021, double high2022, double low2022)
    {
        Month = month;
        High2021 = high2021;
        Low2021 = low2021;
        High2022 = high2022;
        Low2022 = low2022;
    }

    public string Month { get; set; }
    public double High2021 { get; set; }
    public double Low2021 { get; set; }
    public double High2022 { get; set; }
    public double Low2022 { get; set; }
}

Then, we generate the average temperature collection using the ViewModel class and its TemperatureCollection property. Assign the CSV data to the temperature range data collection using the ReadCSV method and store it in the TemperatureCollection property.

Refer to the following code example.

public class ViewModel 
{
    List<Model> temperatureCollection;
    public List<Model> TemperatureCollection
    {
        get
        {
            return temperatureCollection;
        }
        set
        {
            temperatureCollection = value;
        }
    }

    public ViewModel()
    {
        TemperatureCollection = new List<Model>(ReadCSV());
    }

    public IEnumerable<Model> ReadCSV()
    {
        Assembly executingAssembly = typeof(App).GetTypeInfo().Assembly;
        Stream inputStream = executingAssembly.GetManifestResourceStream("RangeColumnSample.Resources.Raw.Rome monthly data.csv");

        string? line;
        List<string> lines = new List<string>();

        using StreamReader reader = new StreamReader(inputStream);
        while ((line = reader.ReadLine()) != null)
        {
            lines.Add(line);
        }

        return lines.Select(line =>
        {
            string[] data = line.Split(',');
            return new Model(data[0], Convert.ToDouble(data[1]), Convert.ToDouble(data[2]), Convert.ToDouble(data[4]), Convert.ToDouble(data[5]));
        });
    }
}

Step 3: Configuring the Syncfusion .NET MAUI Cartesian Charts

Now, configure the Syncfusion .NET MAUI Cartesian Charts control using this documentation.

Refer to the following code example.

<chart:SfCartesianChart>  

 <chart:SfCartesianChart.XAxes>
  <chart:CategoryAxis>
  </chart:CategoryAxis>
 </chart:SfCartesianChart.XAxes>

 <chart:SfCartesianChart.YAxes>
  <chart:NumericalAxis>
  </chart:NumericalAxis>
 </chart:SfCartesianChart.YAxes>

</chart:SfCartesianChart>

Step 4: Bind the monthly temperature data to the range column chart

To compare the monthly average temperature variations for 2021 and 2022, we’ll use the Syncfusion RangeColumnSeries instance.

Refer to the following code example.

<chart:RangeColumnSeries  ItemsSource="{Binding TemperatureCollection}" 
                          XBindingPath="Month" High="High2021" Low="Low2021">
</chart:RangeColumnSeries>

<chart:RangeColumnSeries  ItemsSource="{Binding TemperatureCollection}" 
                          XBindingPath="Month" High="High2022"  Low="Low2022">
</chart:RangeColumnSeries>

In the above code example, we’ve bound the ItemSource with the TemperatureCollection property. We have specified the XBindingPath with the Month property for 2021 and 2022. The High and Low properties are bound with the respective high and low values for 2021 and 2022, respectively.

Step 5: Customizing the chart appearance

Let’s enhance the look of the range column chart. To do this, we will create a layout with a bordered container specifically for the range graph. We will use a Label to display the necessary content.

Refer to the following code example.

<Border BackgroundColor="White" Stroke="#BEB1AE" Margin="10,20,10,10" Padding="10">
    
 <Border.StrokeShape>
  <RoundRectangle CornerRadius="30"/>
 </Border.StrokeShape>
    
 <Grid>
  <Grid.RowDefinitions>
   <RowDefinition Height="8*"/>
   <RowDefinition Height="20"/>
  </Grid.RowDefinitions>

  <chart:SfCartesianChart>
  </chart:SfCartesianChart>
        
  <Label Grid.Row="1" FontSize="Caption" FontAttributes="Italic" 
         Text="Monthly temperature range at a weather station in Rome (Sallustiano), Italy, in 2021 and 2022, in °C.">
  </Label>
        
 </Grid>
    
</Border>

Customizing range column series placement

We can place the range column series side by side or overlap them using the EnableSideBySideSeriesPlacement property. Additionally, we can personalize the chart by setting a background color and margins.

Refer to the following code example.

<chart:SfCartesianChart Margin="10" BackgroundColor="White" EnableSideBySideSeriesPlacement="True">
</chart:SfCartesianChart>

Adding a title to the chart

We can easily enhance the readability of the plotted data by adding a Title to the chart, as shown in the following code example.

<chart:SfCartesianChart.Title>
 <Grid>
  <Grid.RowDefinitions>
   <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>
  <HorizontalStackLayout Grid.Column="0">
   <Image Source="cloud.jpg" WidthRequest="40" HeightRequest="40"/>
   <Label VerticalOptions="Center"  
          Text="Average Temperature Variations in Rome: 2021 vs. 2022" FontSize="18"/>
  </HorizontalStackLayout>
 </Grid>
</chart:SfCartesianChart.Title>

Customizing the chart legend

Refer to the following code to enable and customize the Legend to represent the years for which the range column series is plotted.

<chart:SfCartesianChart.Legend>
 <chart:ChartLegend ItemTemplate="{StaticResource LegendTemplate}">
 </chart:ChartLegend>
</chart:SfCartesianChart.Legend>

<chart:SfCartesianChart.Resources>
 <ResourceDictionary>
  <DataTemplate x:Key="LegendTemplate">
   <Grid ColumnDefinitions="Auto,Auto" ColumnSpacing="5">
    <HorizontalStackLayout>
     <Ellipse HorizontalOptions="Center" VerticalOptions="Center" 
              HeightRequest="13" WidthRequest="13" Margin="0,3,3,0"
              Fill="{Binding IconBrush}"/>
     <Label Grid.Column="1" FontSize="16" VerticalTextAlignment="Center" Text="{Binding Item.Label}" TextColor="Black" HorizontalOptions="Center"  HorizontalTextAlignment="Start"/>
    </HorizontalStackLayout>
   </Grid>
  </DataTemplate>
 </ResourceDictionary>
</chart:SfCartesianChart.Resources>

<chart:RangeColumnSeries Label="2021">                     
</chart:RangeColumnSeries>

<chart:RangeColumnSeries Label="2022">
</chart:RangeColumnSeries>

Customizing the axes and gridlines

Let’s customize the x- and y-axes using properties such as LabelPlacement, LabelStyle, and ShowMajorGridLines, and adjust the y-axis range using the Minimum and Maximum properties.

<chart:SfCartesianChart.XAxes>
 <chart:CategoryAxis LabelPlacement="BetweenTicks">
  <chart:CategoryAxis.LabelStyle>
   <chart:ChartAxisLabelStyle TextColor="Black" FontSize="Caption"/>
  </chart:CategoryAxis.LabelStyle>
 </chart:CategoryAxis>
</chart:SfCartesianChart.XAxes>

<chart:SfCartesianChart.YAxes>
 <chart:NumericalAxis  Minimum="-5" Maximum="40" ShowMajorGridLines="False">
  <chart:NumericalAxis.LabelStyle>
   <chart:ChartAxisLabelStyle TextColor="Black" FontSize="Caption"/>
  </chart:NumericalAxis.LabelStyle>
 </chart:NumericalAxis>
</chart:SfCartesianChart.YAxes>

Customizing the chart series

We can also customize the chart series by adjusting the chart segment Width and applying colors using the Fill property. Refer to the following code example.

<chart:RangeColumnSeries Width="{x:OnPlatform Android='0.9', iOS='0.9', Default='0.8'}" Fill="#98fb98>
</chart:RangeColumnSeries>

<chart:RangeColumnSeries Width="{x:OnPlatform Android='0.9', iOS='0.9', Default='0.8'}" Fill="#ff1493">
</chart:RangeColumnSeries>

Adding data labels

Finally, enable and customize the data labels for each series in the chart as shown in the following code example.

<chart:RangeColumnSeries ShowDataLabels="True" >
 <chart:RangeColumnSeries.DataLabelSettings>
  <chart:CartesianDataLabelSettings UseSeriesPalette="False">
   <chart:CartesianDataLabelSettings.LabelStyle>
    <chart:ChartDataLabelStyle TextColor="Black"/>
   </chart:CartesianDataLabelSettings.LabelStyle>
  </chart:CartesianDataLabelSettings>
 </chart:RangeColumnSeries.DataLabelSettings>
</chart:RangeColumnSeries>

<chart:RangeColumnSeries ShowDataLabels="True" >
 <chart:RangeColumnSeries.DataLabelSettings>
  <chart:CartesianDataLabelSettings UseSeriesPalette="False">
   <chart:CartesianDataLabelSettings.LabelStyle>
    <chart:ChartDataLabelStyle TextColor="White" FontAttributes="Bold"/>
   </chart:CartesianDataLabelSettings.LabelStyle>
  </chart:CartesianDataLabelSettings>
 </chart:RangeColumnSeries.DataLabelSettings>
</chart:RangeColumnSeries>

After executing all these code examples, we will get output like the following image.

Comparing the Monthly Average Temperature Variations in Rome Using a .NET MAUI Range Column Chart
Comparing the Monthly Average Temperature Variations in Rome Using a .NET MAUI Range Column Chart

GitHub reference

For more details, refer to the demo on GitHub.

Conclusion

Thanks for reading! In this blog, we’ve compared the average monthly temperature variations in Rome using the Syncfusion .NET MAUI Range Column Chart. We encourage you to follow the steps and share your experience in the comments section below.

You can also contact us through our support forum, support portal, or feedback portal. We are always happy to assist you!

Test Flight
App Center Badge
Google Play Store Badge
Microsoft Badge
Github Store Badge

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