2017-08-25 158 views
0

如何更改WPF圖表工具包中圖例的位置?WPF圖表工具包圖例位置

我正在使用線條系列,圖例出現在右側,縮小了圖表區域的寬度。

我想查找圖例右上角的圖例。

怎麼辦?

回答

0

您需要修改ControlTemplate了一下:

<chartingToolkit:Chart Title="..."> 
    <chartingToolkit:Chart.Template> 
     <ControlTemplate TargetType="{x:Type chartingToolkit:Chart}" 
           xmlns:visualizationToolkit="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
           xmlns:Primitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit" > 
      <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
        <visualizationToolkit:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}"/> 
        <Grid Grid.Row="1"> 
         <Primitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}"> 
          <Grid Style="{TemplateBinding PlotAreaStyle}" Panel.ZIndex="-1"/> 
          <Border BorderBrush="#FF919191" BorderThickness="1" Panel.ZIndex="10"/> 
         </Primitives:EdgePanel> 
         <visualizationToolkit:Legend x:Name="Legend" 
                  Style="{TemplateBinding LegendStyle}" 
                  Title="{TemplateBinding LegendTitle}" 
                  HorizontalAlignment="Right" 
                  VerticalAlignment="Top" 
                  Margin="0 2 2 0"/> 
        </Grid> 
       </Grid> 
      </Border> 
     </ControlTemplate> 
    </chartingToolkit:Chart.Template> 
</chartingToolkit:Chart>