2015-11-28 66 views
0

首先我XAMLWPF工具包數據可視化 - 如何在代碼背後設置間隔,最小值和最大值?

<charting:Chart x:Name="ChartMain" /> 

這裏是我的代碼背後:

List<KeyValuePair<string, int>> valueList1 = new List<KeyValuePair<string, int>>(); 
valueList1.Insert(0, new KeyValuePair<string, int>(DateTime.Now.ToString(), 1)); 

LineSeries lineSeries1 = new LineSeries(); 
lineSeries1.Title = "Eins"; 
lineSeries1.DependentValuePath = "Value"; 
lineSeries1.IndependentValuePath = "Key"; 
lineSeries1.ItemsSource = valueList1; 
ChartMain.Series.Add(lineSeries1); 

我的問題:如何設置的最小/最大和時間間隔在後面的代碼?

+0

看看'ChartMain.Axes'。你看到該集合中有任何可用的軸? – jsanalytics

+0

是的,我願意。示例: \t \t \t LinearAxis lx = new LinearAxis(); \t \t \t lx.Minimum = -1; \t \t \t lx.Maximum = +1; \t \t \t lx.Interval = 0.5; \t \t \t ChartMain.Axes.Add(lx); 但編譯後我無法看到圖表上的ist ... – MeerArtefakt

+0

哦,對不起,一行丟失: lx.Orientation = AxisOrientation.Y; 現在它可以正常工作 - 我感謝你! – MeerArtefakt

回答

0
List<KeyValuePair<string, int>> valueList1 = new List<KeyValuePair<string, int>>(); 
valueList1.Insert(0, new KeyValuePair<string, int>(DateTime.Now.ToString(), 1)); 

LineSeries lineSeries1 = new LineSeries(); 
lineSeries1.Title = "Eins"; 
lineSeries1.DependentValuePath = "Value"; 
lineSeries1.IndependentValuePath = "Key"; 
lineSeries1.ItemsSource = valueList1; 
ChartMain.Series.Add(lineSeries1); 

LinearAxis linearAxis = new LinearAxis(); 
linearAxis.Orientation = AxisOrientation.Y; 
linearAxis.Minimum = 0; 
linearAxis.Maximum = +1; 
linearAxis.Interval = 0.1; 

ChartMain.Axes.Add(linearAxis); 
+0

我會使用'KeyValuePair '和'DateTimeAxis'來代替。 – jsanalytics

+0

'KeyValuePair '聽起來非常好!但是我需要兩個軸嗎?一個用於'AxisOrientation.X'(DateTime),另一個用於'AxisOrientation.Y'(Value)? – MeerArtefakt

+0

並非如此,您可以完全按照您迄今所做的操作完成,只需用'DateTimeAxis'代替'LinearAxis'即可。 – jsanalytics

相關問題