Set LabelStep Dynamically

Thread is closed for posting
11 posts, 0 answers
  1. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2008

    Posted 26 Mar 2009 Link to this post

    I would like to dynamically set the labelstep value based on how many Yaxis and Xaxis values might be on the chart.  The number of X and Y labels can vary depending on user inputs.  On the x-axis we might be looking at monthly values across a year (12 labels) or hourly vlaues across 3 days (72 labels).  There are many other possibilites.  The Y Laebls can also vary in range.

    I am using the DataBind method, so I am not adding the X and Y values manually.

    I need a way of find out out how many labels are present on each axis so I can dymanically set the labelstep value.  For Example, if there are 12 x-axis labels then I want the labelstep for the X axis to be 1.  If there are 300 then I want it to be 300/30 (or whatever).

    It seems like this must be easy, but I am missing something.

    Thanks,

    Mike
  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 27 Mar 2009 Link to this post

    Hi Michael,

    You can easily obtain the current number of labels generated on each axis through the radChart1.PlotArea.XAxis.Items.Count and .Yaxis.Items.Count properties. That number, however, depends on the LabelStep property as only the required number of labels are generated.

    To aquire the correct number of data points, you just need to retrieve it from  this.radChart1.Series[0].Items.Count. This will solve the problem for X axis, but I am not sure what you need as information on the Y axis. Usually, the Y axis automatically scales itself, searching for the optimum number of labels and optimum range to correctly represent the given range.

    All the best,
    Evtim
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2008

    Posted 06 Apr 2009 Link to this post

    Hi,

    The x-axis is solved, but the Y axis is still a problem.  I did try setting AutoScale to "true" for the Y Axis, but that is not working.

    I am thinking that the following would work:

    1. Let's assume that I want no more than 60 labels on the axis.
    2. Set the Y labelstep to 1.
    3. Find the max and min Y values by looping though each series, and subtract the min from the max.  This would give me the total number of labels on the Y axis if the labelstep were 1.
    4. Take that number and divide by 60 (our max label setting)
    5. So lets say the min is 0 and the max is 300.  Then we do (300-0)/60 = 5.  We now set labelstep for the Y axis to 5.

    So, my questions are as follows:

    1. Is this the best approach?
    2. How can I get the max and min values for any given series?
  5. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 07 Apr 2009 Link to this post

    Hello Michael,

    Currently, the RadChart does not expose API for retrieving the Min/Max values from the series. So, I would say your approach is correct.

    I suggest setting the steps on the DataBound event (if you use data binding). That will ensure the data is initialized.

    Regards,
    Evtim
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  6. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2008

    Posted 08 Apr 2009 Link to this post

    When I said I would, "Find the max and min Y values by looping though each series," I was assuming that there was some means of finding the max/min on the series.  I was not intending on looping the items in each series.

    In an earlier reply you said, "Usually, the Y axis automatically scales itself, searching for the optimum number of labels and optimum range to correctly represent the given range."  How can I get this to happen?  It sounds as if you are describing an "automated" labelstep value.  What might I be missing?
  7. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2008

    Posted 09 Apr 2009 Link to this post

    The reason why AutoScale failed for me was that I was allowing for scale breaks (and there were two in my test data).  Is it true that Scale Breaks *break* the AutoScale feature?
  8. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 10 Apr 2009 Link to this post

    Hi Michael,

    Yes, you are correct, the RadChart does not allow using AutoScale and Scale breaks together.

    Best,
    Evtim
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  9. kevin yang
    kevin yang avatar
    15 posts
    Member since:
    Dec 2009

    Posted 07 Jan 2010 Link to this post

    I want to display the serie item label above of the bar
    I have AxisMode set to Extended,  it display fine even when largest  Y-Axis  bar is almost full ( since mode is extened )
    But when I set ScaleBreaks to true,  the  AxisMode = Extended does not seem to work,  my item label is displaying in the bar and was covered partially by the scalebreak curve line.

    What's the way to achieve what I want to do?
    Please help.
    Thanks

  10. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 13 Jan 2010 Link to this post

    Hi Kevin,

    With AutoScale set to true the algorithm usually manages to produce the axis segments so that there is enough space above the largest bar. If AutoScale is set to false you can add AxisSegment objects to YAxis.ScaleBrakes.Segments collection manually, providing the desired configuration for MinValue, MaxValue and Step.

    Best regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Sunitha
    Sunitha avatar
    3 posts
    Member since:
    Sep 2012

    Posted 20 Jun 2011 Link to this post

    I Have got a similiar problem. I have formatted the xasis as ChartValueFormat.LongTime. But i need to apply a maximum X value as 00:30:00. But Xaxis Max value can set in only as Double/Integres. How can I set the max Xaxis valu as time

     

     

    For i = 0 To dtcolumn.Tables(1).Rows.Count - 1

     

     

    For k = 0 To dt.Rows.Count - 1

     

     

    If (dtcolumn.Tables(1).Rows(i)("mintime")) = (dt.Rows(k)("time")) Then

     

     

     

     

     

    dt.Rows(k)(cumul) = Math.Round(dtcolumn.Tables(1).Rows(i)(

    "cumulative"), 2)

     

     

    ' RadChart1.Series(1).AddItem(dt.Rows(k)(cumul))

     

     

     

     

     

     

    End If

     

     

     

     

     

     

    Next

     

     

     

     

     

     

    Next

     

     

     

     

     

    RadChart1.Series(0).DataYColumn =

    "incs"

     

     

     

     

     

    RadChart1.Series(1).DataYColumn =

    "cumula"

     

     

     

     

     

    RadChart1.Series(1).Appearance.FillStyle.MainColor = Drawing.Color.Red

     

    ' 'RadChart1.PlotArea.XAxis.DataLabelsColumn = "time"

     

     

     

     

     

     

    For i = 0 To dt.Rows.Count - 1

     

    RadChart1.PlotArea.XAxis.AddItem(

    CDate(dt.Rows(i)("time")))

     

     

    'RadChart1.Series().

     

     

     

     

     

     

    Next

     

     

     

     

     

     

     

    ' RadChart1.PlotArea.XAxis.MaxValue = 60

     

     

     

     

     

     

    'RadChart1.PlotArea.XAxis.MinValue = 0

     

     

     

     

     

    RadChart1.PlotArea.XAxis.Appearance.ValueFormat = Styles.ChartValueFormat.LongTime

     

    'RadChart1.PlotArea.XAxis.Appearance.CustomFormat = "hh:mm:ss"

     

     

     

     

     

    RadChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.Black

     

     

     

     

    RadChart1.PlotArea.XAxis.LabelStep = 5

     

    RadChart1.PlotArea.XAxis.AutoScale =

    False

    MAny thanks in Advance

     

  12. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 22 Jun 2011 Link to this post

    Hello Sunitha,

    When configuring the X axis manually for DateTime values, you need to use their OLEAutomation equivalents. You can use the DateTime.ToOADate method for this purpose. You can find such example here.

    Regards,
    Ves
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017