This is a migrated thread and some comments may be shown as answers.

TimeSpan on Y axis

3 Answers 52 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Halász Levente
Top achievements
Rank 1
Halász Levente asked on 26 Aug 2010, 07:15 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 31 Aug 2010, 03:32 PM
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
0
Halász Levente
Top achievements
Rank 1
answered on 03 Sep 2010, 10:04 AM
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
0
Yavor
Telerik team
answered on 07 Sep 2010, 09:17 AM
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
Tags
Chart
Asked by
Halász Levente
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Halász Levente
Top achievements
Rank 1
Share this question
or