2010-03-03 197 views
2

嗨我想知道我該如何設置X軸和Y軸的標籤?如何設置wpf工具箱圖表的y軸和x軸?如y:kg,x:年

現在,我有一個圖表的值,我格式的工具提示,但我不知道如何設置X和Y軸的標籤。

另一件事是,可以在圖表系列中執行縮放,我的意思是,如果我有x年的年數,我想將其更改爲幾個月,或者學期和新的點需要出現在行中?如果這是可行的,太難以做到了嗎?

回答

1

我無法設置y軸的標籤(我認爲它不可能),但是您可以使用Title屬性將其設置在圖例上。在x軸上,它取決於您在DataPointSeries'IndependentValueBinding上設置的綁定。

可以說這個例子中,我創建了一個類對象,它將表示每個記錄/數據點。

public class ChartInfo 
{ 
    public string Label { get; set; } 
    public double Value { get; set; } 
} 

然後,我有這樣的代碼:

List<ChartInfo> list = new List<ChartInfo>(); 
ChartInfo item = new ChartInfo(); 
item.Label = "Individual"; 
item.Vale = 27; 
list.Add(item); 
item = new ChartInfo(); 
item.Label = "Corporate"; 
item.Vale = 108; 
list.Add(item); 

DataPointSeries series = new ColumnSeries(); 
series.Title = "Quantity"; 
series.DependentValueBinding = new Binding("Value"); 
series.IndependentValueBinding = new Binding("Label"); 
series.ItemsSource = list; 
series.SelectionChanged += new SelectionChangedEventHandler(series_SelectionChanged); 
this.chartingToolkitControl.Series.Add(series); 

它會給我這樣的結果。

alt text http://www.freeimagehosting.net/uploads/78e2598620.jpg

對於縮放 - 我認爲正確的術語是下鑽。您可以使用SelectionChanged事件(請參閱上面的代碼)。你應該做的是重新查詢你的數據源並清除圖表的系列,並根據你的查詢結果添加一個新圖表。

private void series_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     //The sender here is of type DataPointSeries wherein you could get the SelectedItem (in our case ChartInfo) and from there you could do the requery. 
    } 
+0

感謝您的回答,它真的幫助我。我沒有想到這種方式的縮放。謝謝。 – Clerks 2010-03-03 15:22:04

+0

@Clerks - 如果答案幫助你不要忘記投票並將其標記爲你的問題的接受答案:) – 2010-03-04 04:21:42