回复 3楼tucueltd的帖子
C1Chart的类型是Pie的时候的动态绑定请参考如下代码:
1.legend项目:
- public class Legendvalues
- {
- public string Name { get; set; }
- public double PercentageValue { get; set; }
- }
复制代码
2.创建一个集合,并且给chart.Data.ItemNames赋值:
- List<Legendvalues> chartlegenditems = new List<Legendvalues>();
- chartlegenditems.Add(new Legendvalues() { Name = "Mango", PercentageValue = 20.3 });
- chartlegenditems.Add(new Legendvalues() { Name = "Apple", PercentageValue = 30.1 });
- chartlegenditems.Add(new Legendvalues() { Name = "Strawberry", PercentageValue = 10.4 });
- chartlegenditems.Add(new Legendvalues() { Name = "Orange", PercentageValue = 50.2 });
- chart.Data.ItemNames = chartlegenditems;
复制代码
3.xmal的绑定代码:
- <c1chart:C1ChartLegend.ItemTemplate>
- <DataTemplate>
- <StackPanel Orientation="Horizontal">
- <Canvas Width="24" Height="24" VerticalAlignment="Center">
- <ContentControl Canvas.Top="2" HorizontalContentAlignment="Stretch"
- VerticalContentAlignment="Stretch" Content="{Binding Path=Line}"
- Width="24" Height="20"/>
- <ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Canvas.Left="5" Canvas.Top="5" Content="{Binding Path=Symbol}" Width="14" Height="14"/>
- </Canvas>
- <TextBlock Text="{Binding Path=Item.Name}" Margin="2,0,2,0" Foreground="{Binding Path=Symbol.Fill}" VerticalAlignment="Center"/>
-
- <TextBlock Text="{Binding Item.PercentageValue}" Margin="2,0,2,0" Foreground="{Binding Path=Symbol.Fill}" VerticalAlignment="Center"/>
-
- </StackPanel>
- </DataTemplate>
- </c1chart:C1ChartLegend.ItemTemplate>
- </c1chart:C1ChartLegend>
复制代码 |