We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Adding a titles to seriesCollection

Hello,

I have the following code that is initializing a chart and i would like to know if it's possible to add a title for this specific chart in this part of the code (i have uploaded the pictures). If there is any other way to do it i must specify that i want titles only in specific charts.

Attachment: something_1332417a.zip

7 Replies

BK Bharathiraja K Syncfusion Team June 11, 2019 03:22 AM

Hi Teodor, 
 
Greetings from Syncfusion. We already have options to add Title with Chart. Please find the below help document for more details. 
 
 
If your requirement is different from the above scenario, please share more details with screenshot of the expected output in Chart. This will be helpful for us to investigate further and provide you a better solution at the earliest. 
 
Regards, 
Bharathi. 



TN Teodor Nikolaev June 11, 2019 09:38 PM

The problems is i can't figure out how to add a title during the creation of the chart, is it possible to add a title in the code that i have sent earlier?

The chart its self is a collection of different chats in a list view and for some of them i just need to add titles.


BK Bharathiraja K Syncfusion Team June 12, 2019 06:11 AM

Hi Teodor,   
 
We have prepared a sample based on your application scenario. Please download the sample from below location. 
 
 
[XXAML]: 
<chart:SfChart.Title> 
                                <chart:ChartTitle Text="{Binding Title}" BackgroundColor="{Binding ChartColor}" FontSize="12"/> 
                            </chart:SfChart.Title> 
 
In Model 
public string Title { get; set; } 
        public ChartModel(ChartSeriesCollection seriesCollection, Color chartColor, string title) 
        { 
            SeriesCollection = seriesCollection; 
            ChartColor = chartColor; 
            Title = title; 
        } 
 
In Collection 
ChartData = new ObservableCollection<ChartModel>() 
            { 
                new ChartModel( 
                    new ChartSeriesCollection() 
                    { 
                        new LineSeries() 
                        { 
                            //or else bind your data model. 
                            ItemsSource = new ObservableCollection<Model>(){new Model("Information Technology", 32), new Model("India",53),new Model("Saudi",26), new Model("USA",82), new Model("Japan",43), 
                            }, 
                            XBindingPath = "Countries", 
                            YBindingPath = "Count", 
                            XAxis = new CategoryAxis(), 
                            YAxis = new NumericalAxis(), 
                        }, 
                    }, Color.LightCoral, "Line Series" 
 
                ), 
 
 
 
If the above requirement is different from your application scenario, then please modify the given sample with replication steps. This will be helpful for us to investigate further and provide you a better solution at the earliest. 
 
Regards, 
Bharathi. 



TN Teodor Nikolaev June 12, 2019 06:24 AM

The problem is that i want titles only on the PieCharts is there a way to do that?



BK Bharathiraja K Syncfusion Team June 12, 2019 10:00 PM

Hi Teodor, 
 
By the same way you can bind the ChartTitle property instead of sting value. Please refer the below code snippet and change your Model and ViewModel accordingly 
 
[At Model] 
public ChartTitle Title { get; set; } 
 
[At ViewModel] – Initiate title only for pie series.  
ChartData = new ObservableCollection<ChartModel>() 
            { 
                new ChartModel( 
                    new ChartSeriesCollection() 
                    { 
                        new LineSeries() 
                        { 
                            //or else bind your data model. 
                            ItemsSource = new ObservableCollection<Model>(){new Model("Information Technology", 32), new Model("India",53),new Model("Saudi",26), new Model("USA",82), new Model("Japan",43), 
                            }, 
                            XBindingPath = "Countries", 
                            YBindingPath = "Count", 
                            XAxis = new CategoryAxis(), 
                            YAxis = new NumericalAxis(), 
                        }, 
                    }, Color.LightCoral, null //Set null for other than pie series. 
 
                ), 
 
                new ChartModel( 
                    new ChartSeriesCollection() 
                    { 
                        new PieSeries() 
                        { 
                            //or else bind your data model. 
                            ItemsSource = new ObservableCollection<Model>(){new Model("Information Technology", 32), new Model("India",43),new Model("Saudi",23), new Model("USA",54), new Model("Japan",63)}, 
                            XBindingPath = "Countries", 
                            YBindingPath = "Count", 
                        }, 
                    }, Color.LightGray, new ChartTitle(){Text="Pie Series", FontSize= 12, BackgroundColor = Color.LightGray} 
                ), 
} 
 
Please find the modified sample from below link. 
 
 
 
 
Regards, 
Bharathi. 



TN Teodor Nikolaev June 13, 2019 12:42 AM

Thank you that solution fits perfectly! I have another question would annotations work the same exact way in terms of binding? 


BK Bharathiraja K Syncfusion Team June 13, 2019 01:30 AM

Hi Teodor,  
 
Yes. All chart properties support binding. Please refer the annotation help document below here. You can bind your ViewModel value to annotation properties.  
 
 
Regards, 
Bharathi. 


Loader.
Live Chat Icon For mobile
Up arrow icon