WPF 制作交互式图表

发布于 2024-08-11 10:48:29 字数 2162 浏览 3 评论 0原文

我在 中使用 System.Windows.Controls.DataVisualization.Toolkit 绘制图表WPF 应用程序。 图表的代码是:

<chartingToolkit:Chart>
                        <!-- Volume -->
                        <chartingToolkit:LineSeries
                            Title="Volume (M)"
                            ItemsSource="{StaticResource StockDataCollection}"
                            IndependentValuePath="Date"
                            DependentValuePath="Volume"/>
                        <!-- Price -->
                        <chartingToolkit:LineSeries
                            Title="Price ($)"
                            ItemsSource="{StaticResource StockDataCollection}"
                            IndependentValuePath="Date"
                            DependentValuePath="Price"/>
                        <chartingToolkit:Chart.Axes>
                            <!-- Axis for custom range -->
                            <chartingToolkit:LinearAxis
                                Orientation="Y"
                                Minimum="0"
                                Maximum="100"
                                ShowGridLines="True"/>
                            <!-- Axis for custom labels -->
                            <chartingToolkit:DateTimeAxis
                                Orientation="X">
                                <chartingToolkit:DateTimeAxis.AxisLabelStyle>
                                    <Style TargetType="chartingToolkit:DateTimeAxisLabel">
                                        <Setter Property="StringFormat" Value="{}{0:MMM d}"/>
                                    </Style>
                                </chartingToolkit:DateTimeAxis.AxisLabelStyle>
                            </chartingToolkit:DateTimeAxis>
                        </chartingToolkit:Chart.Axes>
                    </chartingToolkit:Chart>

我希望用户能够在任何点单击线系列并将其向上或向下拖动,这样值就会改变? 这就像双向数据绑定,但我不知道该怎么做。

I'm using System.Windows.Controls.DataVisualization.Toolkit for charts in my WPF application.
The code for chart is:

<chartingToolkit:Chart>
                        <!-- Volume -->
                        <chartingToolkit:LineSeries
                            Title="Volume (M)"
                            ItemsSource="{StaticResource StockDataCollection}"
                            IndependentValuePath="Date"
                            DependentValuePath="Volume"/>
                        <!-- Price -->
                        <chartingToolkit:LineSeries
                            Title="Price ($)"
                            ItemsSource="{StaticResource StockDataCollection}"
                            IndependentValuePath="Date"
                            DependentValuePath="Price"/>
                        <chartingToolkit:Chart.Axes>
                            <!-- Axis for custom range -->
                            <chartingToolkit:LinearAxis
                                Orientation="Y"
                                Minimum="0"
                                Maximum="100"
                                ShowGridLines="True"/>
                            <!-- Axis for custom labels -->
                            <chartingToolkit:DateTimeAxis
                                Orientation="X">
                                <chartingToolkit:DateTimeAxis.AxisLabelStyle>
                                    <Style TargetType="chartingToolkit:DateTimeAxisLabel">
                                        <Setter Property="StringFormat" Value="{}{0:MMM d}"/>
                                    </Style>
                                </chartingToolkit:DateTimeAxis.AxisLabelStyle>
                            </chartingToolkit:DateTimeAxis>
                        </chartingToolkit:Chart.Axes>
                    </chartingToolkit:Chart>

I want the user be able to click line series at any point and drag it to up or down and so the Value will be changed ?
This is like a two way data binding but I don't know how can I do it.

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

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

发布评论

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

评论(2

心作怪 2024-08-18 10:48:29

WPF Toolkit 图表控件没有任何处理鼠标拖动的代码,因此您必须自己编写。

您应该能够子类化 LineDataPoint 以添加拖动功能,然后子类化 LineSeries 并重写 CreateDataPoint() 以创建自定义 LineDataPoint 项。

在这种情况下,您的 ItemsSource 将不是值的 IEnumerable(例如 IEnumerable),而是值持有者对象(例如 IEnumerable) )。值持有者对象将具有可用于检索或设置此时的值的属性,允许通过将 DependentValueBinding 设置为 TwoWay 绑定来更新值你的财产。您可以重用应用程序中的现有对象,而不是专门为此目的创建值持有者对象。

The WPF Toolkit chart control doesn't have any code to handle mouse dragging, so you'll have to write it yourself.

You should be able to subclass LineDataPoint to add dragging functionality, then subclass LineSeries and override CreateDataPoint()to create your custom LineDataPoint items.

In this case, your ItemsSource would not be an IEnumerable of values (eg IEnumerable<decimal>), but rather of value holder objects (eg IEnumerable<MyValueObject>). The value holder objects would have a property that can be used to retrieve or set the value at that point, Allowing the value to be updated by setting DependentValueBinding to a TwoWay binding to your property. You may be able to reuse existing objects in your application rather than creating a value holder object specifically for this purpose.

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