Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
520
Add Series dynamically
posted

The infragistics website contains an example that shows how to hide a series. While Hiding a series is easy, i want to dynamically add Series based on the values of a Webdropdown i parse into a list.

The following code is used to add a series, based on a date range and a multiselect dropdown:

DataTable datatable = new DataTable();
int i;
DataTable dt = new DataTable("TestTabel");
dt.Columns.Add("Machine", typeof(string));

for (i = 0; i < WebDropDown1.SelectedItems.Count; i++)
{
dt.Rows.Add(WebDropDown1.SelectedItems[i].Value.ToString());
}
string cs = string.Empty;

cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

SqlConnection con = new SqlConnection(cs);

con.Open();
SqlCommand cmd = new SqlCommand("FPYMaschineTabelle", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tblvaluetype = cmd.Parameters.AddWithValue("@List", dt); //Passing table value parameter
SqlParameter Beginn = cmd.Parameters.AddWithValue("Beginn", WebDatePicker1.Value);
SqlParameter Ende = cmd.Parameters.AddWithValue("End", WebDatePicker2.Value);
tblvaluetype.SqlDbType = SqlDbType.Structured; // This is used to tell ADO.NET we are passing Table value Parameter

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable SeriesTable = ds.Tables[0];


NumericSeries Series = new NumericSeries();
Series.Data.DataSource = SeriesTable;
Series.Data.LabelColumn = "Date";
Series.Data.ValueColumn = "FPY";
Series.DataBind();
UltraChart1.Series.Add(Series);

UltraChart1.Data.DataBind();
UltraChart1.Axis.X.Extent = 110;

con.Close();

How can I add a new series with the value column as the string for the stringlist and label column as date ? 

Parents
No Data
Reply
  • 53790
    Suggested Answer
    posted

    Hello Henning,

    Looking at the provided information, your StoredProcedure will return a table. The content of this table will depend of your input parameters. Your stored procedure could return different type of tables (when I said different type of tables, I mean different number of columns, with different data type of these columns and different number of rows). So depending of this table you could use the code below. Let`s say that stored procedure will return a table like this:

     

    Column 1 (DateTime)

    Column 2

    (Double / Decimal)

    Column 3

    (Double / Decimal)

    Column 4

    (Double / Decimal)

    Row 1

     

     

     

     

    Row 2

     

     

     

     

    Row 3

     

     

     

     

    Row 3

     

     

     

     

    where your column 1 is DateTime and these values will be represent on your X axis. Column 2, 3 and 4 will contains your decimal values for Series 1, 2 and 3. For this scenario you could try the code below:


    foreach (DataColumn dc in ds.Tables[0].Columns)

                {

           NumericSeries series = new NumericSeries();

                 series1.DataBind(dt, dc.ColumnName, "Column 1 ");

           UltraChart1.Series.Add(series);

                }

     

    Another possible table could be:

     

    Column 1 (DateTime)

    Column 2

    (Double / Decimal)

    Column 3

    (DateTime)

    Column 4

    (Double / Decimal)

    Row 1

     

     

     

     

    Row 2

     

     

     

     

    Row 3

     

     

     

     

    Row 3

     

     

     

     

     

    In this case you could use similar loop, but this time we should change both columns - LabelColumn and ValueColumn. For example:

    int i=0;

    foreach (DataColumn dc in ds.Tables[0].Columns)

                {

           if (i % 2 != 0)

                    {

             NumericSeries series1 = new NumericSeries();

                     series1.DataBind(dt, ds.Tables[0].Columns[i], ds.Tables[0].Columns[i+1]);

                    }

                    i++;

                }

    Your stored procedure could create many different type of tables and to be more concrete in my answers I need to know what is the structure of your table. 

    Please feel free to write me if you have any questions

    Regards

     

     

     

Children