コード例 #1
0
        private void generateGraph(string SelectedParameter, ListItem Station)
        {
            Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gray;
            Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gray;
            TableRow  trow = new TableRow();
            TableCell tcell_SelectedParameter = new TableCell();

            tcell_SelectedParameter.Text            = SelectedParameter;
            tcell_SelectedParameter.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            trow.Cells.Add(tcell_SelectedParameter);
            Chart1.ChartAreas[0].AxisX.Title          = "Sample Time";
            Chart1.ChartAreas[0].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center;
            Chart1.ChartAreas[0].AxisX.TitleFont      = new System.Drawing.Font("Arial,Helvetica,sans-serif", 11, FontStyle.Bold);
            Chart1.ChartAreas[0].AxisY.Title          = SelectedParameter;
            Chart1.ChartAreas[0].AxisY.TitleFont      = new System.Drawing.Font("Arial,Helvetica,sans-serif", 11, FontStyle.Bold);
            Chart1.ChartAreas[0].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center;
            Chart1.Series.Add(Station.Text);
            Chart1.Series[Station.Text].ChartType         = SeriesChartType.Line;
            Chart1.Series[Station.Text].IsVisibleInLegend = true;
            Chart1.ApplyPaletteColors();
            Label l1_line = new Label();

            l1_line.Text      = "----   ";
            l1_line.ForeColor = Chart1.Series[Station.Text].Color;
            Label l1_name = new Label();

            l1_name.Text = Station.Text;
            string    query     = string.Format("SELECT SampleTime, {0} from WaterQualityData where StationID = '{1}' and SampleTime >= '{2}' and SampleTime <= '{3}' order by SampleTime asc", SelectedParameter, Station.Value, txtStartDate.Text, txtEndDate.Text);
            DataTable dt        = GetData(query);
            DateTime  StartDate = Convert.ToDateTime(txtStartDate.Text.ToString());

            decimal [] y1 = new decimal[dt.Rows.Count];
            string[]   x1 = new string[dt.Rows.Count];
            for (int k = 0; k < dt.Rows.Count; k++)
            {
                y1[k] = 0;
            }
            int      cnt = 0, i, j = 0;
            DateTime d1 = StartDate;

            for (i = 0, j = 0; i < dt.Rows.Count; i++)
            {
                DateTime d3 = FinalDatetime(d1);
                if (Convert.ToDateTime(dt.Rows[i][0].ToString()) <= FinalDatetime(d1))
                {
                    if (!Convert.IsDBNull(dt.Rows[i][1]))
                    {
                        y1[j] += Convert.ToDecimal(Math.Round(Convert.ToDouble(dt.Rows[i][1]), 2));
                    }
                    cnt++;
                }
                else
                {
                    if (cnt > 0)
                    {
                        i -= 1;
                        DataSet ds = dt.DataSet;

                        x1[j] = dt.Rows[i][0].ToString();
                        y1[j] = y1[j] / cnt;
                        cnt   = 0;
                        MyRow r1 = new MyRow();
                        r1.date  = Convert.ToDateTime(dt.Rows[i][0]);
                        r1.value = Convert.ToDouble(y1[j]);
                        datalist.Add(r1);
                        j++;
                    }
                    else
                    {
                        i = i - 1;
                    }
                    d1 = FinalDatetime(d1);
                }
            }
            if (cnt != 0)
            {
                x1[j] = dt.Rows[i - 1][0].ToString();
                y1[j] = y1[j] / cnt;
                MyRow r1 = new MyRow();
                r1.date  = Convert.ToDateTime(dt.Rows[i - 1][0]);
                r1.value = Convert.ToDouble(y1[j]);
                datalist.Add(r1);
            }
            for (i = 0; i < j; i++)
            {
                Chart1.Series[Station.Text].Points.AddXY(x1[i], y1[i]);
                Chart1.Series[Station.Text].Font = new System.Drawing.Font("Arial,Helvetica,sans-serif", 11);
            }
            Chart1.Width  = 750;
            Chart1.Height = 250;
            Panel2.Controls.Add(l1_line);
            Panel2.Controls.Add(l1_name);
            Panel2.Controls.Add(new LiteralControl("</br>"));
            datalist.Sort((x, y) => {
                if (x.value > y.value)
                {
                    return(1);
                }
                else if (x.value == y.value)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
                          );
            Console.WriteLine(datalist);
        }
コード例 #2
0
        private void generateGraph(string SelectedParameter,ListItem Station)
        {
            Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gray;
            Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gray;
            TableRow trow = new TableRow();
            TableCell tcell_SelectedParameter = new TableCell();
            tcell_SelectedParameter.Text = SelectedParameter;
            tcell_SelectedParameter.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            trow.Cells.Add(tcell_SelectedParameter);
            Chart1.ChartAreas[0].AxisX.Title = "Sample Time";
            Chart1.ChartAreas[0].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center;
            Chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Arial,Helvetica,sans-serif", 11, FontStyle.Bold);
            Chart1.ChartAreas[0].AxisY.Title = SelectedParameter;
            Chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Arial,Helvetica,sans-serif", 11, FontStyle.Bold);
            Chart1.ChartAreas[0].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center;
            Chart1.Series.Add(Station.Text);
            Chart1.Series[Station.Text].ChartType = SeriesChartType.Line;
            Chart1.Series[Station.Text].IsVisibleInLegend = true;
            Chart1.ApplyPaletteColors();
            Label l1_line = new Label();
            l1_line.Text = "----   ";
            l1_line.ForeColor = Chart1.Series[Station.Text].Color;
            Label l1_name = new Label();
            l1_name.Text = Station.Text;
            string query = string.Format("SELECT SampleTime, {0} from WaterQualityData where StationID = '{1}' and SampleTime >= '{2}' and SampleTime <= '{3}' order by SampleTime asc", SelectedParameter, Station.Value, txtStartDate.Text, txtEndDate.Text);
            DataTable dt = GetData(query);
            DateTime StartDate = Convert.ToDateTime(txtStartDate.Text.ToString());
            decimal []y1=new decimal[dt.Rows.Count];
            string[] x1 = new string[dt.Rows.Count];
            for (int k = 0; k < dt.Rows.Count; k++)
                y1[k] = 0;
            int cnt = 0,i,j=0;
            DateTime d1=StartDate;

            for(i=0,j=0;i<dt.Rows.Count;i++)
            {
                DateTime d3 = FinalDatetime(d1);
                if(Convert.ToDateTime(dt.Rows[i][0].ToString())<=FinalDatetime(d1))
                {
                    if (!Convert.IsDBNull(dt.Rows[i][1]))
                    {
                        y1[j] += Convert.ToDecimal(Math.Round(Convert.ToDouble(dt.Rows[i][1]), 2));
                    }
                    cnt++;
                }
                else
                {
                    if (cnt > 0)
                    {
                        i -= 1;
                        DataSet ds = dt.DataSet;

                        x1[j] = dt.Rows[i][0].ToString();
                        y1[j] = y1[j] / cnt;
                        cnt = 0;
                        MyRow r1 = new MyRow();
                        r1.date = Convert.ToDateTime(dt.Rows[i][0]);
                        r1.value = Convert.ToDouble(y1[j]);
                        datalist.Add(r1);
                        j++;

                    }
                    else
                    {
                        i=i-1;
                    }
                    d1 = FinalDatetime(d1);
                }
            }
            if(cnt!=0)
            {
                x1[j] = dt.Rows[i-1][0].ToString();
                y1[j] = y1[j] / cnt;
                MyRow r1 = new MyRow();
                r1.date = Convert.ToDateTime(dt.Rows[i-1][0]);
                r1.value = Convert.ToDouble(y1[j]);
                datalist.Add(r1);
            }
            for ( i = 0; i < j; i++)
            {
                Chart1.Series[Station.Text].Points.AddXY(x1[i], y1[i]);
                Chart1.Series[Station.Text].Font = new System.Drawing.Font("Arial,Helvetica,sans-serif", 11);
            }
            Chart1.Width = 750;
            Chart1.Height = 250;
            Panel2.Controls.Add(l1_line);
            Panel2.Controls.Add(l1_name);
            Panel2.Controls.Add(new LiteralControl("</br>"));
               datalist.Sort((x,y)=> {
                                    if(x.value>y.value)
                                        return 1;
                                    else if(x.value==y.value)
                                        return 0;
                                    else return -1;}
                                    );
               Console.WriteLine(datalist);
        }