2012-11-27 134 views
0

目前,我試圖與WPF圖表工具圖表,
的要求是,Y軸應顯示如下圖:
Y-axisWPF圖表工具軸刻度與自定義值

描述
* 0〜84級d
* 85〜99爲B級
...

我不知道圖表工具包是否可以讓這種類型的Y軸的規模。
如果上面的圖表工具箱不支持,我會嘗試將TextBox控件直接放到「Level *」標籤的畫布上,但我有問題,我怎麼才能只顯示85,100,115作爲Y軸的比例。

任何幫助,將不勝感激。謝謝。

回答

1

您可以嘗試使用Converter作爲圖表的軸標籤。事情是這樣的: XAML

<chartingToolkit:Chart Name="chart1" > 
<chartingToolkit:Chart.Resources> 
    <HideConverter x:Key="HideConverter1" /> 
</chartingToolkit:Chart.Resources> 
<chartingToolkit:Chart.Axes> 
    <chartingToolkit:LinearAxis Orientation="Y" ShowGridLines="False" Interval="5" Minimum="0" Maximum="150" > 
    <chartingToolkit:LinearAxis.AxisLabelStyle> 
    <Style TargetType="chartingToolkit:AxisLabel"> 
    <Setter Property="Template"> 
     <Setter.Value> 
     <ControlTemplate TargetType="chartingToolkit:AxisLabel"> 
     <TextBlock DataContext="{TemplateBinding FormattedContent}" Text="{Binding Converter={StaticResource HideConverter1}}" /> 
     </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    </Style> 
    </chartingToolkit:LinearAxis.AxisLabelStyle> 
    </chartingToolkit:LinearAxis> 
</chartingToolkit:Chart.Axes> 
</chartingToolkit:Chart> 

,並在你的代碼隱藏轉換器是

public class HideConverter : IValueConverter 
{ 

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     // value is the current tick on the Y axis 
     int x = int.Parse(value.ToString()); 
     switch (x) 
     { 
      case 85: 
      case 100: 
      case 115: 
       return value; 
      case 40: // I set 40 to be in the middle between 0 and 85 
       return "Level D"; 
      case 90: 
       return "Level C"; 
      case 110: 
       return "Level B"; 
      case 130: 
       return "Level A"; 
      default: 
       return null;; 
     } 
     return null; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

HTH

+0

感謝您的建議。我只是將整個Y軸隱藏起來(可見性=「隱藏」)並將圖像重疊在父畫布中。這種情況下不需要的「蜱蟲」將不會顯示在軸上。 – Ju2017