2011-01-04 15 views
11

私はchartingToolKit:Chartコントロールを使用しています。グラフとプロット領域の間に表示される空白を削除したいと思います。削除する領域のWPFサンプルとイメージを添付しました。WPF Toolkitのチャート領域とプロット領域の間のスペースを削除するにはどうすればよいですか?

<Window x:Class="WpfApplication2.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525" xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"> 


<Grid> 
    <chartingToolkit:Chart x:Name="chart" Width="500" Height="300" Margin="0, 0, 0, 0" LegendStyle="{StaticResource LegendStyle}" > 


     <chartingToolkit:AreaSeries ItemsSource="{Binding}" 

            DependentValuePath="Value" 

            IndependentValuePath="Key" 

            Background="Red" 

            > 


     </chartingToolkit:AreaSeries> 

     <chartingToolkit:Chart.Axes> 
      <chartingToolkit:LinearAxis Orientation="X" ShowGridLines="False" Visibility="Hidden"> 

      </chartingToolkit:LinearAxis> 
      <chartingToolkit:LinearAxis Orientation="Y" ShowGridLines="False" Visibility="Hidden"/> 
     </chartingToolkit:Chart.Axes> 

    </chartingToolkit:Chart> 
</Grid> 

赤い矢印でマークされた領域を使用すると、再テンプレートのチャートに必要なこれを達成するために alt text

答えて

20

を削除する必要があります。次のように標準チャートテンプレートは次のとおりです。

  <ControlTemplate TargetType="charting:Chart"> 
       <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="*" /> 
         </Grid.RowDefinitions> 

         <datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" /> 

         <!-- Use a nested Grid to avoid possible clipping behavior resulting from ColumnSpan+Width=Auto --> 
         <Grid Grid.Row="1" Margin="0,15,0,15"> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*" /> 
           <ColumnDefinition Width="Auto" /> 
          </Grid.ColumnDefinitions> 

          <datavis:Legend x:Name="Legend" Title="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}" Grid.Column="1" /> 
          <chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}"> 
           <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" /> 
           <Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" /> 
          </chartingprimitives:EdgePanel> 
         </Grid> 
        </Grid> 
       </Border> 
      </ControlTemplate> 

これは、プロットエリア、タイトル、説明文などの場所の詳細を...それはまた、プロットエリアの周りにハードコーディングされたマージンを含むので、あなたは何を達成することはできません単にチャートをスタイリングするだけです。あなただけのチャート領域と他には何をしたい場合は、次のようにチャートのテンプレートを簡略化することができます。

xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit" 

<Grid> 
    <chartingToolkit:Chart x:Name="chart" Width="500" Height="300" 
         Margin="0, 0, 0, 0" Padding="0"> 
    <chartingToolkit:AreaSeries ItemsSource="{Binding}" 
            DependentValuePath="Value" 
            IndependentValuePath="Key" 
            Background="Red"> 
    </chartingToolkit:AreaSeries> 
    <chartingToolkit:Chart.Axes> 
     <chartingToolkit:LinearAxis Orientation="X" ShowGridLines="False" Height="0"> 
     </chartingToolkit:LinearAxis> 
     <chartingToolkit:LinearAxis Orientation="Y" ShowGridLines="False" Width="0"/> 
    </chartingToolkit:Chart.Axes> 
    <chartingToolkit:Chart.Template> 
     <ControlTemplate TargetType="chartingToolkit:Chart"> 
     <Border Background="{TemplateBinding Background}" 
       BorderBrush="{TemplateBinding BorderBrush}" 
       BorderThickness="{TemplateBinding BorderThickness}" 
       Padding="{TemplateBinding Padding}"> 
      <Grid> 
      <chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}"> 
       <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" /> 
       <Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" /> 
      </chartingprimitives:EdgePanel> 
      </Grid> 
     </Border> 
     </ControlTemplate> 
    </chartingToolkit:Chart.Template> 
    </chartingToolkit:Chart> 
</Grid> 

これは、あなたが見ているパディングを削除します。

+0

ありがとうございます。 コンテンツを追加すると、グラフは表示されません。それを動作させるためのあらゆるアイデア? –

+0

私はあまりにも積極的にテンプレートの一部を切り取っていたようです。上記の私の回答を編集しました。グラフにゼロ埋めがあり、軸の幅/高さがゼロであることに注意してください。 – ColinE

+0

ありがとうございました..これは私の問題を解決しました –

0

コントロールを再テンプレートせずにもう少し余裕を持たせるには、マージンを設定してください。グラフコントロールをゼロにします。

Margin="0" Padding="0" 
関連する問題