我想创建一张图表,如下图所示。唯一的问题是所有条形的数据总是相同的。我该如何解决这个问题?
C#代码:
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>
解决方案:
实际上这段代码工作正常。 我只是没有撤离导致它累积数据的临时源列表,因此图表上的显示看起来很奇怪!所以制作临时列表的新实例解决了问题!!