XMAL方式:
1 <chartingToolkit:Chart x:Name="SamplePercentageChart" Grid.Row="0"
2 DataContext="{Binding ElementName=PieSampleUserControl}" >
3
4 <chartingToolkit:PieSeries DependentValueBinding="{Binding Percentage}"
5 ItemsSource="{Binding PieSlices}"
6 IndependentValueBinding="{Binding }"
7 >
8
9 </chartingToolkit:PieSeries>
10
11 <chartingToolkit:Chart.LegendStyle>
12 <Style TargetType="datavis:Legend">
13 <Setter Property="Width" Value="0"/>
14 <Setter Property="Height" Value="0"/>
15 </Style>
16 </chartingToolkit:Chart.LegendStyle>
17
18 </chartingToolkit:Chart>
C#代码:
1 Chart chart = new Chart { Title = new TextBlock() { Text = di.Key, TextWrapping = TextWrapping.Wrap }, Width = 350, Height = 300, Margin = new Thickness(20, 20, 0, 0) };
2 Style style = new Style(typeof(Legend));
3 style.Setters.Add(new Setter(Legend.WidthProperty, 0));
4 style.Setters.Add(new Setter(Legend.HeightProperty, 0));
5 chart.LegendStyle = style;
定制X轴和Y轴量程和标题等方法
XAML方式:
<DVC:ScatterSeries Title=""
IndependentValueBinding="{Binding Path=Key}"
DependentValueBinding="{Binding Path=Value}"
>
<DVC:ScatterSeries.IndependentAxis >
<DVC:LinearAxis
Title="Prices"
Orientation="X" Maximum="6.5" Minimum="2">
</DVC:LinearAxis>
</DVC:ScatterSeries.IndependentAxis>
C#代码:
CategoryAxis xAxis = new CategoryAxis { Orientation = AxisOrientation.X, Title = "(年)" };
chart.Axes.Add(xAxis);
LinearAxis yAxis = new LinearAxis { Orientation = AxisOrientation.Y, Location = AxisLocation.Left, Title = "(%)", ShowGridLines = true, Minimum = 0, Maximum = 100 };
chart.Axes.Add(yAxis);
LineSeries ls = new LineSeries();
ls.Title = string.Empty;
ls.IndependentValueBinding = new Binding("Name");
ls.DependentValueBinding = new Binding("Value");
ls.ItemsSource = di.Items;
ls.IndependentAxis = xAxis;
ls.DependentRangeAxis = yAxis;