开发者

How to display minimum and maximum values for DateTimeAxis or LinearAxis in Silverlight Toolkit's line series

I'm hoping this is a simple question, though I have not been able to find an answer yet on the w开发者_StackOverfloweb.

I'm using the April 2010 release of Silverlight Toolkit's line series and I'm required to display only the minimum and maximum values (which I specify) in a DateTimeAxis or LinearAxis. By "display", I mean showing the actual "tick" plus its related value on both ends of the axis.

Is this possible at all?

Thanks!


Yes you can. Set your Minimum and Maximum values and set your Interval as the difference between Minimum and Maximum.

ie:

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

UPDATE: (for DateTimeAxis)

It is a little harder to fix the DateTimeAxis. Here's my solution via 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();
    }
}

where minDate and maxDate are your hard-coded values for the upper and lower bounds of your axis.

Also, you will need to implement this Converter via the AxisLabelStyle of your axis. Thus, in your Styles.xaml or wherever you store your styles, place this style:

<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>

and add xmlns:local="clr-namespace:YOURPROJECTNAME to your XAML file as well as adding local:AxisFormatter x:Key="AxisFormatter" to your resource dictionary.

Then in your axis's actual XAML declaration, put it as shown below;

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

Sorry that this solution is kind of complicated, and let me know if you need further guidance.


Just replied on your Q on my blog:http://geoffwebbercross.blogspot.com/2011/02/silverlight-4-toolkit-zoom-and-pan.html?showComment=1311446800567#c5905503102900111342

"Hi Victor, I wouldn't think you could achieve this with the built in axis as it's not designed to do this. However you could potentially do this by styling out the x axis on the chart like I do in this example, then create your own pseudo axis by placing two textblocks underneath external to the chart at each end; it may take some time to get the formatting right but will definitely work as it's a simple work-around. You could use LINQ to get the min and max when the data is loaded and bind to these values."

Get the code which contains example of styling out axes here:

http://slchartzoomandpan.codeplex.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜