Multiple Series Charts with WPFtoolkit

試著忘記壹切 提交于 2019-11-29 02:16:56
Tom Dudfield

You might want to consider the alternatives, from past experience the charting components in the WPF Toolkit are extremely rigid and hard to extend. I've also had numerous issues with bugs in the toolkit and active development seems to have completely ground to a halt. There are some very good free alternative that are worth considering.

If you want a Chart with two LineSeries

You may have 2 different lists in your .cs file filed with data:

List<KeyValuePair<DateTime, int>> llistaGastats = new List<KeyValuePair<DateTime, int>>();
List<KeyValuePair<DateTime, int>> llistaPreu = new List<KeyValuePair<DateTime, int>>();

Then you have to create another list to group those two lists:

var dataSourceList = new List<List<KeyValuePair<DateTime, int>>>();
dataSourceList.Add(llistaGastats);
dataSourceList.Add(llistaPreu);

And assign it to the DataContext

lineChart.DataContext = dataSourceList;

In your .xaml file you should create a Chart with two LineSeries and get the value of each Line using the ItemSource field.

Here is the .xaml:

<chartingToolkit:Chart Name="lineChart"
                                       Title="Consum KW" 
                                       VerticalAlignment="Top" 
                                       Margin="0,58,58,0" 
                                       Height="382"
                                       Grid.Column="1">
                <chartingToolkit:LineSeries Name="KWG"
                                                Title="KW Gastats"  
                                                DependentValuePath="Value" 
                                                IndependentValuePath="Key"
                                                ItemsSource="{Binding [0]}"
                                                IsSelectionEnabled="True"/>
                <chartingToolkit:LineSeries Name="KWP" 
                                                Title="Preu KW"  
                                                DependentValuePath="Value" 
                                                IndependentValuePath="Key"
                                                ItemsSource="{Binding [1]}"
                                                IsSelectionEnabled="True" />
            </chartingToolkit:Chart>

ItemsSource="{Binding [0]}" Binds the first item in the list assigned to the DataContext. ItemsSource="{Binding [1]}" Binds the second

Beat Kiener has a great article on Databinding Multi-Series Charts. In it, he implements his own MultiChart class, derived from Chart.

This may be too late for you, but at least it may help others.

create a datatable with a column for each series , add five column series(in case of column chart,and five series) to the chart , with DependentValueBinding to each column name, set ItemsSource to datatable( ItemsSource is same for each column series).

Let me know if you want me to add the code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!