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
20
Need help creating dynamic multi-series lne cart
posted

I don't want to use xaml jut css or data info because the amount to doctors will be grabbed from a database. my code references a stored procedure named GetDoctors to grab a list of names and then another named Encounters that retrieves data if this format

Name   |     Date   |   encountertotal

Dr. A        1/1/2009    100

Dr. A        2/1/2009    105

Dr. A        3/1/2009    110

Dr. B       1/1/2009     102

Dr. B       2/1/2009     103

Dr. B       3/1/2009      98

I want the chart to be a line chart with encounter values up Y axis and Dates across X axis with the names of the doctors being the lines. Here is a code segment i'm using, but it only displays one line?

 System.Data.DataTable DT2 = new System.Data.DataTable();

SqlCommand MyCommand2 = new SqlCommand("ClinicData.dbo.GetDoctors", MyConnection);

MyCommand2.CommandType = System.Data.

CommandType.StoredProcedure;

SqlDataAdapter MyDataAdapter2 = new SqlDataAdapter(MyCommand2);

MyDataAdapter2.Fill(DT2);

MyDataAdapter2.Dispose();

// NOW DT2 CONTAINS MY LIST OF DOCTORS

SqlCommand MyCommand = new SqlCommand("ClinicData.dbo.Encounters", MyConnection);

MyCommand.CommandType = System.Data.

CommandType.StoredProcedure;

SqlParameter sqlname = MyCommand.Parameters.Add(new SqlParameter("@name",System.Data.SqlDbType.NVarChar,254));

SqlParameter sqlstartdate = MyCommand.Parameters.Add(new SqlParameter("@startdate",System.Data.SqlDbType.SmallDateTime));

SqlParameter sqlenddate = MyCommand.Parameters.Add(new SqlParameter("@enddate",System.Data.SqlDbType.SmallDateTime));

sqlname.Direction = System.Data.ParameterDirection.Input;

sqlstartdate.Direction = System.Data.ParameterDirection.Input;

sqlenddate.Direction = System.Data.ParameterDirection.Input;

this.xamChart1.Series.Clear();

sqlstartdate.Value = startdate.SelectedDate;

sqlenddate.Value =  startdate.SelectedDate;

// NOW DISPLAY SERIES FOR EACH DOCTOR

 

for (int lp = 0; lp < DT2.Rows.Count; lp++)

{

DT.Clear();

sqlname.Value = DT2.Rows[lp][0].ToString();

SqlDataAdapter MyDataAdapter = new SqlDataAdapter(MyCommand);

MyDataAdapter.Fill(DT);

MyDataAdapter.Dispose();

Infragistics.Windows.Chart.

Series MySeries = new Infragistics.Windows.Chart.Series();

this.xamChart1.Series.Add(MySeries);

this.xamChart1.Series[lp].DataMapping = "Label=name;Value=encountertotal";

this.xamChart1.Series[lp].ChartType = Infragistics.Windows.Chart.ChartType.Line;

this.xamChart1.Series[lp].DataSource = DT;

this.xamChart1.Series[lp].Label = DT2.Rows[lp][0].ToString();

this.xamChart1.Series[lp].Animation = new Infragistics.Windows.Chart.Animation();

}

No matter what I try, I end up with only one line. encounters are listed up the y axis and one name is displayed multiple times across the x axis.What am i doing wrong?

  • 17605
    posted

    You can try changing the creation of the chart series to be something like:

    for (int seriesIndex = 0; seriesIndex < 2; seriesIndex++)

                {

                    Series series = new Series();

     

                    series.ChartType = Infragistics.Windows.Chart.ChartType.Line;

                    this.xamChart1.Series.Add(series);

     

                    int rowIndex = seriesIndex * 3;

     

                    for (int lp = rowIndex; lp < 3 * (rowIndex + 1); lp++)

                    {

                        DataPoint dp = new DataPoint();

                        dp.Value = Convert.ToDouble(DT2.Rows[lp][2]);

                        dp.Label = DT2.Rows[lp][1].ToString();

                    }

                }