我在后台代码中有一个WPF图表,并且应用了一个图例样式。如何减小图例的大小;即fontsize等。
背景代码:
ScatterSeries series;
chart1.Series.Clear();
for (int i = 0; i < model.CDFResults.Count; i++)
{
series = new ScatterSeries();
series.DependentValuePath = "Value";
series.IndependentValuePath = "Key";
series.ItemsSource = model.CDFResults[i].FinalResult1;
series.Title = model.CDFResults[i].categoryname;
Style dataPointStyle = GetNewDataPointStyle(Col,i);
series.DataPointStyle = dataPointStyle;
series.LegendItemStyle = (Style)Layout.Resources["LegendItemStyle1"];
chart1.Series.Add(series);
}
数据点样式是通过此功能设置的,但我认为它不会影响图例:
private static Style GetNewDataPointStyle(List<Color> Col,int i)
{
Color background = Col[i];
Style style = new Style(typeof(DataPoint));
Setter st1 = new Setter(DataPoint.BackgroundProperty,new SolidColorBrush(background));
Setter st2 = new Setter(DataPoint.HeightProperty,12.0);
Setter st3 = new Setter(DataPoint.WidthProperty, 12.0);
style.Setters.Add(st1);
style.Setters.Add(st2);
style.Setters.Add(st3);
return style;
}
在XAML中,传说样式是这样设置的,但我不知道它是否实际被使用,因为当我尝试更改Fontsize或Fontstyle时,不会应用更改:
<Style x:Key="LegendItemStyle1" TargetType="chartingToolkit:LegendItem">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:LegendItem">
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" Height="2" Margin="0,0,3,0" Width="2"/>
<TextBlock Text="{TemplateBinding Content}" TextWrapping="Wrap" FontStyle="Italic" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
XAML中的图表工具包:
<chartingToolkit:Chart Name="chart1" Background ="White" Title="Cumulative Distributed Function Plot" FontFamily="Tahoma" >
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="Y" ShowGridLines="True" FontSize="10" FontFamily="Tahoma" Title="Cumulative Probability"/>
<chartingToolkit:LinearAxis Orientation="X" ShowGridLines="True" FontSize="10" FontFamily="Tahoma" />
</chartingToolkit:Chart.Axes>
以下是图例的截图: