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

7 posts, 1 answers
  1. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 12 Sep Link to this post

    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?
  2. Milena
    Admin
    Milena avatar
    204 posts

    Posted 14 Sep Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 19 Sep in reply to Milena Link to this post

    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.
  5. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 23 Sep in reply to Yaroslav Link to this post

    Hello, Milena, please give me an example of both label formatting options, if this is possible ofcourse. Thank you very much in advance.
  6. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 24 Sep Link to this post

    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.
  7. Answer
    Milena
    Admin
    Milena avatar
    204 posts

    Posted 26 Sep Link to this post

    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.
  8. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 27 Sep in reply to Milena Link to this post

    Thank you very much for your help and support.
Back to Top
UI for WPF is Visual Studio 2017 Ready