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

Rad Chart Y axis remove decimal points

3 Answers 632 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
shwetha
Top achievements
Rank 1
shwetha asked on 08 Apr 2011, 11:59 AM
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.

3 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 13 Apr 2011, 08:21 AM
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,
Evgenia
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.

0
FISCAL
Top achievements
Rank 1
answered on 17 Jan 2013, 06:48 PM
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;
    }
}
0
OMAR
Top achievements
Rank 1
answered on 28 May 2013, 10:28 PM
is a fantastic solution thanks
Tags
Chart (Obsolete)
Asked by
shwetha
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
FISCAL
Top achievements
Rank 1
OMAR
Top achievements
Rank 1
Share this question
or