Label formatstring for a BarSeries of doubles

7 posts, 0 answers
  1. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 18 Jun 2012 Link to this post

    How do I set a format string for a label on a bar series of doubles? e.g. "0.0"

    I've looked at the demos and in these forums and can't find anything
  2. Rahul
    Rahul avatar
    116 posts
    Member since:
    Feb 2011

    Posted 20 Jun 2012 Link to this post

    Hi Liam,

                You can set label format for Bar Series like this:

    seriesMapping.SeriesDefinition.ItemLabelFormat = "#Y{0.0}%";

    You refer below link for more information on label formats.

    http://www.telerik.com/help/silverlight/radchart-features-format-expressions.html



    Thanks & Regards
    Rahul
  3. DevCraft banner
  4. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 26 Jun 2012 Link to this post

    sorry missed a key piece of information from the post

    this is for the ChartView and not RadChart

    the help you have posted doesn't correlate to anything I can find in regards to ChartView
  5. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 28 Jun 2012 Link to this post

    Hello Liam,

     You can achieve this with RadChartView like this:

    <telerik:BarSeries.LabelDefinitions>
                <telerik:ChartSeriesLabelDefinition HorizontalAlignment="Center" Format="{} {0:F1}"/>
    </telerik:BarSeries.LabelDefinitions>

    All the best,
    Evgenia
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. Goran
    Goran avatar
    77 posts
    Member since:
    Feb 2011

    Posted 16 Feb 2013 Link to this post

    Hi Evgenia,

    I have the same requirement, but with addition that user can configure in application properties the number of decimals that chart will display. Since Format is not dependency property, we cannot bind it to a property. How can I achieve this, assuming that, for example, I have this property in ViewModel:

    public string NumberFormat
    {
        get { return "{} {0:F" + ApplicationConfiguration.NumberOfDecimals + "}"; }
    }

    Regards,
    Goran
  7. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 21 Feb 2013 Link to this post

    Hi Goran,

     You can achieve this the same way it was done for AxisXLabelFormat and AxisYLabelFormat in this online example with source code. The properties are registered in the ViewModel as follows:

    private string _axisXLabelFormat;
    private string _axisYLabelFormat;
      
    public string AxisXLabelFormat
            {
                get
                {
                    return this._axisXLabelFormat;
                }
                set
                {
                    if (this._axisXLabelFormat != value)
                    {
                        this._axisXLabelFormat = value;
                        this.OnPropertyChanged("AxisXLabelFormat");
                    }
                }
            }
      
            public string AxisYLabelFormat
            {
                get
                {
                    return this._axisYLabelFormat;
                }
                set
                {
                    if (this._axisYLabelFormat != value)
                    {
                        this._axisYLabelFormat = value;
                        this.OnPropertyChanged("AxisYLabelFormat");
                    }
                }
            }

    They are set in the DisplayLine() method in ExampleViewModel.cs and bound to their corresponding chart properties in xaml.

    I hope this information helps.

    Regards,
    Evgenia
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Heath Morris
    Heath Morris avatar
    1 posts
    Member since:
    Aug 2009

    Posted 15 Mar 2013 Link to this post

    Goran's example did not work for me, but i figured it out. I just needed to remove the first set of brackets {} from the string and the then it was fine.

    ChartSeriesLabelDefinition
    labelDefinition = new ChartSeriesLabelDefinition();

    labelDefinition.Binding = new PropertyNameDataPointBinding() { PropertyName = "Y" };

    labelDefinition.Format = "{0:N1}"; // {0:N1} == "0.0"

     

    BarSeries barSeries = new BarSeries();

    barSeries.ShowLabels = true;

    barSeries.LabelDefinitions.Add(labelDefinition);


    Here are some useful links for numeric formatting.

    string.Formats for regular numbers
    http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

    string.Formats for custom numbers
    http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

    string.Formats Thousands=K Millions=M Billions=B etc.
    http://stackoverflow.com/questions/11731996/string-format-numbers-thousands-123k-millions-123m-billions-123b

    Regards,

    Heath Morris

Back to Top
DevCraft banner