TimeSpan on Y axis

4 posts, 1 answers
  1. Halász Levente
    Halász Levente avatar
    21 posts
    Member since:
    Feb 2010

    Posted 26 Aug 2010 Link to this post

    Hello again,

    We are using MVVM in our project, thus I have issues using your Chart with TimeSpan type. Here is my scenario:
    - i have some records containing event data (when did a problem arise, when did we start to solve it, when was it solved etc.)
    - i need a chart displaying the total, avg, min, max time spent on solving the problems on day, month, year basis

    I found that the aggregation part can be easily with custom aggregate functions (which is great), but the problem is that y axis accepts only double, which is not so great, since displaying 3600 seconds instead of 1 hour will be not appreciated by my customer.

    So is there a way to convert the data point label and the y axis label back to timespan without messing in the code behind xaml

    Regards,

    Levente
  2. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 31 Aug 2010 Link to this post

    Hi Halász Levente,

    You can use custom control template with converter to convert the seconds to meaningful labels for the series item labels like this:

              <Style x:Key="SeriesItemLabelStyle"
    TargetType="telerik:SeriesItemLabel">
                  <Setter Property="Foreground"
         Value="#FF535353" />
                  <Setter Property="Template">
                      <Setter.Value>
                          <ControlTemplate TargetType="telerik:SeriesItemLabel">
                              <Canvas>
                                  <Polyline x:Name="PART_Connector"
                           Style="{TemplateBinding ConnectorStyle}" />
                                  <Border x:Name="PART_TextContainer" DataContext="{TemplateBinding Content}"
                         Style="{TemplateBinding LabelStyle}"
                         Canvas.Left="{TemplateBinding TextContainerCanvasLeft}"
                         Canvas.Top="{TemplateBinding TextContainerCanvasTop}">
                                      <TextBlock Margin="{TemplateBinding Padding}"
                                Text="{Binding Converter={StaticResource timespanConverter}}"
                                TextAlignment="{TemplateBinding HorizontalContentAlignment}" />
                                  </Border>
                              </Canvas>
                          </ControlTemplate>
                      </Setter.Value>
                  </Setter>
              </Style>

    Giving meaningful labels for the axis item labels can be done on the RangeChanged event like this:
    private void AxisY_RangeChanged(object sender, EventArgs e)
    {
        foreach (TickPoint tick in RadChart1.DefaultView.ChartArea.AxisY.TickPoints)
        {
            tick.Label = TimeSpan.FromSeconds(tick.Value).ToString();
        }
    }

    I have attached a sample application that demonstrates this solution. Please review it and if you have any more questions don't hesitate to contact us again!

    Sincerely yours,
    Yavor Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Halász Levente
    Halász Levente avatar
    21 posts
    Member since:
    Feb 2010

    Posted 03 Sep 2010 Link to this post

    Thank your for your kind response. Meanwhile I managed to resolve the problem, by adding a new TimeSpan type property to my DataClass which is calculated as you did in the converter and item mapped to Label.

    Unfortunately couldn't find a better method than using RangChanged event to format axis labels (as you did).

    If you could make these labels so i could use templates than I think all my trouble would go away.

    Thank you again for your support.

    Regards,

    Levente
  4. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 07 Sep 2010 Link to this post

    Hello Halász Levente,

     You can use our custom format expression for the axis labels to access your property like this

    #DATAITEM.<PropertyName>
    More information on this can be found in our help system here.

    Greetings,
    Yavor Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top