我开发了一个c#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;
}
}
}
缩放效果不是很好,有没有办法为它添加滚动条或适当的缩放属性。
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>
答案 0 :(得分:0)
在Xaml的ScrollView中包装图表将允许您滚动。
答案 1 :(得分:0)
我看到Chart控件不支持滚动本身。因此将其包装在ScrollViewer
内可提供解决方案。为此,您可以将图表设置为固定或最小尺寸。
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<dvc:Chart Name="chart" MinWidth="500" MinHeight="300">
(...)
</dvc:Chart>
</ScrollViewer>