0

我希望这是一个简单的问题,尽管我还没有在网上找到答案。

我使用的是 2010 年 4 月发布的 Silverlight Toolkit 的系列产品,我只需要在 DateTimeAxis 或 LinearAxis 中显示最小值和最大值(我指定)。通过“显示”,我的意思是在轴的两端显示实际的“刻度”加上其相关值。

这可能吗?

谢谢!

4

2 回答 2

1

刚刚在我的博客上回复了你的 Q: http://geoffwebbercross.blogspot.com/2011/02/silverlight-4-toolkit-zoom-and-pan.html?showComment= 1311446800567#c5905503102900111342

“嗨,维克多,我不认为你可以使用内置轴来实现这一点,因为它不是为了做到这一点而设计的。但是你可以通过像我在这个例子中那样设计图表上的 x 轴来实现这一点,然后创建您自己的伪轴,方法是在每一端的图表外部放置两个文本块;可能需要一些时间来获得正确的格式,但肯定会起作用,因为它是一个简单的解决方法。您可以使用 LINQ 来获取最小值和最大值数据已加载并绑定到这些值。”

在此处获取包含样式化轴示例的代码:

http://slchartzoomandpan.codeplex.com/

于 2011-07-23T18:50:29.527 回答
1

是的你可以。设置您的最小值和最大值,并将您的间隔设置为最小值和最大值之间的差。

IE:

<toolkit:LinearAxis Minimum="0" Orientation="X" Maximum="105" Interval="105"/>

更新:(对于 DateTimeAxis)

修复 DateTimeAxis 有点困难。这是我通过 IValueConverter 的解决方案:

 public class AxisFormatter : IValueConverter
  {
    public Object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (DateTime.Parse(value.ToString()) != maxDate && DateTime.Parse(value.ToString() != minDate)
            return null;
        else
            return value;
    }

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

其中 minDate 和 maxDate 是轴的上限和下限的硬编码值。

此外,您将需要通过轴的 AxisLabelStyle 实现此转换器。因此,在您的 Styles.xaml 或您存储样式的任何位置,放置此样式:

<Style x:Key="DateTimeAxisLabelStyle1" TargetType="charting:DateTimeAxisLabel">
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="YearsIntervalStringFormat" Value="{}{0:yyyy}"/>
    <Setter Property="MonthsIntervalStringFormat" Value="{}{0:d}"/>
    <Setter Property="WeeksIntervalStringFormat" Value="{}{0:d}"/>
    <Setter Property="DaysIntervalStringFormat" Value="{}{0:d}"/>
    <Setter Property="HoursIntervalStringFormat" Value="{}{0:t}"/>
    <Setter Property="MinutesIntervalStringFormat" Value="{}{0:t}"/>
    <Setter Property="SecondsIntervalStringFormat" Value="{}{0:T}"/>
    <Setter Property="MillisecondsIntervalStringFormat" Value="{}{0:mm:ss.fff}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="charting:DateTimeAxisLabel">
                <TextBlock DataContext="{TemplateBinding FormattedContent}" Text="{Binding Converter={StaticResource axisFormatter}}"></TextBlock>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

并将 xmlns:local="clr-namespace:YOURPROJECTNAME 添加到您的 XAML 文件中,并将 local:AxisFormatter x:Key="AxisFormatter" 添加到您的资源字典中。

然后在你的轴的实际 XAML 声明中,如下所示放置它;

<toolkit:DateTimeAxis AxisLabelStyle="{StaticResource DateTimeAxisLabelStyle1}"  Orientation="X" />

抱歉,这个解决方案有点复杂,如果您需要进一步的指导,请告诉我。

于 2011-07-15T17:10:19.460 回答