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

How to round fractional part of labels of BarSeries to thousandths?

6 Answers 48 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 12 Sep 2016, 01:02 PM
Hello. I display labels on BarSeries. Please see the picture in 'BarChartLabels.PNG' file. But as you can see there, sometimes the numerical values of labels are too long and look ugly. How to round fractional part of labels of BarSeries to thousandths for example?

6 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 14 Sep 2016, 10:28 AM
Hello Yaroslav, 

You can set Format property of labels as you can see in our help topic Label Definition. Another option is if you have a template for labels with TextBlock inside to set FormatString property of the Text.

I hope this information helps.

Regards,
Milena
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Dmitry
Top achievements
Rank 1
answered on 19 Sep 2016, 07:18 AM
Thank you, Milena. I'll read about LabelDefinition and try. I bag your pardon I've been sick these days and therefore couldn't reply to you in time.
0
Dmitry
Top achievements
Rank 1
answered on 23 Sep 2016, 09:00 AM
Hello, Milena, please give me an example of both label formatting options, if this is possible ofcourse. Thank you very much in advance.
0
Dmitry
Top achievements
Rank 1
answered on 24 Sep 2016, 08:33 AM
Hello, Milena. I've already solved the problem by the use of your adviced aproach of Label Definition. See below:
<telerik:RadCartesianChart Visibility="{Binding IsComparativeBarChartVisible}">
            <!-- X-axis -->
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:CategoricalAxis/>
            </telerik:RadCartesianChart.HorizontalAxis>
            <!-- Y-axis -->
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis Title="Относительная величина" Minimum="{Binding ComparativeChartMinimum}" Maximum="{Binding ComparativeChartMaximum}"/>
            </telerik:RadCartesianChart.VerticalAxis>
            <!--Bar chart itself-->
            <telerik:RadCartesianChart.Series>
                <telerik:BarSeries ShowLabels="True" CategoryBinding="Category" ValueBinding="Value" ItemsSource="{Binding ComparativeData}">
                    <!--AND FINALLY, HERE I ASSIGN THE FORMAT TO A LABEL-->
                    <telerik:BarSeries.LabelDefinitions>
                        <telerik:ChartSeriesLabelDefinition Format="{} {0:0.###}"/>
                    </telerik:BarSeries.LabelDefinitions>
                </telerik:BarSeries>
            </telerik:RadCartesianChart.Series>
        </telerik:RadCartesianChart>
But you wrote: "...Another option is if you have a template for labels with TextBlock inside to set FormatString property of the Text..". So if this is possible, please give me an example of this aproach.
0
Accepted
Milena
Telerik team
answered on 26 Sep 2016, 03:33 PM
Hello Yaroslav,

I'm glad that you found a solution. The second option I mentioned was in case you are using a template for the labels: 
<telerik:BarSeries.LabelDefinitions>
    <telerik:ChartSeriesLabelDefinition>
        <telerik:ChartSeriesLabelDefinition.Template>
            <DataTemplate>
                <TextBlock Text="{Binding Value, StringFormat={}{0:0.00}}"  />
            </DataTemplate>
        </telerik:ChartSeriesLabelDefinition.Template>
    </telerik:ChartSeriesLabelDefinition>
</telerik:BarSeries.LabelDefinitions>

I hope this information helps.

Regards,
Milena
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Dmitry
Top achievements
Rank 1
answered on 27 Sep 2016, 12:32 PM
Thank you very much for your help and support.
Tags
ChartView
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Milena
Telerik team
Dmitry
Top achievements
Rank 1
Share this question
or