Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a large table with roughly 70 columns.  I have a checkboxlist listing the column names and when the user checks certain items from that list (limit of 3 for now), it will create a multi line/multi series graph from those selections and use the items selected to create the legend as well.  I can get the graph to create but it is not graphing the columns I select and is just doing the last column in the checkboxlist.  I don't know why it is only doing 1 column and not all the ones selected and I am not sure why the legend creates a series for each item in the checkbox - regardless of what is selected.  


What I have tried:

from my aspx.cs page - binding to datatable

C#
protected void BindChart()
        {
            //Add columns to the DataTable
            string oradb = "Data Source=P3CMS;Persist Security Info=True;User ID=cmsuser;Password=cmssystem";
            OracleConnection cn = new OracleConnection(oradb);
            cn.Open();
            string cmdstr = "";
            string selectedValue = "";

            cmdstr = "SELECT DISTINCT CEM_READING_DATE, BATTERY_NAME, TURN ";

            //Build the IN string by looping through the listbox
            for (int i = 0; i < ListBoxSelection.Items.Count; i++)
            {
                if (ListBoxSelection.Items[i].Selected)
                {
                    selectedValue = selectedValue + ", " + ListBoxSelection.Items[i].Value;
                }
            }

            selectedValue = selectedValue.TrimEnd(',');

            cmdstr = cmdstr + selectedValue + " FROM CEM_READINGS ";

            //Create the WHERE string
            strWhere = "WHERE (CEM_READING_DATE >= TO_DATE('" + tbStartDate.Text + "','MM/DD/YYYY HH:MI:SS AM')) " +
                       "AND (BATTERY_NAME = '" + DropDownList1.SelectedValue + "') " +
                       "AND (TURN = '" + ddlTurn.SelectedValue + "') " +
                       "AND ROWNUM <= 100 " +
                       "ORDER BY CEM_READING_DATE ASC";

            //Add WHERE clause
            cmdstr = cmdstr + strWhere;

            OracleCommand cmd = new OracleCommand(cmdstr, cn);
            OracleDataAdapter adapter = new OracleDataAdapter(cmd);

            DataSet ds = new DataSet();
            adapter.Fill(ds);
            DataTable dt = ds.Tables[0];

            string[] x = new string[dt.Rows.Count];
            int[] y = new int[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                x[i] = dt.Rows[i][0].ToString();
                CEMGRAPH.Series[0].XValueType = ChartValueType.DateTime;
			}

            for (int col = 3; col < dt.Columns.Count; col++)
            {
                Series series = new Series();
                string ColName = dt.Columns[col].ColumnName;
                string retVal = string.Empty;
                bool bFound = true;
                
                for (int i = 0; i < CheckBoxList1.Items.Count; i++)
                {
                    if (CheckBoxList1.Items.Count > i)

                        if (CheckBoxList1.Items.Count == i)
                        {
                            selectedValue = selectedValue + ", " + CheckBoxList1.Items[i].ToString();
                        }
                }

                if (bFound)
                {
                    for (int i = 0; i < dt.Rows.Count - 1; i++)
                    {
                        y[i] = Convert.ToInt32(dt.Rows[i][col]);
                    }

                    CEMGRAPH.Series[0].Points.DataBindXY(x, y);
                    CEMGRAPH.Series.Add("Series" + (col).ToString());
                    CEMGRAPH.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;

                    CEMGRAPH.Legends["Default"].Enabled = true;
                    CEMGRAPH.Series[0].IsVisibleInLegend = true;
                }
            }
        }
Posted
Comments
j snooze 13-Sep-17 17:31pm    
looks to me like this would be your issue.
if (CheckBoxList1.Items.Count == i)
{
selectedValue = selectedValue + ", " + CheckBoxList1.Items[i].ToString();
}

i will only equal the the count of the checkboxlist items on the last time through. or perhaps I'm not understanding what that code is trying to accomplish.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900