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

How can Xaxis label format display changes freq based on data

8 Answers 171 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
siva
Top achievements
Rank 1
siva asked on 08 Feb 2011, 03:22 PM
I have x - axis displaying datetime contains values like

02/07/2011 10:11
02/07/2011 10:13
02/07/2011 10:14
02/07/2011 10:16
02/07/2011 10:17
02/07/2011 10:18
02/08/2011 1:11
02/08/2011 1:15
02/08/2011 1:18
02/08/2011 1:30

X-Axis Label       '
                    02/07/2011 10:11  10:13 10:14 10:16 ................................... 02/08/2011 1:11 1:15...............................

how i can display this in silverlight chart. thanks in advance

8 Answers, 1 is accepted

Sort by
0
Mark Woodlief
Top achievements
Rank 1
answered on 08 Feb 2011, 05:04 PM
Siva, I'm having the exact same issue.  Would love for someone to chime in regarding formatting DateTime on the xaxis correctly. 

I need to show a range of minutes for 1 day, when i bind this data to a RadChart the chart displays data starting at the year of 1899.. which doesnt exist in my dataset.
0
Yavor
Telerik team
answered on 11 Feb 2011, 08:02 AM
Hi Mark,

The control fully supports datetime value. You have a number of options to handle the precise setup. More information on this is available in the following article:

http://www.telerik.com/help/silverlight/radchart-features-datetime-support.html

I hope this information gets you started properly. 

Greetings,
Yavor
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Mark Woodlief
Top achievements
Rank 1
answered on 13 Feb 2011, 11:45 PM
I think FULLY is a bit of a stretch, since I've managed to isolate a bug thats been plauging us forever.

Format the XAxis with an Entity Framework Date field.    One that allows null in the Database.. so the DateTime type becomes DateTime? - nullable.. not just DateTime type

Attach that to a telerik grid xaxis and things dont play so nice.. even if you do the standard DateTime.Value, instead of DateTIme

Odd bug, but a bug none the less..
0
Yavor
Telerik team
answered on 17 Feb 2011, 07:56 AM
Hello Mark,

Based on the supplied information, it is hard to determine what is the source of the problem which you mentioned. To properly address the issue, it will be best if you open a formal support ticket, and send us a small working project, demonstrating the problem. We will debug it locally, and advise you further.

Best wishes,
Yavor
the Telerik team
0
siva
Top achievements
Rank 1
answered on 30 Mar 2011, 08:07 AM
How Do I add Axis (X-Axis) Labels Programmatically? Is it possible on silverlight RadChart. It is urgent please assist me. Thanks in advance
0
Yavor
Telerik team
answered on 30 Mar 2011, 09:06 AM
Hi siva,

Basically, once can add tickpoints to the axis. The code may look like this:

private void Button_Click(object sender, RoutedEventArgs e)
{
TickPoint point = new TickPoint();
point.Label = "Manually Added";
RadChart1.DefaultView.ChartArea.AxisX.TickPoints.Add(point);
}

However, this is not the recommended approach - this would simply add a tickpoint, without persisting it, or sizing the axis properly. If one would like to customize the axis, you can toggle off its auto ranging, and set the min and max values, as well as the step.
Another option is to customize the axis labels via a converter. The tipic below elaborates on the matter.

Customizing Axis Labels via a converter
There are cases when the standard format strings for the Chart may fall short in meeting a particular format behavior. In such scenarios, as well as in cases when one wants to have more complete control on a per label basis, one can take the following approach:

1.1. retemplate the AxisLabel2D, which is the type for the labels along both the x and y axis.

<Style       
            TargetType="telerik:AxisLabel2D">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="ItemLabelStyle">
                <Setter.Value>
                    <Style TargetType="TextBlock">
                        <Setter Property="TextAlignment" Value="Center" />
                        <Setter Property="Padding" Value="1" />
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:AxisLabel2D">                       
                        <?SILVERLIGHT BEGIN?>
                        <primitives:LayoutTransformControl x:Name="PART_LayoutTransformControl"                                                  VerticalAlignment="{TemplateBinding VerticalAlignment}"                                                       HorizontalAlignment="{TemplateBinding HorizontalAlignment}">                            <primitives:LayoutTransformControl.Content>
                                <TextBlock Style="{TemplateBinding ItemLabelStyle}"
                                       Text="{Binding Converter={StaticResource DateConverter}}" />                            </primitives:LayoutTransformControl.Content>
                            <primitives:LayoutTransformControl.LayoutTransform>
                                <RotateTransform x:Name="PART_RotateTransform" />
                            </primitives:LayoutTransformControl.LayoutTransform>                        </primitives:LayoutTransformControl>
                        <?SILVERLIGHT END?>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Essentially, the most important piece of the logic here are the TextBlock, and the correlated converter which determines the text which will be rendered at the label(s):

 <TextBlock Style="{TemplateBinding ItemLabelStyle}"
       Text="{Binding Converter={StaticResource DateConverter}}" />                            </primitives:LayoutTransformControl.Content>


1,2. set a DefaultLabelFormat for the axis which will be customized. This default format will be used in the converter, to differentiate between the labels along the x and y axis. This may look something like this:

Chart1.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "CustomYFormat";

1.3. include the actual converter in the code-behind:

public class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string returnValue;
            TickPoint tickPoint = value as TickPoint;
            if ((value as TickPoint).LabelFormat == "CustomYFormat" && (value as TickPoint).Value.ToString().Length>3 )                            {
                returnValue = (value as TickPoint).Value.ToString().Substring(0, 3) + "Custom text";
               }
            else
            {
                returnValue = (value as TickPoint).Value.ToString(); ;
            }                        

            return returnValue;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value as string;
            DateTime resultDateTime;
            if (DateTime.TryParse(strValue, out resultDateTime))
            {
                return resultDateTime;
            }
            return DependencyProperty.UnsetValue;
        }

    }

1.4. Include the converted in the resources section on the page:

  <converter:DateConverter x:Key="DateConverter">           
  </converter:DateConverter>

I hope this information helps.

Kind regards,
Yavor
the Telerik team
0
siva
Top achievements
Rank 1
answered on 30 Mar 2011, 09:14 AM
Thanks for your kind response. I need in a similiar way winform Radchart adding XAxis(0).Textblock.Text = "Abcd" a kind of this

FYI like this

http://www.telerik.com/help/winforms/chart-how-to-add-axis-labels-programmatically.html
0
Yavor
Telerik team
answered on 01 Apr 2011, 09:01 AM
Hello siva,

If you are looking to alter the Silverlight chart labels in a manner similar to the approach for the winforms control, this is possible, however I would recommend that you stick with the previous approach which I elaborated on - it is more flexible, and still gives access to all labels along the axis. On the other hand, the approach for the Silverlight chart is not transferable to the winforms control. As shown in the topic, you can dynamically visit each label, and set the text accordingly. I hope this information helps.

Kind regards,
Yavor
the Telerik team
Tags
Chart
Asked by
siva
Top achievements
Rank 1
Answers by
Mark Woodlief
Top achievements
Rank 1
Yavor
Telerik team
siva
Top achievements
Rank 1
Share this question
or