2014-03-12 28 views
7

我有一個工作正常的Column系列圖表。滾動X軸繪圖區 - Silverlight Column系列

我有一個功能,我需要添加到這一點,我希望水平滾動被啓用到繪圖區域是x軸。

下面是截圖:

enter image description here

如果你看到屏幕快照,我有六個項目,以及酒吧,因爲更多數量的項目非常薄,所以想,如果我有20個項目那麼酒吧將根本不可見。

那麼我們可以讓X軸橫向滾動嗎?

編輯

ResourceDictionary.xaml

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:convertor="clr-namespace:ChartingDV.Provider" 
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"> 

    <ControlTemplate x:Key="PhoneChartPortraitTemplate" TargetType="charting:Chart"> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="*"/> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <datavis:Title 
       Content="{TemplateBinding Title}" 
       Style="{TemplateBinding TitleStyle}"/> 
      <datavis:Legend x:Name="Legend" 
       Grid.Row="2" 
       Header="{TemplateBinding LegendTitle}" 
       Style="{TemplateBinding LegendStyle}"> 
       <datavis:Legend.ItemsPanel> 
        <ItemsPanelTemplate> 
         <StackPanel Orientation="Horizontal"/> 
        </ItemsPanelTemplate> 
       </datavis:Legend.ItemsPanel> 
       <datavis:Legend.Template> 
        <ControlTemplate TargetType="datavis:Legend"> 
         <Grid> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="Auto" /> 
           <RowDefinition /> 
          </Grid.RowDefinitions> 
          <ScrollViewer 
            Grid.Row="1" 
            HorizontalScrollBarVisibility="Auto" 
            VerticalScrollBarVisibility="Disabled" 
            BorderThickness="0" 
            Padding="0" 
            IsTabStop="False"> 
           <ItemsPresenter 
             x:Name="Items" 
             Margin="10,0,10,10"/> 
          </ScrollViewer> 
         </Grid> 
        </ControlTemplate> 
       </datavis:Legend.Template> 
      </datavis:Legend> 
      <chartingprimitives:EdgePanel 
       Grid.Column="0" 
       Grid.Row="1" 
       x:Name="ChartArea" 
       Style="{TemplateBinding ChartAreaStyle}"> 
       <Grid 
        Canvas.ZIndex="-1" 
        Style="{TemplateBinding PlotAreaStyle}" /> 
      </chartingprimitives:EdgePanel> 
     </Grid> 
    </ControlTemplate> 

    <!-- Chart Style for Phone --> 
    <Style x:Key="PhoneChartStyle" TargetType="charting:Chart"> 
     <Setter Property="IsTabStop" Value="False" /> 
     <Setter Property="Padding" Value="10" /> 
     <Setter Property="Palette"> 
      <Setter.Value> 
       <datavis:ResourceDictionaryCollection> 
        <!-- Blue --> 
        <ResourceDictionary> 
         <SolidColorBrush x:Key="Background" Color="#E85F3D"/> 
         <Style x:Key="DataPointStyle" TargetType="Control"> 
          <Setter Property="Background" Value="{StaticResource Background}" /> 
         </Style> 
         <Style x:Key="DataShapeStyle" TargetType="Shape"> 
          <Setter Property="Stroke" Value="{StaticResource Background}" /> 
          <Setter Property="StrokeThickness" Value="2" /> 
          <Setter Property="StrokeMiterLimit" Value="1" /> 
          <Setter Property="Fill" Value="{StaticResource Background}" /> 
         </Style> 
        </ResourceDictionary> 
        <!-- Red --> 
        <ResourceDictionary> 
         <SolidColorBrush x:Key="Background" Color="#76D164"/> 
         <Style x:Key="DataPointStyle" TargetType="Control"> 
          <Setter Property="Background" Value="{StaticResource Background}" /> 
         </Style> 
         <Style x:Key="DataShapeStyle" TargetType="Shape"> 
          <Setter Property="Stroke" Value="{StaticResource Background}" /> 
          <Setter Property="StrokeThickness" Value="2" /> 
          <Setter Property="StrokeMiterLimit" Value="1" /> 
          <Setter Property="Fill" Value="{StaticResource Background}" /> 
         </Style> 
        </ResourceDictionary> 
        <!-- Light Green --> 
        <ResourceDictionary> 
         <SolidColorBrush x:Key="Background" Color="#648ED1"/> 
         <Style x:Key="DataPointStyle" TargetType="Control"> 
          <Setter Property="Background" Value="{StaticResource Background}" /> 
         </Style> 
         <Style x:Key="DataShapeStyle" TargetType="Shape"> 
          <Setter Property="Stroke" Value="{StaticResource Background}" /> 
          <Setter Property="StrokeThickness" Value="2" /> 
          <Setter Property="StrokeMiterLimit" Value="1" /> 
          <Setter Property="Fill" Value="{StaticResource Background}" /> 
         </Style> 
        </ResourceDictionary> 
       </datavis:ResourceDictionaryCollection> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="LegendStyle"> 
      <Setter.Value> 
       <Style TargetType="datavis:Legend"> 
        <Setter Property="HorizontalAlignment" Value="Center"/> 
        <Setter Property="VerticalAlignment" Value="Center"/> 
        <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/> 
        <Setter Property="Margin" Value="20"/> 
       </Style> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="ChartAreaStyle"> 
      <Setter.Value> 
       <Style TargetType="Panel"> 
        <Setter Property="MinWidth" Value="100" /> 
        <Setter Property="MinHeight" Value="75" /> 
       </Style> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="PlotAreaStyle"> 
      <Setter.Value> 
       <Style TargetType="Grid"> 
        <Setter Property="Background" Value="Transparent"/> 
       </Style> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="Template" Value="{StaticResource PhoneChartPortraitTemplate}"/> 
    </Style> 

</ResourceDictionary> 

在XAML文件:

<charting:Chart Name="barChart" 
    Style="{StaticResource PhoneChartStyle}" 
    Template="{StaticResource PhoneChartPortraitTemplate}"> 
    <charting:Chart.Series> 
     <charting:ColumnSeries 
      Title="Incorrect" 
      IndependentValueBinding="{Binding Key}" 
      DependentValueBinding="{Binding Value}" 
      AnimationSequence="Simultaneous"> 
     </charting:ColumnSeries> 
     <charting:ColumnSeries     
      Title="Correct" 
      IndependentValueBinding="{Binding Key}" 
      DependentValueBinding="{Binding Value}" 
      AnimationSequence="Simultaneous"> 
     </charting:ColumnSeries> 
     <charting:ColumnSeries     
      Title="Skipped" 
      IndependentValueBinding="{Binding Key}" 
      DependentValueBinding="{Binding Value}" 
      AnimationSequence="Simultaneous"> 
     </charting:ColumnSeries> 
    </charting:Chart.Series> 
</charting:Chart> 
+1

你可以嘗試編輯模板,並添加一個'ScrollViewer'控制在那裏,但在這種情況下,Y軸將滾動和隱藏過。但我不知道更好的方法。 – vorrtex

+0

@vorrtex我應該在這裏添加我的風格嗎?你能幫我編輯一下嗎? – Goofy

+0

是的,發佈圖表控件模板。 – vorrtex

回答

0

最後我已經解決了,但我還沒有作出了API的變化,相反,我遵循了下面的方法。

1)我們可以選擇滾動整個圖表。

2)使整個條形圖滾動,然後刪除Y axis值。

3)現在用Y axis values使用Grid row definitions創建一個虛擬佈局。這會將您的根Grid

4)現在在根網格內部,您可以繪製網格圖。

5)現在,當您測試沒有測試時,您可以滾動圖表,但您的虛擬佈局的值爲Y axis,因此對於用戶來說,它看起來像條形圖正在滾動。

享受:)