Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

c# - Multiple Series Charts with WPFtoolkit

Does anyone of you know the way to create multiple series charts with wpftoolkit? In a nutshell what I want is to have more dependent values for the same independent value. So far I couldn't find any comprehensive mechanism to get this working. Any help is deeply appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want a Chart with two LineSeries

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...