To reproduce:
DataTable table = new DataTable();
table.Columns.Add("CategoryName");
table.Columns.Add("Sales");
table.Rows.Add("Beverages", 102074.31);
table.Rows.Add("Condiments", 55277.6);
table.Rows.Add("Confections", 80894.14);
table.Rows.Add("Diary Products", 114749.78);
table.Rows.Add("Grains/Cereals", 55948.82);
table.Rows.Add("Meat/Poultry", 81338.06);
table.Rows.Add("Produce", 53019.98);
table.Rows.Add("Seafood", 65544.18);
var result = table.AsEnumerable().Take(5);
this.radChartView1.AreaType = ChartAreaType.Pie;
PieSeries series = new PieSeries();
radChartView1.Series.Add(series);
series.ShowLabels = true;
series.ValueMember = "Sales";
series.DisplayMember = "CategoryName";
series.DataSource = result.ToList();
The last row will produce invalid binding. Here is a valid binding in this scenario:
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using Telerik.WinControls.UI;
namespace Lab.Chart
{
public partial class ChartBindToEnumerableForm : Form
{
private RadChartView chartView = new RadChartView();
public ChartBindToEnumerableForm()
{
InitializeComponent();
chartView.Dock = DockStyle.Fill;
chartView.Parent = this;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
DataTable table = new DataTable();
table.Columns.Add("CategoryName");
table.Columns.Add("Sales");
table.Rows.Add("Beverages", 5);
table.Rows.Add("Condiments", 5);
table.Rows.Add("Confections", 4);
table.Rows.Add("Diary Products", 4);
table.Rows.Add("Grains/Cereals", 23);
table.Rows.Add("Meat/Poultry", 2);
table.Rows.Add("Produce", 1);
table.Rows.Add("Seafood", 3);
var result = table.AsEnumerable().Take(5);
chartView.AreaType = ChartAreaType.Cartesian;
BarSeries series = new BarSeries();
chartView.Series.Add(series);
series.ShowLabels = true;
series.ValueMember = "Sales";
series.CategoryMember = series.DisplayMember = "CategoryName";
//series.DataSource = result.ToList(); WRONG WAY!!!, produce list of DataRows, which related to DataTable, DataView implementation of custom PropertyDescriptoCollection will generated errors and invalid binding for all list binding controls: grid, list, combo, chart, listview
series.DataSource = result.CopyToDataTable();
}
}
}