目前我正在尝试用WPF图表工具包制作图表,
要求是Y轴应如下图所示:
描述了 * 0~84为D级 * 85~99级为B级 ...
我不确定图表工具包是否可以制作这种类型的Y轴刻度 如果图表工具包不支持上面的话,我会尝试将TextBox控件直接放入画布中“Level *”标签,我仍有问题,如何只显示85,100,115作为Y轴的比例。
任何帮助将不胜感激。谢谢。
答案 0 :(得分: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