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 parameterSqlParameter 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 ?
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
Column 4
Row 1
Row 2
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:
(DateTime)
In this case you could use similar loop, but this time we should change both columns - LabelColumn and ValueColumn. For example:
int i=0;
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
Thank you very much. How can I set the Series "Name", if there is such a property. I use the following Code to add multiple Series
foreach (string list in KPI) {
string KPIValue = list; NumericSeries Series = new NumericSeries(); Series.Data.DataSource = SeriesTable; Series.Data.LabelColumn = "Shift"; Series.Data.ValueColumn = KPIValue; Series.DataBind(); UltraChart1.Series.Add(Series); }
How would I add multiple Series in a similar fashion, but assign a custom Name to the Series that will be shown in the legend ?