开发者

WPF Make Interactive Charts

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"/>
                        <c开发者_JS百科hartingToolkit: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.


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.


Check this library

http://www.fusioncharts.com/demos/features/#visual-editing-of-data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜