3

I want to create a chart just like in the picture below. The only problem is that the data is always the same for all bars. How can I fix this??

enter image description here

C# Code :

    List<List<KeyValuePair<string, int>>> list = new List<List<KeyValuePair<string, int>>>();
    list = ncBUS.DonneesChartNCparMois(year);
    DataPointSeries series0 = (DataPointSeries)lineChart.Series[0];
    DataPointSeries series1 = (DataPointSeries)lineChart.Series[1];
    DataPointSeries series2 = (DataPointSeries)lineChart.Series[2];
    series0.ItemsSource = list[0];
    series1.ItemsSource = list[1];
    series2.ItemsSource = list[2];

XAML :

     <chartingToolkit:Chart Name="lineChart"
                                   Title="Graphe Remblais et Pose" 
                                   VerticalAlignment="Top"
                                   Margin="0,59,6,0" 
                                   Height="335">
                    <chartingToolkit:ColumnSeries Name="TNC"
                                            Title="Total NC"  
                                            DependentValuePath="Value" 
                                            IndependentValuePath="Key">
                    </chartingToolkit:ColumnSeries>
                    <chartingToolkit:ColumnSeries Name="NCR" 
                                            Title="NC Remblais"  
                                            DependentValuePath="Value" 
                                            IndependentValuePath="Key">
                    </chartingToolkit:ColumnSeries>
                    <chartingToolkit:ColumnSeries Name="NCP" 
                                            Title="NC Pose"  
                                            DependentValuePath="Value" 
                                            IndependentValuePath="Key">
                    </chartingToolkit:ColumnSeries>
                </chartingToolkit:Chart>

Solution :

Actually this code is working just fine. I just wasn't evacuating the temporary source list which caused it to accumulate data and therefore the display on the chart seemed weird !! so making a new instance of the temporary list solved the problem !!

Nohad Imad
  • 71
  • 7

0 Answers0