更改 WPF Toolkit 图表中绘图区域和标题周围的边距

发布于 2024-09-16 13:55:01 字数 156 浏览 10 评论 0原文

我正在使用 WPF Toolkit 2010 年 2 月版本的 Chart 控件。图表相对于绘图区域占用了大量空间。

如何控制绘图区域和图表标题周围的边距。这样,我可以将我需要的 10 个图表排列在网格中,而无需在屏幕上使用太多空间。

谢谢,

精灵。

I am using the Chart control of WPF Toolkit February 2010 release. The chart takes up lots of space relative to the plot area.

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.

Thanks,

sprite.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独留℉清风醉 2024-09-23 13:55:02

我在 WPF Toolkit 讨论区中找到了类似问题的答案,并认为我应该分享这些知识。

当前唯一可用的解决方案是自己设置图表样式。所以基本上,我从工具包的源代码中获取了原始的样式定义,并对其进行了修改以满足我的需求。我还用它来完全删除图例。

<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>

此模板将标题和绘图区域周围的边距降至最低限度,并删除了图例。然后,我在适合我的需求的用户控件中使用了它,并多次重复使用它。

在控件的标头中定义了以下命名空间:

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"

享受吧!

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"

Enjoy!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文