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

[Solved] RadCartesianChart Y axis label displaying exponential value

2 Answers 316 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
bachi
Top achievements
Rank 1
bachi asked on 27 Apr 2014, 02:37 PM
Hi Telerik Team,

I am facing a issues with RadCartesianChart control and was trying for a week to fix this issue, the Y axis value which is auto calculated based on the X axis value is showing exponential value for large range value. As per my requirement I should display the value without the exponential, need your help in overcoming this issue.

Below is my XAML code and attaching you the error screenshot for your reference

XAML:
<telerik:RadCartesianChart x:Name="MyChartRangeIssue" Grid.Row="1" Margin="180,49,62,210" PaletteName="DefaultDark" Width="700" Height="500">
  <telerik:RadCartesianChart.HorizontalAxis> <telerik:CategoricalAxis/> </telerik:RadCartesianChart.HorizontalAxis>
<telerik:RadCartesianChart.VerticalAxis> <telerik:LinearAxis/> </telerik:RadCartesianChart.VerticalAxis>
</telerik:RadCartesianChart>

XAML.CS:
var series = new BarSeries();
series.ShowLabels = true;
 series.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Cluster;
series.CategoryBinding = new PropertyNameDataPointBinding("Category");
series.ValueBinding = new PropertyNameDataPointBinding("Value");

var itemSources = new List<object>();

itemSources.Add(new Data9 { Category = "AAAAA", Value = 42217612.77 });
itemSources.Add(new Data9 { Category = "BBBBB", Value = 15504891.06 });
itemSources.Add(new Data9 { Category = "CCCCC", Value = 6915841.52 });
itemSources.Add(new Data9 { Category = "DDDDD", Value = 8421990.89 });
itemSources.Add(new Data9 { Category = "EEEEE", Value = 3608019.22 });
itemSources.Add(new Data9 { Category = "GGGGG", Value = 7975391.48 });


series.ItemsSource = itemSources;
MyChartRangeIssue.Series.Add(series);

public class Data9
{
public string Category { get; set; }

public double Value { get; set; }


}


Thanks,
Bachi

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosy Topchiyska
Telerik team
answered on 28 Apr 2014, 09:52 AM

Hello,

Thank you for the question.

There are two ways to customize the axis labels:

  1. With the LabelFormat property:
    <telerik:LinearAxis LabelFormat="{}{0:N}"/>

    Here you can see the possible format strings: Standard Numeric Format Strings

  2. Using the LabelTemplate property:
    <telerik:LinearAxis>
        <telerik:LinearAxis.LabelTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Converter={StaticResource Converter}}" Margin="5"/>
            </DataTemplate>
        </telerik:LinearAxis.LabelTemplate>
    </telerik:LinearAxis>

    Here is an example of a value converter that gets the value without the exponent part:

    public class Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            return double.Parse(value.ToString()) / 10000000;
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }

I hope this helps. Please, let us know if you have further questions.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
bachi
Top achievements
Rank 1
answered on 29 Apr 2014, 07:38 PM
Hi Rosy Topchiyska,

Thank you very much for your help here.

Your solution was very much helpful, made couple of changes to get the results which is was looking for

1. Removed the divided by operation from the Converter class, its showing decimal values for the value range less than 10000000

2.  Removed the typecast double.Parse and just returning the string value.

Thank you once again for your quick response


Best Wishes,
Bachi

Tags
Chart for XAML
Asked by
bachi
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
bachi
Top achievements
Rank 1
Share this question
or