This is a migrated thread and some comments may be shown as answers.

Binding list to

5 Answers 47 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 22 Aug 2013, 08:04 AM
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

5 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 27 Aug 2013, 06:15 AM
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.
0
Ram
Top achievements
Rank 1
answered on 27 Aug 2013, 08:25 AM
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
0
Peshito
Telerik team
answered on 30 Aug 2013, 07:13 AM
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.
0
Ram
Top achievements
Rank 1
answered on 30 Aug 2013, 10:03 AM
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();
0
Accepted
Peshito
Telerik team
answered on 04 Sep 2013, 06:08 AM
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.
Tags
Chart (Obsolete)
Asked by
Ram
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Ram
Top achievements
Rank 1
Share this question
or