Y-Axis formatter in KB, MB, GB, etc.

5 posts, 0 answers
  1. Tim
    Tim avatar
    169 posts
    Member since:
    Apr 2008

    Posted 24 Jun 2010 Link to this post

    Is there a AxisY.DefaultLabelFormat I can specify to change raw bytes into computer storage (1024=KB, 1024^2=MB, ...) for my y-axis?  For that matter, is there any standard way to do this for generic numeric formatting (for use in RadGridView, say.)

    I'm open to a custom method or IValueConverter or whatever to do the work, as long as I can get the right scale (which I can determine from the min and max Y values in the collection, if nothing else.)

    Thx,
    Tim

  2. Sia
    Admin
    Sia avatar
    745 posts

    Posted 30 Jun 2010 Link to this post

    Hi Tim,

    One possible solution is to set the following in your code behind:
    RadChart1.DefaultView.ChartArea.AxisX.AutoRange = false;
    //Set Min, Max and Step for the AxisX
    RadChart1.DefaultView.ChartArea.AxisX.AddRange(-1024, 10240, 1024);
     
    RadChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "0,KB";

    In that way you will achieve "0KB, 1KB, 2KB, ...10KB" labels. Having KB and MB at the same time on your Axis is not possible.

    Please excuse us for the inconvenience caused.

    All the best,
    Sia
    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. Tim
    Tim avatar
    169 posts
    Member since:
    Apr 2008

    Posted 30 Jun 2010 Link to this post

    I'll give that a try, thanks.  What about if I used a logarithmic axis?  Then I might get 1KB, 10KB, 100KB, 1MB, 10MB, ... which would be nice if the range is big enough.

    So far, I've been able to get 0.00GB, 0.01GB, 0.10GB, 1.0GB, 10GB, 100GB, etc.  BUT below 1.00GB the bars point down (with AutoRange=true)


    Tim

  4. Sia
    Admin
    Sia avatar
    745 posts

    Posted 02 Jul 2010 Link to this post

    Hi Tim,

    Yes, you can use logarithmic scale in your scenario. Just set
    RadChart1.DefaultView.ChartArea.AxisY.IsLogarithmic = true;
    and you will see the bars from the screenshot2.jpg. You can compare it with the default look from the screenshot1.jpg.

    Here you can see how to format your items' labels also:
    DataSeries series1 = new DataSeries()
    {
       new DataPoint(1024),
       new DataPoint(10240),
       new DataPoint(102400),
       new DataPoint(1024000)
    };
    series1.Definition = new BarSeriesDefinition();
    series1.Definition.ItemLabelFormat = "0,KB";
     
    RadChart1.DefaultView.ChartArea.AxisY.IsLogarithmic = true;
     
    RadChart1.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "0,KB";
     
    RadChart1.DefaultView.ChartArea.DataSeries.Add(series1);

    If you need somethings else, do not hesitate to contact us again.

    Greetings,
    Sia
    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
  5. Sia
    Admin
    Sia avatar
    745 posts

    Posted 02 Jul 2010 Link to this post

    Hi Tim,

    Just a quick followup.

    In your case your step is 1024, but the ItemLabelFormat supports only the standard .NET formats. That is why all values are devided in 1000.

    So, unfortunately, this approach would not be applicable for bar labels as  the formatted values differ from the true values.

    All the best,
    Sia
    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