在WPF工具包图表中更改绘图区域和标题周围的边距

编程入门 行业动态 更新时间:2024-10-27 17:21:15
本文介绍了在WPF工具包图表中更改绘图区域和标题周围的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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工具包图表中更改绘图区域和标题周围的边距

本文发布于:2023-07-18 05:07:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具包   图表   区域   标题   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!