AutoRange issue with LinearAxis

9 posts, 0 answers
  1. Timo
    Timo avatar
    7 posts
    Member since:
    Oct 2010

    Posted 08 Dec 2011 Link to this post

    Hi,

    I have a chart with a horizontal DateTimeContinuousAxis and a vertical LinearAxis.
    <telerik:RadCartesianChart Background="red" x:Name="chart" MinWidth="400" MinHeight="300" >
              <telerik:RadCartesianChart.Behaviors>
                       <telerik:ChartPanAndZoomBehavior PanMode="Both" ZoomMode="Both"/>
              </telerik:RadCartesianChart.Behaviors>
              <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:DateTimeContinuousAxis LabelInterval="1" MajorStepUnit="Minute" LabelFitMode="None"    PlotMode="OnTicks" LastLabelVisibility="Hidden">
                   </telerik:DateTimeContinuousAxis>
                    </telerik:RadCartesianChart.HorizontalAxis>
               <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis />
               </telerik:RadCartesianChart.VerticalAxis>
    </telerik:RadCartesianChart>

    If I have the following code, the vertical axis will auto arrange itself.

    var items = new List<Vm>();
     var data = new DateTime(2011, 12, 1);
     for (int i = 0; i < 12; i++)
          {
              double? val = (i % 4) + 10;
              if (val == 10)
                   val = null;
               items.Add(new Vm { Date = data.AddDays(i), Value = val});
           }
      var rz = items.Where(ee => ee.Value.HasValue).ToList();
      this.chart.Series[0].ItemsSource = rz;
      (chart.HorizontalAxis as DateTimeContinuousAxis).Maximum = new DateTime(2011, 12, 15);
      (chart.HorizontalAxis as DateTimeContinuousAxis).Minimum = new DateTime(2011, 12, 1).AddDays(1);
     
    public class Vm
       {
           public DateTime Date { get; set; }
           public double? Value { get; set; }
       }


    But if I change to the following

    var items = new List<Vm>();
    var data = new DateTime(2011, 12, 1);
    for (int i = 0; i < 12; i++)
    {
        double? val = (i % 4) + 10;
        //if (val == 10)
        //    val = null;
        items.Add(new Vm { Date = data.AddDays(i), Value = val});
    }
    var rz = items.Where(ee => ee.Value.HasValue).ToList();
    this.chart.Series[0].ItemsSource = rz;
    (chart.HorizontalAxis as DateTimeContinuousAxis).Maximum = new DateTime(2011, 12, 15);
    (chart.HorizontalAxis as DateTimeContinuousAxis).Minimum = new DateTime(2011, 12, 1).AddDays(1);

    the vertical axis will no longer arrange itself to the minimum of the series, but the minimum will become 0.

    All I want is to display a chart from moment A to B, and the points in A and B to be displayed right to the start and right to the end of the chart ( no space before first point - that's why I have set PlotMode on horizontal Axis to "OnTicks") and the linearAxis to auto arrange itself without computing minimum and maximum of it.
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 12 Dec 2011 Link to this post

    Hi Timo,

    The automatic axis range calculation in RadChartView mimics the behavior of MS Excel -- see this KB article here ("If the difference between yMax and yMin is greater than 16.667 percent of the value of yMax, the automatic minimum for the y-axis is zero.").

    However, you can manually tweak this behavior by setting the LinearAxis.RangeExtendDirection property to NumericalAxisRangeExtendDirection.None or NumericalAxisRangeExtendDirection.Positive.

    Hope this helps.


    Greetings,
    Giuseppe
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Sebastian
    Sebastian avatar
    4 posts
    Member since:
    Dec 2011

    Posted 04 Jan 2012 Link to this post

    Hi,

    I am also having the same problem but with the DateTimeCategoricalAxis. I want values of 0 to start in the chart from 0,0 coordinate.
    However i don´t seem too find the LinearAxis.RangeExtendDirection on the DateTimeCategoricalAxis.

    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:DateTimeCategoricalAxis DateTimeComponent="Millisecond" />
    </telerik:RadCartesianChart.HorizontalAxis>

    Any input on this?

    //Sebastian
  5. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 09 Jan 2012 Link to this post

    Hello Sebastian,

    You cannot extend the range (neither set the range manually) for a CategoricalAxis / DateTimeCategoricalAxis as this axis type represents discrete values (categories) that should be user-defined.

    Could you elaborate a bit more on the "I want values of 0 to start in the chart from 0,0 coordinate" requirement in the context of DateTime axis?


    Kind regards,
    Giuseppe
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Sebastian
    Sebastian avatar
    4 posts
    Member since:
    Dec 2011

    Posted 16 Jan 2012 Link to this post

    Hi Giuseppe,

    What i mean is that i would like to remove the space between the Y-axis and the 0-point on the X-axis. I have attached a picture illustrating the space that i want to remove. Hope this makes my explanation clearer.

    Regards,
    Sebastian
  7. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 19 Jan 2012 Link to this post

    Hello Sebastian,

    Provided that your Y-axis (the vertical one) is linear, you should be able to modify its LinearAxis.RangeExtendDirection property and not any property on the DateTimeCategoricalAxis (the horizontal one).


    Regards,
    Giuseppe
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Sebastian
    Sebastian avatar
    4 posts
    Member since:
    Dec 2011

    Posted 19 Jan 2012 Link to this post

    Hi Giuseppe,

    I have tried all the different types of RangeExtendDirections. However i am not getting rid of the gap between my Y-axis (the vertical one) and the 0-value on my X-axis.

    I am grateful for the help so far. I have pasted my code if that will help.
    <telerik:RadCartesianChart x:Name="radc" Height="200" Background="Green" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
               <telerik:RadCartesianChart.Behaviors>
                   <telerik:ChartTrackBallBehavior ShowIntersectionPoints="True"
                                            ShowTrackInfo="True" SnapMode="None"/>
               </telerik:RadCartesianChart.Behaviors>
               <telerik:RadCartesianChart.VerticalAxis>
                   <telerik:LinearAxis ShowLabels="True" RangeExtendDirection="None" Visibility="Visible"/>
               </telerik:RadCartesianChart.VerticalAxis>
               <telerik:RadCartesianChart.HorizontalAxis>                
                   <telerik:DateTimeCategoricalAxis DateTimeComponent="Millisecond" HorizontalContentAlignment="Stretch"/>
               </telerik:RadCartesianChart.HorizontalAxis>
               <telerik:LineSeries Stroke="Orange" StrokeThickness="2" CategoryBinding="When" ValueBinding="VitalValue" ItemsSource="{Binding FakeVitals}">
                   <telerik:LineSeries.PointTemplate>
                       <DataTemplate>
                           <Ellipse Width="4" Height="4" Fill="Aquamarine"></Ellipse>
                       </DataTemplate>
                   </telerik:LineSeries.PointTemplate>
                   <telerik:LineSeries.TrackBallTemplate>
                       <DataTemplate>
                           <Rectangle Width="20"
                          Height="20"
                          Fill="Violet"
                          RenderTransformOrigin="0.5,0.5">
                               <Rectangle.RenderTransform>
                                   <RotateTransform Angle="45"/>
                               </Rectangle.RenderTransform>
                           </Rectangle>
                       </DataTemplate>
                   </telerik:LineSeries.TrackBallTemplate>
               </telerik:LineSeries>
     
               <telerik:LineSeries Stroke="Chocolate" StrokeThickness="2" CategoryBinding="When" ValueBinding="VitalValue" ItemsSource="{Binding FakeVitals2}" />
           </telerik:RadCartesianChart>

    Regards,
    Sebastian
  9. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 24 Jan 2012 Link to this post

    Hi Sebastian,

    You can set the PlotMode property of the DateTimeCategoricalAxis to AxisPlotMode.OnTicks. This will place the labels right under their corresponding ticks and not between the ticks, as shown in this example.

    Best regards,
    Ves
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Sebastian
    Sebastian avatar
    4 posts
    Member since:
    Dec 2011

    Posted 22 Feb 2012 Link to this post

    Hi Ves,

    Sorry for the late answer.
    Yes that seemed to fix it now the lineseries starts from the 0,0 position in the Chart.

    Thanks,
    Sebastian
Back to Top
DevCraft banner