How to bind multiple column RadChart

2 posts, 1 answers
  1. Projects Computerra
    Projects Computerra avatar
    31 posts
    Member since:
    Aug 2009

    Posted 05 Oct 2009 Link to this post


    Please refer uploaded images. SampleData is the datatable which I am binding with the control. TelerikReport.jpg is shows my program result(for which I have doubt). CrystalReport.jpg displays my needed result(I have made this chart using crystal report).

    Now, let me describe my doubt. I want to display category on x-axis and incidents on y-axis. I want to display multiple category on x-axis with different colors and its incidents on y-axis(want grouping of category on x-axis and want to display incidents on y-axis same like crystalreport.jpg).

    See my code,
    RadChart1.DataSource = dt  
    RadChart1.DataGroupColumn = "Month" 
    RadChart1.PlotArea.XAxis.DataLabelsColumn = "Category" 

    I think I am missing something in code. Please guide me.
  2. Answer
    Dwight avatar
    475 posts

    Posted 06 Oct 2009 Link to this post


    The RadChart for WinForms does not allow string values for the X axis. In order to achieve the required functionality, you need to add unique numeric (double, int, etc.) value for each category, as additional data to each row.

    In the following example, I have created a method Extend, to which you need to pass the DataTable, the category column and a name for the new numeric column. This method extracts the unique values from the category column and fills in the new numeric column with respective values. Once this is done, through the DataManager specify this column to be used for the X Values. Also, specify which columns are to be used for the generation of series (ValueYColumns). Here is the sample:
    public partial class Form1 : Form 
        public Form1() 
            DataTable table = MyDataSource.Create(); ; 
            MyDataSource.Extend(table, "Category""CategoryNum"); 
            this.radChart1.DataSource = table; 
            this.radChart1.DataGroupColumn = "Month"
            this.radChart1.DataManager.ValuesYColumns = new string[] { "Incident" }; 
            this.radChart1.DataManager.ValuesXColumn = "CategoryNum"
            this.radChart1.PlotArea.XAxis.DataLabelsColumn = "Category"
    public static class MyDataSource 
        public static DataTable Create() 
            DataTable table = new DataTable(); 
            table.Rows.Add(CreateRow(table.NewRow(), "11D", 3, 4)); 
            table.Rows.Add(CreateRow(table.NewRow(), "13A", 3, 8)); 
            table.Rows.Add(CreateRow(table.NewRow(), "13B", 2, 7)); 
            table.Rows.Add(CreateRow(table.NewRow(), "13B", 3, 71)); 
            table.Rows.Add(CreateRow(table.NewRow(), "13C", 2, 8)); 
            table.Rows.Add(CreateRow(table.NewRow(), "13C", 3, 16)); 
            table.Rows.Add(CreateRow(table.NewRow(), "220", 2, 13)); 
            table.Rows.Add(CreateRow(table.NewRow(), "220", 3, 40)); 
            table.Rows.Add(CreateRow(table.NewRow(), "23C", 2, 3)); 
            table.Rows.Add(CreateRow(table.NewRow(), "23C", 3, 10)); 
            return table; 
        public static void Extend(DataTable table, string column, string newColumn) 
            List<object> uniqueValues = RetrieveUniqueValues(table, column); 
            DataColumn newDataColumn = table.Columns.Add(newColumn, typeof(int)); 
            foreach (DataRow row in table.Rows) 
                row[newDataColumn] = uniqueValues.IndexOf(row[column]) + 1; 
        private static List<object> RetrieveUniqueValues(DataTable table, string column) 
            List<object> uniqueValues = new List<object>(); 
            foreach (DataRow row in table.Rows) 
                object value = row[column]; 
                if (!uniqueValues.Contains(value)) 
            return uniqueValues; 
        private static DataRow CreateRow(DataRow dataRow, params object[] parameters) 
            for (int i = 0; i < parameters.Length; i++) 
                dataRow[i] = parameters[i]; 
            return dataRow; 

    Feel free to use and modify the provided code. Also, let me know if you need further assistance.

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top