- Home
- Forum
- Xamarin.Forms
- Adding a titles to seriesCollection
Adding a titles to seriesCollection
Hello,
Attachment: something_1332417a.zip
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
SIGN IN To post a reply.
7 Replies
BK
Bharathiraja K
Syncfusion Team
June 11, 2019 11:22 AM UTC
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 12, 2019 05:38 AM UTC
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 02:11 PM UTC
Hi Teodor,
We have prepared a sample based on your application scenario. Please download the sample from below location.
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SimpleSample_(3)376987437.zip
[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 02:24 PM UTC
The problem is that i want titles only on the PieCharts is there a way to do that?
BK
Bharathiraja K
Syncfusion Team
June 13, 2019 06:00 AM UTC
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.
Modified Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SimpleSample1185726414.zip
Regards,
Bharathi.
TN
Teodor Nikolaev
June 13, 2019 08:42 AM UTC
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 09:30 AM UTC
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.
SIGN IN To post a reply.
- 7 Replies
- 2 Participants
-
TN Teodor Nikolaev
- Jun 11, 2019 07:45 AM UTC
- Jun 13, 2019 09:30 AM UTC