Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my windows store app i am unable to display all the items in charts .
its taking only last item and value but i have 6 items in my list
C#
var CIdata = await DMService.GetCIStatusAsync();
foreach (var cchart in CIdata)
{
    string ename = cchart.CIEntityName;
    int pr = Convert.ToInt32(cchart.CIP1Reported);

    List<CIlist> CIlistItems = new List<CIlist>();
    CIlistItems.Add(new CIlist() { Name = ename, Amount = pr });
    (PieChart.Series[0] as PieSeries).ItemsSource = CIlistItems;
    (ColumnChart.Series[0] as ColumnSeries).ItemsSource = CIlistItems;
    (LineChart.Series[0] as LineSeries).ItemsSource = CIlistItems;
    (BarChart.Series[0] as BarSeries).ItemsSource = CIlistItems;
    (BubbleChart.Series[0] as BubbleSeries).ItemsSource = CIlistItems;
}
Posted
Updated 18-Dec-14 3:24am
v2

1 solution

That is because at the end of the code, only the last one change is remaining unchanged. I mean that the last item inside the list makes a change. The first ones, do make a change but that change is soon overwritten by the next element, and this change is also overwritten by the next one and this process continues till the last item in the collection. Since there is no other element to cause a change, that is why this change remains in the UI.

What I would like to tell you, would be to, if you want to show all of the items inside the UI, make them a child for a same parent. Such as, name a simple parent as ChartDataHolder, in XAML it will be,

HTML
<stackpanel name="ChartDataHolder">
   <!-- It can now hold, as many child elements as you want -->
</stackpanel>


.. now in the code behind, create a new List and then add these items from the Collection to it. For example, like

C#
var CIdata = await DMService.GetCIStatusAsync();
foreach (var cchart in CIdata)
{
    string ename = cchart.CIEntityName;
    int pr = Convert.ToInt32(cchart.CIP1Reported);
 
    List<cilist> CIlistItems = new List<cilist>();
    CIlistItems.Add(new CIlist() { Name = ename, Amount = pr });
    // create new instance of *Series each time in this method
    // Add all of the, BubbleSeries, BarSeries etc to a StackPanel like, 
    StackPanel panel = new StackPanel();
    // use panel.Children.Add method(), once added, 
    ChartDataHolder.Children.Add(panel);
}
</cilist></cilist>


.. now, all of the charts will be added independently to the same parent StackPanel and they will be available, because you will be creating a new instance, and won't override any previous data and will be added to the Panel seperately, which way you will get all of the items inside the UI.
 
Share this answer
 
Comments
jayanthik 19-Dec-14 1:42am    
hi afzaal little bit confusion I will try as per ur suggetion
jayanthik 19-Dec-14 2:05am    
not getting will u pls give me more clear, what should I add in panel.children.add(?)
I tried with all giving error
Afzaal Ahmad Zeeshan 19-Dec-14 2:22am    
What is the error?

You will add the Series inside the Panel's childrens, for them to visible in the StackPanel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900