WPF 制作交互式图表
我在 中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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 subclassLineSeries
and overrideCreateDataPoint()
to create your custom LineDataPoint items.In this case, your
ItemsSource
would not be an IEnumerable of values (egIEnumerable<decimal>
), but rather of value holder objects (egIEnumerable<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 settingDependentValueBinding
to aTwoWay
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.检查此库
http://www.fusioncharts.com/demos/features /#数据可视化编辑
Check this library
http://www.fusioncharts.com/demos/features/#visual-editing-of-data