Binding list to

Thread is closed for posting
6 posts, 1 answers
  1. Ram
    Ram avatar
    8 posts
    Member since:
    Jul 2013

    Posted 22 Aug 2013 Link to this post

    Hi all

    I have a list collection and want to bind this to a Radchart programmatically ie in the code-behind at the click of a button.

    The Radchart needs to display all the items in the collection, do I need to loop through the list then bind?

    I couldn't find any example where this is done programmatically.

    Ram
  2. Peshito
    Admin
    Peshito avatar
    496 posts

    Posted 27 Aug 2013 Link to this post

    Hello,

    Please take a look at our online help topic describing how to bind RadChart to a generic list of objects.

    Regards,
    Peshito
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ram
    Ram avatar
    8 posts
    Member since:
    Jul 2013

    Posted 27 Aug 2013 Link to this post

    Hi Poshito

    Thanks for your reply below but this doesn't help me I want to be able to loop through a list and add "Multiple Series" the example below
    is for one series.

    I have a list through which I need to loop and add a series for each item in the collection something like below with items and values being added from a list<> programmatically.

    http://www.telerik.com/help/aspnet-ajax/chart-building-programmatic-create-complex.html

    Kind Regards,
    Ram
  5. Peshito
    Admin
    Peshito avatar
    496 posts

    Posted 30 Aug 2013 Link to this post

    Hello,

    Please find attached sample demonstrating a multiple series chart using a single data source. You can also use Grouping later in order to further customize the chart.

    Regards,
    Peshito
    Telerik
    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 the blog feed now.
  6. Ram
    Ram avatar
    8 posts
    Member since:
    Jul 2013

    Posted 30 Aug 2013 Link to this post

    Hi Poshito

    Many thanks for your replies which have been really helpful, I am nearly there with my chart.

    Currently I am able to add multiple series to a chart but my plotting isn't working correctly - please see attached screenshot.

    The first item in the series is correct with an average of 6 but the second item should start from 0 and have the lightBlue colour.

    I am going wrong somewhere in my code below - please help.
    testing.PlotArea.XAxis.DataLabelsColumn = "year";
     testing.DefaultType = Telerik.Charting.ChartSeriesType.Line;
     testing.ChartTitle.TextBlock.Text = "Yearly Chart";
     
     testing.DataGroupColumn = "product";
     testing.Legend.Appearance.GroupNameFormat = "product:year";
     
     testing.DataSource = YearlyAverage;
     int lcount = YearlyAverage.Count();
     string name = ""; string product = "";
     Telerik.Charting.ChartSeries chart = new Telerik.Charting.ChartSeries();
     Telerik.Charting.ChartSeriesItem charttype = new Telerik.Charting.ChartSeriesItem();
     
      #region loop through list
      for (int i = 0; i < YearlyAverage.Count; i++)
      {
          string x = YearlyAverage[i].FromDateAverage.Date.Year.ToString();
          name = YearlyAverage[i].Product + " " + YearlyAverage[i].ProductStrength + " " + YearlyAverage[i].Pack_Size;
          string n = "John" + i;
          chart.Name = n;// name;
          decimal v = YearlyAverage[i].Average;
          double d = double.Parse(v.ToString());
          chart.Type = Telerik.Charting.ChartSeriesType.Line;
           
          chart.AddItem(double.Parse(v.ToString()));
         // chart.AddItem(double.Parse(v.ToString()), name);
          product = YearlyAverage[i].Product.ToString();
     
          testing.Series.Add(chart);
         // testing.Chart.Series.Add(chart);
         //testing.AddChartSeries(chart);
         //chart.PlotArea.XAxis.DataLabelsColumn = product;
         //  chart.PlotArea.XAxis.DataLabelsColumn = YearlyAverage[i].Product;
      }
      #endregion
      
     // testing.Series.Add(chart);
      testing.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font = new System.Drawing.Font("Arial", 8);
      testing.Height = 1200;
      testing.Width = 1090;
      testing.DataBind();
  7. Answer
    Peshito
    Admin
    Peshito avatar
    496 posts

    Posted 04 Sep 2013 Link to this post

    Hi Ram,

    From the code provided it is not clear enough why do you experience such a behavior. You said that the second item should start from 0, however where does it end? Could you please provide the running sample project so I could debug it and provide you with an appropriate solution. As this is a forum thread and you cannot attach files to it, please use a third party web site for upload and share.

    Regards,
    Peshito
    Telerik
    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 the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017