2016-03-09 33 views
0

我已經開發了ac#WPF應用程序 我想對我的圖表視圖執行縮放或滾動條,導致數據正在彼此合併,我相信縮放或添加滾動條會成爲解決方案。 到目前爲止,我有這個。順便說一句,我正在做一個柱形圖。如何將滾動條添加到圖表

public partial class ChartControl : UserControl 
{ 
    System.Windows.Forms.ScrollableControl ctl = new System.Windows.Forms.ScrollableControl(); 
    public ChartControl() 
    { 
     InitializeComponent(); 
     scrollbar(); 
    } 

    private System.Windows.Forms.ScrollBars scrollbar() 
    { 
     if (ctl.HorizontalScroll.Visible) 
      return ctl.VerticalScroll.Visible ? System.Windows.Forms.ScrollBars.Both : System.Windows.Forms.ScrollBars.Horizontal; 
     else 
      return ctl.VerticalScroll.Visible ? System.Windows.Forms.ScrollBars.Vertical : System.Windows.Forms.ScrollBars.Horizontal; 
    } 

    private void Grid_MouseWheel(object sender, MouseWheelEventArgs e) 
    { 
     if (e.Delta > 0) 
     { 
      chartzoom.ScaleX += 1; 
      chartzoom.ScaleY += 1; 
     } 
     else 
     { 
      chartzoom.ScaleX -= 1; 
      chartzoom.ScaleY -= 1; 
     } 
    } 
} 

zoom是不是很有效,有沒有辦法給它添加一個滾動條或適當的縮放屬性。

XAML代碼如下::

<Grid MouseWheel="Grid_MouseWheel"> 

     <dvc:Chart Canvas.Top="80" Name="chart" PreviewMouseWheel="Grid_MouseWheel" > 

      <dvc:Chart.LayoutTransform> 
       <ScaleTransform x:Name="chartzoom"></ScaleTransform>    
      </dvc:Chart.LayoutTransform> 

      <dvc:Chart.Series > 
       <dvc:ColumnSeries Title="{Binding LineGraphTitledg1}" 
            ItemsSource="{Binding Data}" 
            IndependentValueBinding="{Binding Path=Time}" 
            DependentValueBinding="{Binding Path=DG1}" /> 
       <dvc:ColumnSeries Title="{Binding LineGraphTitledg2 }" 
            ItemsSource="{Binding Data}" 
            IndependentValueBinding="{Binding Path=Time}" 
            DependentValueBinding="{Binding Path=DG2}" /> 
       <dvc:ColumnSeries Title="{Binding LineGraphTitledg3}" 
            ItemsSource="{Binding Data}" 
            IndependentValueBinding="{Binding Path=Time}" 
            DependentValueBinding="{Binding Path=DG3}" /> 
       <dvc:ColumnSeries Title="{Binding LineGraphTitledgunits}" 
            ItemsSource="{Binding Dataunitvsfuel}" 
            IndependentValueBinding="{Binding Path=kwh}" 
            DependentValueBinding="{Binding Path=fuel}" 
            IsSelectionEnabled="True" />            
      </dvc:Chart.Series> 
     </dvc:Chart> 
+1

請向我們展示一些XAML代碼,特別是您定義圖表的XAML代碼。 –

+0

@HermanCordes請參閱,因爲我已更新xaml。 – anilG

回答

0

結束語在XAML中滾動型圖表將允許您滾動。

+1

你能舉個例子嗎? – anilG

0

我看到Chart控件不支持滾動本身。因此,將其包裝在ScrollViewer內提供瞭解決方案。爲此,您已將圖表設置爲固定或最小尺寸。

<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"> 
    <dvc:Chart Name="chart" MinWidth="500" MinHeight="300"> 
     (...) 
    </dvc:Chart> 
</ScrollViewer>