{"id":23060989,"url":"https://github.com/syncfusionexamples/gettingstarted_cartesianchart_maui","last_synced_at":"2025-08-15T08:32:17.983Z","repository":{"id":98095285,"uuid":"578877753","full_name":"SyncfusionExamples/GettingStarted_CartesianChart_MAUI","owner":"SyncfusionExamples","description":"This sample demonstrates how to create a .NET MAUI Cartesian chart with data, a title, data labels, a legend, and tooltip.","archived":false,"fork":false,"pushed_at":"2024-10-30T13:25:50.000Z","size":473,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-30T14:31:14.219Z","etag":null,"topics":["cartesian-chart","cartesian-chart-getting-started","getting-started","maui-chart","maui-chart-getting-started"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SyncfusionExamples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-16T05:04:25.000Z","updated_at":"2024-03-25T07:20:07.000Z","dependencies_parsed_at":"2024-01-19T09:03:27.184Z","dependency_job_id":"c9354fc8-c117-43f8-bbb2-66f7ba067bfa","html_url":"https://github.com/SyncfusionExamples/GettingStarted_CartesianChart_MAUI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2FGettingStarted_CartesianChart_MAUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2FGettingStarted_CartesianChart_MAUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2FGettingStarted_CartesianChart_MAUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2FGettingStarted_CartesianChart_MAUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SyncfusionExamples","download_url":"https://codeload.github.com/SyncfusionExamples/GettingStarted_CartesianChart_MAUI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229901552,"owners_count":18141741,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cartesian-chart","cartesian-chart-getting-started","getting-started","maui-chart","maui-chart-getting-started"],"created_at":"2024-12-16T03:15:52.720Z","updated_at":"2024-12-16T03:15:53.229Z","avatar_url":"https://github.com/SyncfusionExamples.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GettingStarted_CartesianChart_MAUI\n\n## Creating an application with .NET MAUI chart\n\n1. Create a new .NET MAUI application in Visual Studio.\n2. Syncfusion .NET MAUI components are available in [nuget.org](https://www.nuget.org/). To add SfCartesianChart to your project, open the NuGet package manager in Visual Studio, search for Syncfusion.Maui.Charts and then install it.\n3. To initialize the control, import the Chart namespace.\n4. Initialize [SfCartesianChart](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html?tabs=tabid-1).\n\n###### Xaml\n```xaml\n\u003cContentPage\n    . . .    \n    xmlns:chart=\"clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts\"\u003e\n\n    \u003cchart:SfCartesianChart/\u003e\n    \n\u003c/ContentPage\u003e\n ```\n###### C#\n```C#\nusing Syncfusion.Maui.Charts;\nnamespace ChartGettingStarted\n{\n    public partial class MainPage : ContentPage\n    {\n        public MainPage()\n        {\n            InitializeComponent();           \n            SfCartesianChart chart = new SfCartesianChart(); \n            this.Content = chart; \n        }\n    }   \n}\n```\n\n## Register the handler\n\nSyncfusion.Maui.Core nuget is a dependent package for all Syncfusion controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion core.\n###### C#\n```C#\nusing Microsoft.Maui;\nusing Microsoft.Maui.Hosting;\nusing Microsoft.Maui.Controls.Compatibility;\nusing Microsoft.Maui.Controls.Hosting;\nusing Microsoft.Maui.Controls.Xaml;\nusing Syncfusion.Maui.Core.Hosting;\n\nnamespace ChartGettingStarted\n{\n    public static class MauiProgram\n    {\n        public static MauiApp CreateMauiApp()\n        {\n            var builder = MauiApp.CreateBuilder();\n            builder\n            .UseMauiApp\u003cApp\u003e()\n            .ConfigureSyncfusionCore()\n            .ConfigureFonts(fonts =\u003e\n            {\n                fonts.AddFont(\"OpenSans-Regular.ttf\", \"OpenSansRegular\");\n            });\n\n            return builder.Build();\n        }\n    }\n}\n```\n\n## Initialize view model\n\nNow, let us define a simple data model that represents a data point in the chart.\n######\n```C#\npublic class PersonModel   \n{   \n    public string Name { get; set; }\n    public double Height { get; set; }\n}\n```\nNext, create a PersonViewModel class and initialize a list of `PersonModel` objects as follows.\n###### C#\n```C#\npublic class PersonViewModel  \n{\n    public List\u003cPersonModel\u003e Data { get; set; }      \n\n    public PersonViewModel()       \n    {\n        Data = new List\u003cPersonModel\u003e()\n        {\n            new PersonModel { Name = \"David\", Height = 170 },\n            new PersonModel { Name = \"Michael\", Height = 96 },\n            new PersonModel { Name = \"Steve\", Height = 65 },\n            new PersonModel { Name = \"Joel\", Height = 182 },\n            new PersonModel { Name = \"Bob\", Height = 134 }\n        }; \n    }\n }\n```\n\nSet the `PersonViewModel` instance as the `BindingContext` of your page to bind `PersonViewModel` properties to the chart. \n \n* Add namespace of `PersonViewModel` class to your XAML Page, if you prefer to set `BindingContext` in XAML.\n###### Xaml\n```xaml\n\u003cContentPage\n    xmlns=\"http://schemas.microsoft.com/dotnet/2021/maui\"\n    xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\"\n    x:Class=\"ChartGettingStarted.MainPage\"\n    xmlns:chart=\"clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts\"\n    xmlns:model=\"clr-namespace:ChartGettingStarted\"\u003e\n\n    \u003cContentPage.BindingContext\u003e\n        \u003cmodel:PersonViewModel/\u003e\n    \u003c/ContentPage.BindingContext\u003e\n\u003c/ContentPage\u003e\n```\n###### C#\n```C#\nthis.BindingContext = new ViewModel();\n```\n\n## Initialize Chart axis\n\n[ChartAxis](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html) is used to locate the data points inside the chart area. The [XAxes](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html?tabs=tabid-1#Syncfusion_Maui_Charts_SfCartesianChart_XAxes) and [YAxes](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_YAxes) collection of the chart is used to initialize the axis for the chart.\n###### Xaml\n```xaml\n\u003cchart:SfCartesianChart\u003e                            \n     \u003cchart:SfCartesianChart.XAxes\u003e\n                    \u003cchart:CategoryAxis\u003e\n                        \u003cchart:CategoryAxis.Title\u003e\n                            \u003cchart:ChartAxisTitle Text=\"Year\" /\u003e\n                        \u003c/chart:CategoryAxis.Title\u003e\n                    \u003c/chart:CategoryAxis\u003e\n                \u003c/chart:SfCartesianChart.XAxes\u003e\n    \u003cchart:SfCartesianChart.YAxes\u003e\n        \u003cchart:NumericalAxis/\u003e\n    \u003c/chart:SfCartesianChart.YAxes\u003e                       \n\u003c/chart:SfCartesianChart\u003e\n```\n###### C#\n```C#\n    SfCartesianChart chart = new SfCartesianChart();\n    CategoryAxis primaryAxis = new CategoryAxis();\n    chart.XAxes.Add(primaryAxis);\n    NumericalAxis secondaryAxis = new NumericalAxis();\n    chart.YAxes.Add(secondaryAxis);\n ```\n    \nRun the project and check if you get following output to make sure you have configured your project properly to add a chart.\n\n![Initializing axis for .NET MAUI Chart](Getting_start_images/MAUI_chart_initialized.jpg)\n\n## Populate Chart with data\n\nAs we are going to visualize the comparison of heights in the data model, add [ColumnSeries](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ColumnSeries.html?tabs=tabid-1) to [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_Series) property of chart, and then bind the `Data` property of the above `PersonViewModel` to the `ColumnSeries.ItemsSource` as follows.\n\n* The cartesian chart has [Series](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html#Syncfusion_Maui_Charts_SfCartesianChart_Series) as its default content.\n* You need to set [XBindingPath](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_XBindingPath) and [YBindingPath](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.XYDataSeries.html#Syncfusion_Maui_Charts_XYDataSeries_YBindingPath)\n properties so that chart will fetch values from the respective properties in the data model to plot the series. \n\n###### Xaml\n```xaml\n\u003cchart:SfCartesianChart\u003e\n    \u003cchart:SfCartesianChart.XAxes\u003e\n        \u003cchart:CategoryAxis\u003e\n            \u003cchart:CategoryAxis.Title\u003e\n                \u003cchart:ChartAxisTitle Text=\"Name\" /\u003e\n            \u003c/chart:CategoryAxis.Title\u003e\n        \u003c/chart:CategoryAxis\u003e\n    \u003c/chart:SfCartesianChart.XAxes\u003e\n    \u003cchart:SfCartesianChart.YAxes\u003e\n        \u003cchart:NumericalAxis\u003e\n            \u003cchart:NumericalAxis.Title\u003e\n                \u003cchart:ChartAxisTitle Text=\"Height(in cm)\" /\u003e\n            \u003c/chart:NumericalAxis.Title\u003e\n        \u003c/chart:NumericalAxis\u003e\n    \u003c/chart:SfCartesianChart.YAxes\u003e\n\n    \u003cchart:ColumnSeries ItemsSource=\"{Binding Data}\" \n                        XBindingPath=\"Name\" \n                        YBindingPath=\"Height\" /\u003e\n\u003c/chart:SfCartesianChart\u003e\n```\n###### C#\n```C#\nSfCartesianChart chart = new SfCartesianChart();\n\n// Initializing primary axis\nCategoryAxis primaryAxis = new CategoryAxis();\nprimaryAxis.Title.Text = \"Name\";\nchart.XAxes.Add(primaryAxis);\n\n//Initializing secondary Axis\nNumericalAxis secondaryAxis = new NumericalAxis();\nsecondaryAxis.Title.Text = \"Height(in cm)\";\nchart.YAxes.Add(secondaryAxis);\n\n//Initialize the two series for SfChart\nColumnSeries series = new ColumnSeries();\nseries.Label = \"Height\";\nseries.ShowDataLabels = true;\nseries.ItemsSource = (new PersonViewModel()).Data;\nseries.XBindingPath = \"Name\";\nseries.YBindingPath = \"Height\";\n\n//Adding Series to the Chart Series Collection\nchart.Series.Add(series);\n```\n\n## Add a title\n\nThe title of the chart provide quick information to the user about the data being plotted in the chart. The [Title](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartBase.html#Syncfusion_Maui_Charts_ChartBase_Title) property is used to set title for the chart as follows.\n###### Xaml\n```xaml\n\u003cGrid\u003e\n    \u003cchart:SfCartesianChart\u003e\n        \u003cchart:SfCartesianChart.Title\u003e\n            \u003cLabel Text=\"Height Comparison\" /\u003e\n        \u003c/chart:SfCartesianChart.Title\u003e \n    \u003c/chart:SfCartesianChart\u003e\n\u003c/Grid\u003e\n```\n\n###### C#\n```C#\nSfCartesianChart chart = new SfCartesianChart();\nchart.Title = new Label\n{\n    Text = \"Height Comparison\"\n};\n```  \n\n## Enable the data labels\n\nThe [ShowDataLabels](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_ShowDataLabels) property of series can be used to enable the data labels to improve the readability of the chart. The label visibility is set to `False` by default.\n###### Xaml\n```xaml\n\u003cchart:SfCartesianChart\u003e\n    . . . \n    \u003cchart:ColumnSeries ShowDataLabels=\"True\"\u003e\n    \u003c/chart:ColumnSeries\u003e\n\u003c/chart:SfCartesianChart\u003e\n```\n\n###### C#\n```C#\nSfCartesianChart chart = new SfCartesianChart()\n. . .\nColumnSeries series = new ColumnSeries();\nseries.ShowDataLabels = true;\nchart.Series.Add(series);\n```  \n\n## Enable a legend\n\nThe legend provides information about the data point displayed in the chart. The [Legend](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartBase.html#Syncfusion_Maui_Charts_ChartBase_Legend) property of the chart was used to enable it.\n###### Xaml\n```xaml\n\u003cchart:SfCartesianChart \u003e\n    . . .\n    \u003cchart:SfCartesianChart.Legend\u003e\n        \u003cchart:ChartLegend/\u003e\n    \u003c/chart:SfCartesianChart.Legend\u003e\n    . . .\n\u003c/chart:SfCartesianChart\u003e\n```\n\n###### C#\n```C#\n    SfCartesianChart chart = new SfCartesianChart();\n    chart.Legend = new ChartLegend (); \n```\n\n* Additionally, set label for each series using the `Label` property of chart series, which will be displayed in corresponding legend.\n\n###### Xaml\n```xaml\n\u003cchart:SfCartesianChart\u003e\n    . . .\n    \u003cchart:ColumnSeries Label=\"Height\"\n                        ItemsSource=\"{Binding Data}\"\n                        XBindingPath=\"Name\" \n                        YBindingPath=\"Height\"\u003e\n    \u003c/chart:ColumnSeries\u003e\n\u003c/chart:SfCartesianChart\u003e\n```\n\n###### C#\n```C#\nColumnSeries series = new ColumnSeries (); \nseries.ItemsSource = (new PersonViewModel()).Data;\nseries.XBindingPath = \"Name\"; \nseries.YBindingPath = \"Height\"; \nseries.Label = \"Height\";\n```\n\n## Enable tooltip\n\nTooltips are used to show information about the segment, when a user hovers over a segment. Enable tooltip by setting series [EnableTooltip](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_EnableTooltip) property to true.\n\n###### Xaml\n```xaml\n\u003cchart:SfCartesianChart\u003e\n    ...\n    \u003cchart:ColumnSeries EnableTooltip=\"True\"\n\t\t\t\t\t\tItemsSource=\"{Binding Data}\"\n\t\t\t\t\t\tXBindingPath=\"Name\"\n\t\t\t\t\t\tYBindingPath=\"Height\"/\u003e\n    ...\n\u003c/chart:SfCartesianChart\u003e \n```\n\n###### C#\n```C#\nColumnSeries series = new ColumnSeries();\nseries.ItemsSource = (new PersonViewModel()).Data;\nseries.XBindingPath = \"Name\";          \nseries.YBindingPath = \"Height\";\nseries.EnableTooltip = true;\n```\n\nThe following code example gives you the complete code of above configurations.\n\n###### Xaml\n```xaml\n\u003cContentPage\n    xmlns=\"http://schemas.microsoft.com/dotnet/2021/maui\"\n    xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\"\n    x:Class=\"ChartGettingStarted.MainPage\"\n    xmlns:chart=\"clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts\"\n    xmlns:model=\"clr-namespace:ChartGettingStarted\"\u003e\n\n    \u003cContentPage.BindingContext\u003e\n        \u003cmodel:PersonViewModel/\u003e\n    \u003c/ContentPage.BindingContext\u003e\n\n    \u003cContentPage.Content\u003e\n        \u003cGrid\u003e\n            \u003cchart:SfCartesianChart\u003e\n                \u003cchart:SfCartesianChart.Title\u003e\n                    \u003cLabel Text=\"Height Comparison\"/\u003e\n                \u003c/chart:SfCartesianChart.Title\u003e\n\n                \u003cchart:SfCartesianChart.Legend\u003e\n                    \u003cchart:ChartLegend/\u003e\n                \u003c/chart:SfCartesianChart.Legend\u003e\n    \n                \u003cchart:SfCartesianChart.XAxes\u003e\n                    \u003cchart:CategoryAxis\u003e\n                        \u003cchart:CategoryAxis.Title\u003e\n                            \u003cchart:ChartAxisTitle Text=\"Name\"/\u003e\n                        \u003c/chart:CategoryAxis.Title\u003e\n                    \u003c/chart:CategoryAxis\u003e\n                \u003c/chart:SfCartesianChart.XAxes\u003e\n\n                \u003cchart:SfCartesianChart.YAxes\u003e\n                    \u003cchart:NumericalAxis\u003e\n                        \u003cchart:NumericalAxis.Title\u003e\n                            \u003cchart:ChartAxisTitle Text=\"Height(in cm)\"/\u003e\n                        \u003c/chart:NumericalAxis.Title\u003e\n                    \u003c/chart:NumericalAxis\u003e\n                \u003c/chart:SfCartesianChart.YAxes\u003e\n\n            \u003c!--Initialize the series for chart--\u003e\n            \u003cchart:ColumnSeries Label=\"Height\" \n                    EnableTooltip=\"True\"\n                    ShowDataLabels=\"True\"\n                    ItemsSource=\"{Binding Data}\"\n                    XBindingPath=\"Name\" \n                    YBindingPath=\"Height\"\u003e\n                \u003cchart:ColumnSeries.DataLabelSettings\u003e\n                    \u003cchart:CartesianDataLabelSettings LabelPlacement=\"Inner\"/\u003e\n                    \u003c/chart:ColumnSeries.DataLabelSettings\u003e\n            \u003c/chart:ColumnSeries\u003e\n            \u003c/chart:SfCartesianChart\u003e\n        \u003c/Grid\u003e\n    \u003c/ContentPage.Content\u003e\n\u003c/ContentPage\u003e\n```\n\n###### C#\n```C#\nusing Syncfusion.Maui.Charts;\nnamespace ChartGettingStarted\n{\n    public partial class MainPage : ContentPage\n    {\n        public MainPage()\n        {\n            InitializeComponent();            \n            SfCartesianChart chart = new SfCartesianChart();\n\n            chart.Title = new Label\n            {\n                Text = \"Height Comparison\"\n            };\n\n            // Initializing primary axis\n            CategoryAxis primaryAxis = new CategoryAxis();\n            primaryAxis.Title.Text = \"Name\";\n            chart.XAxes.Add(primaryAxis);\n\n            //Initializing secondary Axis\n            NumericalAxis secondaryAxis = new NumericalAxis();\n            secondaryAxis.Title.Text = \"Height(in cm)\";\n            chart.YAxes.Add(secondaryAxis);\n\n            //Initialize the two series for SfChart\n            ColumnSeries series = new ColumnSeries()\n            {\n                Label = \"Height\",\n                ShowDataLabels = true,\n                ItemsSource = (new PersonViewModel()).Data,\n                XBindingPath = \"Name\",\n                YBindingPath = \"Height\",\n                DataLabelSettings = new CartesianDataLabelSettings\n                {\n                    LabelPlacement = DataLabelPlacement.Inner\n                }              \n            };  \n\n            //Adding Series to the Chart Series Collection\n            chart.Series.Add(series);\n            this.Content = chart;\n        }\n    }   \n}\n```\n\nThe following chart is created as a result of the previous codes.\n\n![Getting started for .NET MAUI Chart](Getting_start_images/MAUI_chart.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncfusionexamples%2Fgettingstarted_cartesianchart_maui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyncfusionexamples%2Fgettingstarted_cartesianchart_maui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncfusionexamples%2Fgettingstarted_cartesianchart_maui/lists"}