Display Series Name & Value in the Bar for a Bar Chart

Thread is closed for posting
4 posts, 0 answers
  1. Vamsi Pulavarthi
    Vamsi Pulavarthi avatar
    2 posts
    Member since:
    Jun 2005

    Posted 17 Jun 2012 Link to this post

    Hello -
    I am trying to display information in a Horizontal Bar chart. The Y axis information is a list of series that we care about. The names of the series are quite long as you will see from the screen shot.

    I would like to display the Series Name along with the value where the actual value is currently displaying. Is that possible. If yes, can someone tell me how to do that?

    Also is it possible to make the Chart move a little to the right and make sure the Legend space is utilized by the chart. Sometime I don't need a legend and would like to use that space instead.

    thanks
    Vamsi

    In the picture, I would like to replace '38' with 'Determine ... Decision - 38'
  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 20 Jun 2012 Link to this post

    Hello Vamsi,

    You can achieve this as shown in the sample below:

    protected void Page_Load(object sender, EventArgs e)
       {
           List<Product> products = new List<Product>();
           products.Add(new Product("Parka L", 120));
           products.Add(new Product("Parka M", 100));
           products.Add(new Product("Parka S", 132));
           products.Add(new Product("Wool Cap", 45));
           products.Add(new Product("Mittens", 67));
           ChartSeries serie = new ChartSeries();
           serie.Type = ChartSeriesType.Bar;
           foreach (Product product in products)
           {
               ChartSeriesItem item = new ChartSeriesItem();
               item.YValue = (double)product.QuantityInStock;
               item.Name = (string)product.Name;
               item.Label.TextBlock.Text = (string)product.Name + " - #Y";
               serie.Items.Add(item);
           }
           RadChart1.Series.Add(serie);
       }
       public class Product
       {
           public Product(string name, int quantityInStock)
           {
               _name = name;
               _quantityInStock = quantityInStock;
           }
           private string _name;
           public string Name
           {
               get { return _name; }
               set { _name = value; }
           }
           private int _quantityInStock;
           public int QuantityInStock
           {
               get { return _quantityInStock; }
               set { _quantityInStock = value; }
           }
       }

    As to your second questions - turn on the AutoLayout property of the chart as it will automatically rearrange chart elements to be fully readable.

    Regards,
    Evgenia
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vamsi Pulavarthi
    Vamsi Pulavarthi avatar
    2 posts
    Member since:
    Jun 2005

    Posted 20 Jun 2012 Link to this post

    Thank You for your respnose Evgenia.

    I finally did figure out last night how to do it. But I did it in a slightly different way.
    Do you know of any pit falls of doing it this way?

    Protected Sub decisionChart_ItemDataBound(sender As Object, e As Telerik.Charting.ChartItemDataBoundEventArgs) Handles decisionChart.ItemDataBound

            decisionChart.Legend.Visible = False
            e.SeriesItem.Name = CType(e.DataItem, DataRowView)("DecisionName").ToString()
            For Each item In decisionChart.Series(0).Items
                item.Label.Appearance.LabelLocation = Telerik.Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Inside
                Dim str1 As String = item.Name()
                str1 = item.YValue & " - " & str1
                item.Label.TextBlock.Text = str1
                'item.YValue = str1
            Next

        End Sub


    thanks
    Vamsi
  5. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 21 Jun 2012 Link to this post

    Hello Vamsi,

     I'm glad that you managed to do this on your own. The approach you used is absolutely valid and it is up to you to pick up which one is more suitable for you.

    All the best,
    Evgenia
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top