2012-11-13 23 views

回答

3

您可以使用LabelProvider來達到您想要的效果。你將不得不創建一個新的LabelProvider類,這個類不是來自於LabelProviderBase,或者更具體的來說就是NumericLabelProviderBase。你應該能夠把你擁有的所有滴答(1,0-1),並使用新的LabelProviderClass中的一個if或者一個開關,將它們變成字符串。標籤提供者的來源中有許多可用作基礎的示例。

您要覆蓋的方法是CreateLabels。這是一個快速的方法,我應該(希望!)把你帶到你需要的地方。在您創建的新課程中實施。

public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) {    

     var ticks = ticksInfo.Ticks; 
     Init(ticks);    

     UIElement[] res = new UIElement[ticks.Length]; 
     LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info }; 
     for (int i = 0; i < res.Length; i++) { 
      tickInfo.Tick = ticks[i]; 
      tickInfo.Index = i; 
      string labelText = ""; 

      if(Convert.ToInt32(tickInfo.Tick) == 1) { 
       labelText = "High"; 
      } else if(Convert.ToInt32(tickInfo.Tick) == 0) { 
       labelText = "Medium" 
      } else if(Convert.ToInt32(tickInfo.Tick) == -1) { 
       labelText = "Low" 
      } else { 
       labelText = "" 
      } 

      TextBlock label = (TextBlock)GetResourceFromPool(); 
      if (label == null) { 
       label = new TextBlock(); 
      } 

      label.Text = labelText; 
      label.ToolTip = ticks[i].ToString(); 

      res[i] = label; 

      ApplyCustomView(tickInfo, label); 
     } 
     return res; 
    } 

爲了這個新LabelProvider分配到海圖機,命名要在XAML標記或創建爲C#中的對象軸:

yAxis.LabelProvider = new ZazkapulskLabelProvider(); 
+0

賈森,我應該帶你去保持。再次感謝。您是否會告訴我如何在繪圖儀=新ChartPlotter的定義中使用此方法? – zazkapulsk

+0

我會編輯我的答案! :) –

+0

傑森,你的地址是?在哪裏送花?順便說一句,你見過這個 - http://stackoverflow.com/questions/13378180/wpf-dynamicdatadisplay-slow-plotting-with-markers? – zazkapulsk

0

不要使用上的解決方案。讓我的許多編譯器錯誤。我在3小時試圖在VS2013上的解決方案,但沒有工作。使用該解決方案,其中功能平局圖:

dimSeviyesiAxis.LabelProvider.CustomFormatter = (tickInfo) => 
     { 
      return "%" + tickInfo.Tick.ToString(); 
     }; 

這dimSeviyesiAxis是XAML軸名所做的軸標籤以「%」開始。在返回之前,您可以編寫任何條件語句。這裏是來源鏈接:

http://dynamicdatadisplay.codeplex.com/discussions/462842

+0

@Hamed你遇到了哪個錯誤? –

相關問題