在WPF工具包图表中更改绘图区域和标题周围的边距 [英] Change margin around plot area and title in WPF Toolkit chart
问题描述
我正在使用WPF Toolkit 2010年2月版的Chart控件。图表相对于绘图区域占用了大量空间。
I am using the Chart control of WPF Toolkit February 2010 release. The chart takes up lots of space relative to the plot area.
如何控制绘图区域和图表标题周围的边距。这样,我可以在网格中排列我需要的10个图表,而不必在屏幕上占用太多空间。
How do I control the margin around the plot area and title of the chart. This way, I can arrange the 10 charts I need in a grid without having to use so much space on the screen.
谢谢,
sprite。
推荐答案
我在WPF工具包讨论板中找到了类似问题的答案,并认为我会分享这些知识。
I found an answer to a similar question in the WPF Toolkit discussion boards and thought I'd share the knowledge.
当前唯一可用的解决方案是自己设置图表样式。因此,基本上,我从工具箱的源代码中获取了原始样式定义,并对其进行了修改以满足我的需求。我还使用它完全删除了图例。
The only solution currently available is to style the chart myself. So basically, I took the original style definition from the source code of the toolkit and I modified it to meet my needs. I also used this to remove the legend completely.
<Grid.Resources>
<!-- chart style modified from WPFToolkit\DataVisualization\Themes\generic.xaml -->
<Style TargetType="charts:Chart">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charts:Chart">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<dataVis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" Margin="1"/>
<!-- Use a nested Grid to avoid possible clipping behavior resulting from ColumnSpan+Width=Auto -->
<Grid Grid.Row="1" Margin="5,0,5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<chartPrmtvs:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
<Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />
</chartPrmtvs:EdgePanel>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
此模板将标题和情节区域周围的边距最小化,也删除了图例。然后,我在适合我需要的用户控件中使用了此控件,并多次重复使用。
This template removes margins to a bare minimum around the title and plot area and also removes the legend. I then used this in a user control suited to my needs and reused it many times over.
在控件的标题中定义了以下命名空间:
The following namespaces were defined in the header of the control:
xmlns:dataVis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:chartPrmtvs="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:charts="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
享受吧!
这篇关于在WPF工具包图表中更改绘图区域和标题周围的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!