我创建了一个堆栈图表,它有2个seriesDefinition。 它工作正常。
<chartingToolkit:Chart>
<chartingToolkit:StackedColumnSeries>
<chartingToolkit:SeriesDefinition
DataContext="{Binding Path=CostDetail[0]}"
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
<chartingToolkit:SeriesDefinition
DataContext="{Binding Path=CostDetail[1]}"
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
</chartingToolkit:StackedColumnSeries>
现在我希望它可以使用数据绑定动态创建seriesDefinitions。像这样:
//-------------DesignData File Begin (CostData.xaml)----------------//
<CostDemo_Model:CostData.CostDetail>
<CostDemo_Model:StackColumn title="plane">
<CostDemo_Model:StackColumn.fees>
<CostDemo_Model:PrjFee2 Fee="11" PrjName="costKind1"/>
<CostDemo_Model:PrjFee2 Fee="75" PrjName="costKind2"/>
<CostDemo_Model:PrjFee2 Fee="60" PrjName="costKind3"/>
<CostDemo_Model:PrjFee2 Fee="30" PrjName="costKind4"/>
<CostDemo_Model:PrjFee2 Fee="10" PrjName="costKind5"/>
</CostDemo_Model:StackColumn.fees>
</CostDemo_Model:StackColumn>
<CostDemo_Model:StackColumn title="Train">
<CostDemo_Model:StackColumn.fees>
<CostDemo_Model:PrjFee2 Fee="41" PrjName="costKind1"/>
<CostDemo_Model:PrjFee2 Fee="70" PrjName="costKind2"/>
<CostDemo_Model:PrjFee2 Fee="50" PrjName="costKind3"/>
<CostDemo_Model:PrjFee2 Fee="51" PrjName="costKind4"/>
<CostDemo_Model:PrjFee2 Fee="10" PrjName="costKind5"/>
</CostDemo_Model:StackColumn.fees>
</CostDemo_Model:StackColumn>
</CostDemo_Model:CostData.CostDetail>
//-------------DesignData File End (CostData.xaml)----------------//
//-------------View File Start(CostAnalysis.xaml)----------------//
<UserControl d:DataContext="{d:DesignData Source=/Model/Design/CostData.xaml}" >
<UserControl.Resources>
<toolkit:ObjectCollection x:Name="mySeries">
for(i=0; i<CostDetail.Count; i++){
<chartingToolkit:SeriesDefinition
DataContext="{Binding Path=CostDetail[i]}"
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
}
</toolkit:ObjectCollection>
</UserControl.Resources>
<chartingToolkit:Chart>
<chartingToolkit:StackedColumnSeries SeriesDefinitions ={StaticResources mySeries}>
</chartingToolkit:StackedColumnSeries>
</chartingToolkit:Chart>
</UserControl>
//-------------View File End(CostAnalysis.xaml)----------------//
但我不知道怎么做。 谢谢你的帮助!
答案 0 :(得分:1)
这样的事情可能会成为解决方案:
<chartingToolkit:StackedColumnSeries DataContext="{Binding CostDetail}">
<DataTemplate>
<chartingToolkit:SeriesDefinition
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
</DataTemplate>
</chartingToolkit:StackedColumnSeries>
如果您在此期间有另一个解决此问题的方案,我也会对此感兴趣: - )
最诚挚的问候, 安德烈亚斯