[英]WPF chart toolkit axis scale with custom value
currently I'm trying to make a chart with WPF chart toolkit, 目前,我正在尝试使用WPF图表工具包制作图表,
the requirement is that Y-axis should show as the image below: 要求是Y轴应如下图所示:
which describes 描述
*0~84 is Level D * 0〜84为D级
*85~99 is Level B * B级为85〜99
... ...
I'm not sure whether chart toolkit can make this type of Y-axis scale. 我不确定图表工具包是否可以制作这种类型的Y轴比例尺。
I'll try to put TextBox controls directly into the canvas for "Level *" label if above is not supported by the chart toolkit, still I have problem how can I show only 85, 100, 115 as scale of Y axis. 如果图表工具包不支持上述功能,我将尝试将TextBox控件直接放入“级别*”标签的画布中,但仍然有问题,如何显示Y轴的比例尺仅为85、100、115。
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks.
谢谢。
You can try to use a Converter for the axis label of your chart. 您可以尝试将Converter用于图表的轴标签。 Something like this: XAML
像这样的东西: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>
and in your codebehind the converter is 在您的代码背后,转换器是
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 高温超导
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.