Rad Chart Y axis remove decimal points

Thread is closed for posting
4 posts, 0 answers
  1. shwetha
    shwetha avatar
    12 posts
    Member since:
    Jul 2008

    Posted 08 Apr 2011 Link to this post

    Hi Telerik Team,

    We are using rad chart for drawing Bar and Line Series graphs.

    Have set the property autoscale=true;
    When the Y axis value is 1 or 2 the Y axis shows decimal points. Need to eliminate the decimal points. Please refer the screen shot.

    As the data will be dymanic, do not want to use the property autoscale = false and set min and max value with steps.
    we did set ValueFormat to Number, but this also ended up showing decimal.

    At any point of time my Y axis should not contain the decimal, as our result data will not have such decimal data.

    Version: 2009.3.1208.35

    Early reply will be appreciated.

    Thanks and regards.
  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 13 Apr 2011 Link to this post

    Hello shwetha,

    There is no way out-of-the-box to control whether the YAxis values should appear if they are decimal or integer.
    However this workaround may be helpful:
    You can use the RadChart1.PlotArea.YAxis.Appearance.ValueFormat to format the value(s) as per your requirements. Additionally, you can use the RadChart1.PlotArea.YAxis.Appearance.CustomFormat property of the axes in the Chart to pass a format string as the Standard Numeric Format Strings.
    The code you should use is similar to this:
    radChart.PlotArea.YAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.Number; 
     //change this with appropriate format string
    radChart.PlotArea.YAxis.Appearance.CustomFormat = "#Y{N0}"; 

    Unfortunately the code above will cause the YAxis to have repeating values (0.2 and 0.4 for example will both be formatted to 0) .
    What I can suggest you to get rid of the repeating YAxis Values is to subscribe to BeforeLayout event of the Chart and by looping through each ChartSeriesItem set Empty String for the TextBlock.Text property of the repeating values. This can be achieved like this:

    void radChart_BeforeLayout(object sender, EventArgs e) 
           for (int i = 0; i < radChart.PlotArea.YAxis.Items.Count - 2; i++ ) 
               if (radChart.PlotArea.YAxis.Items[i].Value == radChart.PlotArea.YAxis.Items[i + 1].Value) 
                   radChart.PlotArea.YAxis.Items[i + 1].TextBlock.Text = " "; 
                   radChart.PlotArea.YAxis.Appearance.MajorTick.Visible = false; 

    As there is no way to loop through MajorTicks of the axes which means that you can either make all of them invisible or nor of them. The code snippet above demonstrates how to turn off visibility for all (marked in yellow).

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

    FISCAL avatar
    2 posts
    Member since:
    Jun 2012

    Posted 17 Jan 2013 Link to this post

    I used a different condition in the if that gave me a similar solution:

    for (int i = 0; i < chart.PlotArea.YAxis.Items.Count; i++)
        int integer = (int)chart.PlotArea.YAxis.Items[i].Value;
        if (chart.PlotArea.YAxis.Items[i].Value - integer > 0)
            chart.PlotArea.YAxis.Items[i].TextBlock.Text = " ";
            chart.PlotArea.YAxis.Appearance.MajorTick.Visible = false;
  4. OMAR
    OMAR avatar
    1 posts
    Member since:
    May 2013

    Posted 28 May 2013 Link to this post

    is a fantastic solution thanks
Back to Top