- Home
- Forum
- Xamarin.Forms
- Stacked Doughnut
Stacked Doughnut
20 Replies
DD
Devakumar Dhanapoosanam
Syncfusion Team
February 12, 2020 05:41 AM UTC
Hi Emad Afaq,
Greetings from Syncfusion.
You can get the StackedDoughnut sample and the complete chart samples from the links below.
StackedDoughnut: https://github.com/syncfusion/xamarin-demos/tree/master/Forms/Chart/Chart/Samples/MultipleCircle
Please let us know if you need any further assistance.
Regards,
Devakumar D
EA
Emad Afaq
February 12, 2020 06:07 AM UTC
Thanks got it. But i have one issue now. My response from the server is as follows:
{"@odata.context":"https://analytics.dev.azure.com/Org/Project/_odata/v3.0/$metadata#WorkItems(WorkItemType,State,Count)","value":[{"@odata.id":null,"State":"Approved","WorkItemType":"Bug","Count":2},{"@odata.id":null,"State":"Committed","WorkItemType":"Bug","Count":1},{"@odata.id":null,"State":"Done","WorkItemType":"Bug","Count":217},{"@odata.id":null,"State":"New","WorkItemType":"Bug","Count":2},{"@odata.id":null,"State":"Removed","WorkItemType":"Bug","Count":6},{"@odata.id":null,"State":"Done","WorkItemType":"Epic","Count":428},{"@odata.id":null,"State":"In Progress","WorkItemType":"Epic","Count":183},{"@odata.id":null,"State":"New","WorkItemType":"Epic","Count":104},{"@odata.id":null,"State":"Removed","WorkItemType":"Epic","Count":3},{"@odata.id":null,"State":"Done","WorkItemType":"Feature","Count":900},{"@odata.id":null,"State":"In Progress","WorkItemType":"Feature","Count":443},{"@odata.id":null,"State":"New","WorkItemType":"Feature","Count":747},{"@odata.id":null,"State":"Removed","WorkItemType":"Feature","Count":5},{"@odata.id":null,"State":"Closed","WorkItemType":"Impediment","Count":8},{"@odata.id":null,"State":"Open","WorkItemType":"Impediment","Count":21},{"@odata.id":null,"State":"Approved","WorkItemType":"Product Backlog Item","Count":148},{"@odata.id":null,"State":"Committed","WorkItemType":"Product Backlog Item","Count":343},{"@odata.id":null,"State":"Done","WorkItemType":"Product Backlog Item","Count":10811},{"@odata.id":null,"State":"New","WorkItemType":"Product Backlog Item","Count":440},{"@odata.id":null,"State":"Removed","WorkItemType":"Product Backlog Item","Count":108},{"@odata.id":null,"State":"Active","WorkItemType":"Shared Parameter","Count":1},{"@odata.id":null,"State":"Closed","WorkItemType":"Shared Steps","Count":1},{"@odata.id":null,"State":"Done","WorkItemType":"Task","Count":12656},{"@odata.id":null,"State":"In Progress","WorkItemType":"Task","Count":151},{"@odata.id":null,"State":"Removed","WorkItemType":"Task","Count":55},{"@odata.id":null,"State":"To Do","WorkItemType":"Task","Count":222},{"@odata.id":null,"State":"Closed","WorkItemType":"Test Case","Count":3},{"@odata.id":null,"State":"Design","WorkItemType":"Test Case","Count":470},{"@odata.id":null,"State":"Ready","WorkItemType":"Test Case","Count":6},{"@odata.id":null,"State":"Active","WorkItemType":"Test Plan","Count":12},{"@odata.id":null,"State":"Completed","WorkItemType":"Test Suite","Count":1},{"@odata.id":null,"State":"In Progress","WorkItemType":"Test Suite","Count":60}]}
And I need to do alot of manual data structuring. Also instead of Images in the small circles I want to show the work item type (from Json).
Please advise what will be the best approach. As this is the final screen and we want to release it.
DD
Devakumar Dhanapoosanam
Syncfusion Team
February 12, 2020 08:49 AM UTC
Hi Emad Afaq,
We have analyzed your query using data from Json, please refer the below KB for how to set the chart data form Json
Please let us know if your requirement is satisfied with the above solution or not. If not, please explain more details regarding your exact requirement detail in pictorial representation which will be helpful for us to provide the solution at earlier.
Regards,
Devakumar D
EA
Emad Afaq
February 13, 2020 01:59 AM UTC
I went through the KB. Got a bit of an idea. But let me break down what I am doing
I have a RestService Class making the API call that will the JSON which i shared with you earlier. I also have a model for this response that will help me parse it. So now in my viewmodel class I want to call this function and then push it to the view (Stacked Doughnut View).
Is is clear, if not please let me know.
EA
Emad Afaq
February 13, 2020 02:59 AM UTC
EA
Emad Afaq
February 16, 2020 08:19 AM UTC
Hi,
Please let me know. Thanks you
DD
Devakumar Dhanapoosanam
Syncfusion Team
February 16, 2020 07:17 PM UTC
Hi Emad Afaq,
We have analyzed the provided codesnippet, in this you have set the json data using URL and trying to add the parsed data items in RestServiceDashboard class based on the model with items such as WorkItem and Count for the StackedDoughnut.
But we were not clear about how you converting the json data using DashboardModel.FromJson(content) in the provided code below in your attachment.
C#: [RestServiceDashboard.cs]
|
…
var response = await _client.GetAsync("https://analytics.dev.azure.com/slb-it/digital-cells-sso-
dna/_odata/v3.0//WorkItems? &$apply = groupby((WorkItemType, State),
aggregate($count as Count))");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var dashboardValue = DashboardModel.FromJson(content);
foreach (var item in dashboardValue)
{
foreach (var tem in item.Value)
{
DoughnutSeriesData = new ObservableCollection<MultipleCircleModel>
{
new MultipleCircleModel(tem.WorkItemType, tem.Count,"Car.png"),
};//creating new instance always here for DoughnutSeriesData not clear
}
}
return DoughnutSeriesData;
}
… |
Can you please provide more details regarding your requirement using the stacked doughnut in a pictorial representation which will be helpful for us provide the solution at earlier?
1) Whether you want to show the WorkItem type inside the DoughnutSeries Centerview for each legend instead of image as in the sample output at the end.
2) URL link added in the App class details not has enough details.
We would like to share the below code snippet and sample for your reference how to set json data from URL. Please refer the below code for binding the data from URL.
Code snippet[C#]:
|
private readonly HttpClient _client = new HttpClient();
protected override async void OnAppearing()
{
string content = await _client.GetStringAsync(Url);
var json_Datas = JsonConvert.DeserializeObject<ObservableCollection<Model>>(content);
viewModel.Data = json_Datas;
myChart.BindingContext = viewModel;
base.OnAppearing();
} |
Code snippet[XAML]:
|
<chart:SfChart.Series>
<chart:ColumnSeries ItemsSource="{Binding Data}" XBindingPath="CustomerID" YBindingPath="OrderID">
</chart:ColumnSeries>
</chart:SfChart.Series> |
Please refer the below sample using the json data passed as string in specific format and using the json data from a URL.
Output:
Note: The above sample we have prepared using the both Json data from string and also using the URL link.
Regards,
Devakumar D
EA
Emad Afaq
February 18, 2020 02:05 AM UTC
Thank you very much.
The requirement is to show
Epics: Approved(Count), In-Progress(Count), Done(Count) etc
Feature: Approved(Count), In-Progress(Count), Done(Count) etc
Product Backlog Item: Approved(Count), In-Progress(Count), Done(Count) etc

etc.
So in the middle you are right. I dont want to use the pictures Instead we want to have Status and Count
Something like above. I have posted the JSON also. Basically all values are needed as to get that json data we had to query is using OData.
EA
Emad Afaq
February 19, 2020 11:51 AM UTC
Hi, please update. I am not sure this is possible. Thank you
DD
Devakumar Dhanapoosanam
Syncfusion Team
February 20, 2020 02:38 AM UTC
Hi Emad Afaq,
We would like to know that you can get the JSON data into valid chart DataSource properly. Based on that, you can populate the custom view into the DoughtSeries’s CenterView as per in below code snippet using the Leged ItemTemplate.
CodeSnippet [XAML]:
|
…
<chart:ChartLegend.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal" x:Name="root" >
….
<StackLayout HeightRequest="100" WidthRequest="100">
<chart:SfChart VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
<chart:SfChart.Series>
<chart:DoughnutSeries StartAngle="-90"
CapStyle="BothCurve" EndAngle="270" MaximumValue="100"
CircularCoefficient="1" IsStackedDoughnut="true" x:Name="series"
ItemsSource="{Binding Converter={StaticResource
indexToItemSourceConverter}}"
XBindingPath="WorkItemType" YBindingPath="Count"
Color="{Binding IconColor}" EnableAnimation="True">
<chart:DoughnutSeries.CenterView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="workItem" Grid.Row="0" Text="{Binding
BindingContext.DataPoint.WorkItemType}"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" VerticalOptions="Center"/>
<Label x:Name="count" Grid.Row="1" Text="{Binding
BindingContext.DataPoint.Count}"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Grid>
</chart:DoughnutSeries.CenterView>
</chart:DoughnutSeries>
</chart:SfChart.Series>
</chart:SfChart>
</StackLayout>
</StackLayout>
</DataTemplate>
</chart:ChartLegend.ItemTemplate>
… |
Above one is enough to achieve your requirement for adding the CenterView with the work item type and count in the previous updated sample with the local json data in string, moreover we didn’t receive already requested details to check it further.
· Using the json data from the URL. URL link added in the App class details not has enough details.
· Can you please share the details how you converting “all values are needed as to get that json data we had to query is using OData”.
· If possible, please share the provided sample by modifying using the json data from URL as per your requirement.
Please update us with needed information to check it further and to provide a better solution.
Regards,
Devakumar D
EA
Emad Afaq
February 24, 2020 10:33 AM UTC
Hi,
I am not understanding about the App URLthat you are mentioning.
The rest call's link is : https://analytics.dev.azure.com/slb-it/digital-cells-sso-dna/_odata/v3.0//WorkItems? &$apply = groupby((WorkItemType, State), aggregate($count as Count)) in my rest service class.
I went through the sample and the JSON that is hard-coded there isn't the same format as I get from the URL. I get the following response.
{"@odata.context":"https://analytics.dev.azure.com/slb-it/digital-cells-sso-dna/_odata/v3.0/$metadata#WorkItems(WorkItemType,State,Count)","value":[{"@odata.id":null,"State":"Approved","WorkItemType":"Bug","Count":1},{"@odata.id":null,"State":"Committed","WorkItemType":"Bug","Count":1},{"@odata.id":null,"State":"Done","WorkItemType":"Bug","Count":220},{"@odata.id":null,"State":"New","WorkItemType":"Bug","Count":2},{"@odata.id":null,"State":"Removed","WorkItemType":"Bug","Count":7},{"@odata.id":null,"State":"Done","WorkItemType":"Epic","Count":438},{"@odata.id":null,"State":"In Progress","WorkItemType":"Epic","Count":179},{"@odata.id":null,"State":"New","WorkItemType":"Epic","Count":108},{"@odata.id":null,"State":"Removed","WorkItemType":"Epic","Count":3},{"@odata.id":null,"State":"Done","WorkItemType":"Feature","Count":919},{"@odata.id":null,"State":"In Progress","WorkItemType":"Feature","Count":448},{"@odata.id":null,"State":"New","WorkItemType":"Feature","Count":769},{"@odata.id":null,"State":"Removed","WorkItemType":"Feature","Count":5},{"@odata.id":null,"State":"Closed","WorkItemType":"Impediment","Count":10},{"@odata.id":null,"State":"Open","WorkItemType":"Impediment","Count":21},{"@odata.id":null,"State":"Approved","WorkItemType":"Product Backlog Item","Count":150},{"@odata.id":null,"State":"Committed","WorkItemType":"Product Backlog Item","Count":238},{"@odata.id":null,"State":"Done","WorkItemType":"Product Backlog Item","Count":11158},{"@odata.id":null,"State":"New","WorkItemType":"Product Backlog Item","Count":445},{"@odata.id":null,"State":"Removed","WorkItemType":"Product Backlog Item","Count":118},{"@odata.id":null,"State":"Active","WorkItemType":"Shared Parameter","Count":1},{"@odata.id":null,"State":"Closed","WorkItemType":"Shared Steps","Count":1},{"@odata.id":null,"State":"Done","WorkItemType":"Task","Count":13032},{"@odata.id":null,"State":"In Progress","WorkItemType":"Task","Count":124},{"@odata.id":null,"State":"Removed","WorkItemType":"Task","Count":56},{"@odata.id":null,"State":"To Do","WorkItemType":"Task","Count":198},{"@odata.id":null,"State":"Closed","WorkItemType":"Test Case","Count":3},{"@odata.id":null,"State":"Design","WorkItemType":"Test Case","Count":472},{"@odata.id":null,"State":"Ready","WorkItemType":"Test Case","Count":6},{"@odata.id":null,"State":"Active","WorkItemType":"Test Plan","Count":12},{"@odata.id":null,"State":"Completed","WorkItemType":"Test Suite","Count":1},{"@odata.id":null,"State":"In Progress","WorkItemType":"Test Suite","Count":60}]}As provided in my code earlier, i was getting this response.
In the sample they are too many extra classes and i am going through the whole code and checking what there. It will be really appreciated that the sample provided only has the required classes.
My understanding was that the JSON data should be parsed in a specific structure in order for the Chart to accept it. thats why I was converting it.
Please provide a clean sample so its a bit easier to understand and I can try to implement it. Thank you, your support is highly appreciated.
And there is an extra chart added on top of multiple circles. Thats not our requirement. :)
I am trying here to make sure of MVVM aswell. Kindly update me. I am gonna try from myside too.
EA
Emad Afaq
February 25, 2020 04:37 AM UTC
I tried to implement what you suggested and its not working out for me. And BTW the static json that you are using in the sample is not having the same structure comparing to the URL Response which i have pasted earlier.
Attachment: Sample_378f3ae1.zip
I have tried using what you have mentioned but its not pushing data to the view. I have attached the sample please do take a look. And guide me on what should i do next.
Attachment: Sample_378f3ae1.zip
EA
Emad Afaq
February 25, 2020 04:08 PM UTC
Thanks for the support. It is working now. Not exactly the same but your sample helped alot.
DD
Devakumar Dhanapoosanam
Syncfusion Team
February 26, 2020 05:18 AM UTC
Hi Emad Afaq,
We are glad to hear that your requirement has been achieved.
Please let us know if you need any further assistance on this.
Regards,
Devakumar D
KE
Ken
July 29, 2020 04:29 AM UTC
Hi,
Currently I have condition like this. This is the example case.
Let's say we have 3 topics which every topic has "completed hour" and "required hour".
- Mathematics has "10 required hours" ---> 10 is MaximumValue for Mathematics
- Science has "8 required hours" ---> 8 is MaximumValue for Science
- English has "6 required hours" ---> 6 is MaximumValue for English
- Arts has "5 required hours" ---> 5 is MaximumValue for Arts
User John Smith has "5 completed hours" for Mathematics (5/10), "3 completed hours" for Science (3/8), "2 completed hours" for English (2/6), and "4 completed hours for Arts". I want to show these data in 1 Doughnut Chart.
Is there any method to set MaximumValue for each circle if use StackedDoughnut?
SJ
Suyamburaja Jayakumar
Syncfusion Team
July 29, 2020 04:16 PM UTC
We would like to let you know that your requirement has been achieved by doing the required calculation with attend time period by actual time period in model class and populating these to the stacked doughnut series as per in below code snippet
XAML:
|
<StackLayout x:Name="stack">
. . . . .
<chart:SfChart.Series>
<chart:DoughnutSeries StartAngle="-90"
CapStyle="BothCurve"
EndAngle="270"
MaximumValue="100"
CircularCoefficient="0.9"
IsStackedDoughnut="true"
x:Name="doughnutSeries"
ItemsSource="{Binding PriceChartDictonaryModel}"
XBindingPath="Subject"
YBindingPath="Percentage"
LegendIcon="Circle"
Spacing="0.4"
EnableAnimation="True">
<chart:DoughnutSeries.CenterView>
<Image Source="Person.png"
HorizontalOptions="Center"
VerticalOptions="Center">
</Image>
</chart:DoughnutSeries.CenterView>
</chart:DoughnutSeries>
</chart:SfChart.Series>
</chart:SfChart> |
Model:
|
public class Model
{
public string Subject { get; set; }
public double Percentage { get; set; }
public Model(string subject, double Totalcompleted_hour, double Required_hour)
{
Subject = subject;
Percentage = ( Required_hour/ Totalcompleted_hour) *100;
}
} |
ViewModel:
|
public class ViewModel
{
public ObservableCollection<Model> PriceChartDictonaryModel { get; set; }
public ViewModel()
{
PriceChartDictonaryModel = new ObservableCollection<Model>();
PriceChartDictonaryModel.Add(new Model("Mathematics", 10, 5));
PriceChartDictonaryModel.Add(new Model("Science", 8, 3));
PriceChartDictonaryModel.Add(new Model("English", 6, 2));
PriceChartDictonaryModel.Add(new Model("Arts", 4, 4));
}
} |
Screenshot:
Sample Link: https://www.syncfusion.com/downloads/support/forum/151463/ze/StackedDoughnut-645704462.zip
Please let us know if you need any further assistance.
Regards,
Suyamburaja J
KE
Ken
July 30, 2020 04:40 AM UTC
Hi Suyamburaja,
Thank you for your help!
Best Regards,
Kenny
YP
Yuvaraj Palanisamy
Syncfusion Team
July 31, 2020 05:13 AM UTC
Hi Kenny,
Thank you for your update.
Please let us know if you need any further assistance.
Regards,
Yuvaraj
EL
Eduardo Luczinski Junior
October 19, 2020 02:47 PM UTC
Hi all!


When I try to include the chart in a CarouselView many cs0103 the name 'identifier' doesn’t exist in the current context errors occurs for the code behind of the view. Specifically for the legend, chart, doughnutSeries and the colorModel objects. When I comment the CarrousselView there's no error.
Errors when the chart is inside a CarouselView:
Here is the carouselview definition:
Do you know what's going on?
Thank you!
Regards,
Eduardo.
SM
Saravanan Madheswaran
Syncfusion Team
October 20, 2020 02:09 PM UTC
Hi Emad,
Greetings from Syncfusion.
We have checked the provided code snippet and you have added the SfChart as template view of CollectionView, hence only we were unable to get the reference of chart elements. As your requirement is to set platform-specific values, it will be achieved through inline customization code or ViewModel binding.
Please try the below code changes.
Xaml:
|
<chart:SfChart.Legend>
<chart:ChartLegend
DockPosition="{OnPlatform UWP='Right', WPF= 'Right', Default= 'Bottom'}"
Margin="{OnPlatform UWP='200,0,200,0'}"
OverflowMode="{OnPlatform UWP='Scroll', Default='Wrap'}">
</chart:ChartLegend>
</chart:SfChart.Legend>
. . .
<chart:SfChart.Series>
<chart:DoughnutSeries Spacing="{OnPlatform UWP='0.5'}"
. . . />
|
Regards,
Saravanan.
SIGN IN To post a reply.
- 20 Replies
- 7 Participants
-
EA Emad Afaq
- Feb 12, 2020 01:54 AM UTC
- Oct 20, 2020 02:09 PM UTC