Chart of the Week: Creating a .NET MAUI Column Chart to Visualize Top Insurance Companies
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 Column Chart to Visualize Top Insurance Companies

Chart of the Week: Creating a .NET MAUI Column Chart to Visualize Top Insurance Companies

Welcome to our Chart of the Week blog series!

 Today, we’ll create a customized column chart to visualize the top insurance companies in the USA using the Syncfusion .NET MAUI Column Chart. This control is supported on desktop (Windows and Mac) and mobile platforms (Android and iOS).

A column chart is a data visualization tool where categories are represented in the form of vertical columns. In this case, the column chart has been customized to represent the top insurance companies in the USA based on their 2022 market capitalization.

Visualizing data of the USA’s top insurance companies using the Syncfusion .NET MAUI Column ChartLet’s get started!

Step 1: Collect data on top insurance companies

First, let’s gather data on the names of the leading insurance companies in the USA and their corresponding market capitalizations for the year 2022 from the CompaniesMarketCap website. Click on each company’s name to retrieve the yearly market capitalization data and collect the values for the year 2022.

Step 2: Prepare data for the chart

Create an InsuranceCompany model class that includes properties for storing information about companies and their market capitalization in the USA.

Refer to the following code example.

public class InsuranceCompany
{
    public string CompaniesName { get; set; }
    public double MarketCapitalization { get; set; }

    public InsuranceCompany(string name, double capitalization)
    {
        CompaniesName = name;
        MarketCapitalization = capitalization;
    }
}

Next, configure the ViewModel class to create a collection of insurance companies along with their market capitalizations and store it in an observable collection using the InsuranceCompaniesList property.

Refer to the following code example.

public class InsuranceCompaniesViewModel
{
    public ObservableCollection<InsuranceCompany> InsuranceCompaniesList { get; set; }

    public InsuranceCompaniesViewModel()
    {
        InsuranceCompaniesList = new ObservableCollection<InsuranceCompany>
        {
             new InsuranceCompany("Elevance Health",123.11),
             new InsuranceCompany("Cigna",101.30),
             new InsuranceCompany("Marsh&MC Lennan",82.07),
             new InsuranceCompany("Progressive",75.88),
             new InsuranceCompany("Humana",64.84),
             new InsuranceCompany("MetLife",56.78),
             new InsuranceCompany("American International",46.98),
             new InsuranceCompany("Arthur J.Gallagher",39.75),           
         };
    }
}

Step 3: Define layout

Define the layout using a Border element. Inside the border, utilize a Grid to place the chart elements.

Refer to the following code example.

<Border StrokeShape="RoundRectangle 20" 
                StrokeThickness="4"
                Stroke="Gray"
                Margin="20">

<Grid RowDefinitions="2*,8*">

<!--Align Header-->
<Grid Grid.Row="0"
         ColumnDefinitions="50,*" RowDefinitions="50,*">
</Grid>

</Grid>
</Border>

Step 4: Configuring the Syncfusion .NET MAUI Charts

Let’s configure the Syncfusion .NET MAUI Cartesian Charts control using this documentation.

Refer to the following code example.

<chart:SfCartesianChart Grid.Row="1">

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

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

Step 5: Bind data to the chart

Use Syncfusion’s ColumnSeries instance to visualize the list of top insurance companies. In this case, we want a customized column chart. Therefore, in the code behind, initialize the column chart and segment accordingly.

Refer to the following code example.

public class ColumnSeriesExt : ColumnSeries
{

} 
public class ColumnSegmentExt : ColumnSegment
{

}

Utilize a customized column instance to bind the data to the chart. Bind the InsuranceCompaniesList collection to the ItemSource property. The XBindingPath and YBindingPath properties should be associated with the CompaniesName and MarketCapitalization properties, respectively. These bindings indicate the data points to be used for the x-axis and y-axis values.

<chart:SfCartesianChart  Grid.Row="1">
 <model:ColumnSeriesExt ItemsSource="{Binding InsuranceCompaniesList}"
                        XBindingPath="CompaniesName" 
                        YBindingPath="MarketCapitalization">
 </model:ColumnSeriesExt>
</chart:SfCartesianChart>

Step 6: Customize the column chart

Refer to the following code example. In it, the ColumnSeriesExt class extends the standard ColumnSeries and overrides the CreateSegment method. This method is crucial as it dictates the creation of a custom ColumnSegmentExt instance, enabling the chart to display specialized segments.

The ColumnSegmentExt class, which inherits from ColumnSegment, holds the drawing logic for the custom column shape. The Draw method within this class utilizes PathF to define shapes: a rectangle with a triangle top.

public class ColumnSeriesExt : ColumnSeries
{
    protected override ChartSegment CreateSegment()
    {
        return new ColumnSegmentExt();
    }
}

public class ColumnSegmentExt : ColumnSegment
{
    protected override void Draw(ICanvas canvas)
    {
          // Create a path rectangle with a triangle top.
          var path = new PathF();
          path.MoveTo(Left, Bottom); 
          path.LineTo(Right, Bottom); 
          path.LineTo(Right, Top + 20); 
          path.LineTo((Left + Right) / 2, Top); 
          path.LineTo(Left, Top + 20); 
          path.Close();

          var color = (Fill is SolidColorBrush brush) ? brush.Color : Colors.Transparent;
          canvas.FillColor = color;
          canvas.FillPath(path);   
 
     }
}

Step 7: Customize the chart appearance

Let’s enhance the visual appeal of the chart and its elements for better readability.

Customizing the title

Refer to the following example to customize the chart title.

<!--Align Header-->
 <Grid Grid.Row="0" ColumnDefinitions="50,*" RowDefinitions="50,*">
     <Image Grid.RowSpan="1" Grid.Column="0" Source="insurancelogo.png"
                 HeightRequest="40"
                 WidthRequest="40"
                 Margin="8"/>
     <VerticalStackLayout Grid.Row="0" Grid.Column="1">
       <Label Text="Creating a Customized Column Chart for USA's Insurance Companies by Market Capitalization"
            TextColor="Black" 
            FontSize="18"
            FontFamily="TimeSpan"
            FontAttributes="Bold"
            Margin="0,5,0,0"/>

       <Label Text="List of USA insurance companies based on 2022 market capitalization data, visualized in a customized column chart."
            TextColor="Black" 
            FontSize="12"
            FontFamily="TimeSpan"
            Margin="5"/>
     </VerticalStackLayout>
 </Grid>

Customizing the axes

Customize the x- and y-axes using the properties MajorGrideLines, Title, Text, and Interval.

Refer to the following code example.

<chart:SfCartesianChart.XAxes>
   <chart:CategoryAxis ShowMajorGridLines="False">
     <chart:CategoryAxis.Title>
        <chart:ChartAxisTitle Text="Insurance Companies"/>
     </chart:CategoryAxis.Title>
   </chart:CategoryAxis>
</chart:SfCartesianChart.XAxes>

<chart:SfCartesianChart.YAxes>
   <chart:NumericalAxis Interval="20" IsVisible="True" />
</chart:SfCartesianChart.YAxes>

Customizing the series appearance

Customize the column series using the Fill property.

<model:ColumnSeriesExt Fill="#2E97A7"> 
</model:ColumnSeriesExt> 

Customizing the series data labels

Add the chart’s data labels and customize the labels as shown in the following code example.

<model:ColumnSeriesExt ItemsSource="{Binding InsuranceCompaniesList}"
                       XBindingPath="CompaniesName" 
                       YBindingPath="MarketCapitalization"
                       ShowDataLabels="True"
                       Fill="#2E97A7">  
  <chart:ColumnSeries.DataLabelSettings>
    <chart:CartesianDataLabelSettings LabelPlacement="Inner" BarAlignment="Middle"                                                                        UseSeriesPalette="False">
      <chart:CartesianDataLabelSettings.LabelStyle>
        <chart:ChartDataLabelStyle LabelFormat="$0.00'B" TextColor="White"/>
      </chart:CartesianDataLabelSettings.LabelStyle>
    </chart:CartesianDataLabelSettings>
  </chart:ColumnSeries.DataLabelSettings>
</model:ColumnSeriesExt>

After executing the previous code examples, our output will look like the following image.

Visualizing data of the USA’s top insurance companies using the Syncfusion .NET MAUI Column Chart
Visualizing data of the USA’s top insurance companies using the Syncfusion .NET MAUI Column Chart

GitHub reference

For more information, refer to the project on Github.

Supercharge your cross-platform apps with Syncfusion's robust .NET MAUI controls.

Conclusion

Thanks for reading! We’ve seen how to compare the top insurance companies in the USA based on 2022 market capitalization using the Syncfusion .NET MAUI Column Chart control. We encourage you to follow these steps and share your thoughts on the experience in the comment section below.

If you require assistance, please don’t hesitate to contact us via our support forumsupport portal, or feedback portal. We are always happy to help 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