This is a migrated thread and some comments may be shown as answers.
2 Bar Series with Data Binding
1 Answer 11 Views
This is a migrated thread and some comments may be shown as answers.
Marianne
Top achievements
Rank 1
Veteran
Marianne asked on 09 Jun 2020, 02:24 PM
I was able to create a bar chart with one set of bars (series)  and bound it to a DataTable without any problem.  Now my boss wants me to create two series - how do I bind it to a data source?  Do I bind it to a DataSet or bind the DataTables to each series?

1 Answer, 1 is accepted

Sort by
0
Nadya
Telerik team
answered on 11 Jun 2020, 03:21 PM

Hello Marianne,

If you want to have two BarSeries in RadChartView you can bind each separate seria to a data source by using the DataSource property. Thus, you can bind the BarSeries and add them to the Series collection. A sample example is demonstrated below:

public RadForm1()
{
    InitializeComponent();

    DataTable table = new DataTable();
    table.Columns.Add("Value", typeof(double));
    table.Columns.Add("Name", typeof(string));
    table.Rows.Add(1, "John");
    table.Rows.Add(3, "Adam");
    table.Rows.Add(5, "Peter");
    table.Rows.Add(12, "Sam");
    table.Rows.Add(6, "Paul");

    BarSeries barSeries = new BarSeries();
    this.radChartView1.Series.Add(barSeries);
    barSeries.DataSource = table;
    barSeries.ValueMember = "Value";
    barSeries.CategoryMember = "Name";

    //barSeries2
    DataTable table2 = new DataTable();
    table2.Columns.Add("Value", typeof(double));
    table2.Columns.Add("Name", typeof(string));
    table2.Rows.Add(2, "John");
    table2.Rows.Add(8, "Adam");
    table2.Rows.Add(7, "Peter");
    table2.Rows.Add(15, "Sam");
    table2.Rows.Add(20, "Paul");

    BarSeries barSeries2 = new BarSeries();
    this.radChartView1.Series.Add(barSeries2);
    barSeries2.DataSource = table2;
    barSeries2.ValueMember = "Value";
    barSeries2.CategoryMember = "Name";
}

I hope this helps. If you have further questions please let me know.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Asked by
Marianne
Top achievements
Rank 1
Veteran
Answers by
Nadya
Telerik team
Share this question
or