This is a migrated thread and some comments may be shown as answers.
Label formatstring for a BarSeries of doubles
6 Answers 225 Views
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 18 Jun 2012, 12:51 PM
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

6 Answers, 1 is accepted

Sort by
0
Rahul
Top achievements
Rank 2
answered on 20 Jun 2012, 03:55 PM
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
0
Mark
Top achievements
Rank 1
answered on 26 Jun 2012, 06:08 AM
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
0
Evgenia
Telerik team
answered on 28 Jun 2012, 01:04 PM
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 >>
0
Goran
Top achievements
Rank 1
answered on 16 Feb 2013, 11:42 PM
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
0
Evgenia
Telerik team
answered on 21 Feb 2013, 08:10 AM
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.

0
Heath Morris
Top achievements
Rank 1
answered on 15 Mar 2013, 08:24 PM

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

Tags
Chart
Asked by
Mark
Top achievements
Rank 1
Answers by
Rahul
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Evgenia
Telerik team
Goran
Top achievements
Rank 1
Heath Morris
Top achievements
Rank 1
Share this question
or