Пример #1
0
        public OnLineStatic()
        {
            InitializeComponent();
            wnd = (StartPage)Application.Current.MainWindow;
            //  line = plotter.AddLineGraph(dataSource1, Colors.Green, 2, "PH");//添加曲线


            string          strSelect = "select * from tb_lhf_measure where saveindex is not null";
            OleDbConnection con       = wnd.con;

            if (con.State == ConnectionState.Open)
            {
                OleDbCommand     cmd = new OleDbCommand(strSelect, con);
                OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
                DataSet          set = new DataSet();
                adp.Fill(set);
                dt = set.Tables[0];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list.Add(Convert.ToString(dt.Rows[i].Field <object>("name")));
                }

                preSelectIndex.ItemsSource   = list;//设置组合框数据源
                preSelectIndex.SelectedIndex = nowSelectIndex;

                temp_datelist = new List <DateTime>();
                temp_ylist    = new List <double>();

                x = new EnumerableDataSource <DateTime>(temp_datelist);
                x.SetXMapping(x => xAxis.ConvertToDouble(x));
                y = new EnumerableDataSource <double>(temp_ylist);
                y.SetYMapping(y => y);
                composite = new CompositeDataSource(x, y);
                line      = plotter.AddLineGraph(composite, Colors.Green, 2, list.ElementAt(nowSelectIndex));//添加曲线
                if (dt.Rows[nowSelectIndex].Field <object>("upper") != null)
                {
                    temp_datelist_upper = new List <DateTime>();
                    temp_ylist_upper    = new List <double>();

                    x_upper = new EnumerableDataSource <DateTime>(temp_datelist_upper);
                    x_upper.SetXMapping(x_upper => xAxis.ConvertToDouble(x_upper));
                    y_upper = new EnumerableDataSource <double>(temp_ylist_upper);
                    y_upper.SetYMapping(y_upper => y_upper);
                    composite_upper = new CompositeDataSource(x_upper, y_upper);

                    Pen pen = new Pen();
                    pen.Brush     = new SolidColorBrush(Colors.Red);
                    pen.DashStyle = new DashStyle(new double[] { 2, 5 }, 2);
                    pen.Thickness = 2;//新建虚线画笔

                    PenDescription description = new PenDescription("上限");
                    line_upper = plotter.AddLineGraph(composite_upper, pen, description);//添加上曲线
                }
                if (dt.Rows[nowSelectIndex].Field <object>("lower") != null)
                {
                    temp_datelist_lower = new List <DateTime>();
                    temp_ylist_lower    = new List <double>();

                    x_lower = new EnumerableDataSource <DateTime>(temp_datelist_lower);
                    x_lower.SetXMapping(x_lower => xAxis.ConvertToDouble(x_lower));
                    y_lower = new EnumerableDataSource <double>(temp_ylist_lower);
                    y_lower.SetYMapping(y_lower => y_lower);
                    composite_lower = new CompositeDataSource(x_lower, y_lower);

                    Pen pen = new Pen();
                    pen.Brush     = new SolidColorBrush(Colors.Red);
                    pen.DashStyle = new DashStyle(new double[] { 2, 5 }, 2);
                    pen.Thickness = 2;//新建虚线画笔

                    PenDescription description = new PenDescription("下限");
                    line_upper = plotter.AddLineGraph(composite_lower, pen, description); //添加下限曲线
                }
                list_widiget = new List <Widiget>();                                      //警示灯链表
                for (int i = 0; i < dt.Rows.Count - 1; i++)
                {
                    Label lable = new Label();
                    lable.Content = dt.Rows[i].Field <object>("name");
                    lable.VerticalContentAlignment = VerticalAlignment.Center;
                    Ellipse ellipse = new Ellipse();
                    ellipse.Width           = 20;
                    ellipse.Height          = 20;
                    ellipse.Fill            = new SolidColorBrush(Colors.Green);
                    ellipse.Stroke          = new SolidColorBrush(Colors.Black);
                    ellipse.StrokeThickness = 2;
                    Widiget widiget = new Widiget();
                    widiget.lable   = lable;   //设置标签
                    widiget.ellipse = ellipse; //设置警示灯
                    list_widiget.Add(widiget); //添加到窗口部件链表

                    wnd_lower.Children.Add(lable);
                    wnd_lower.Children.Add(ellipse);
                }
            }
            else
            {
                return;
            }

            woker         = new BackgroundWorker();//后台更新UI线程
            woker.DoWork += DoWork;
        }
Пример #2
0
        public HistoryStatic()
        {
            InitializeComponent();
            wnd = (StartPage)Application.Current.MainWindow; //获取主窗口
            con = wnd.con;                                   //获取主链接
            string strSelect = "select * from tb_lhf_measure where saveindex is not null";

            if (con.State == ConnectionState.Open)
            {
                OleDbCommand     cmd = new OleDbCommand(strSelect, con);
                OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
                DataSet          set = new DataSet();
                adp.Fill(set);
                dt = set.Tables[0];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list.Add(Convert.ToString(dt.Rows[i].Field <object>("name")));
                }

                preSelectIndex.ItemsSource   = list;//设置组合框数据源
                preSelectIndex.SelectedIndex = nowSelectIndex;

                temp_datelist = new List <DateTime>();
                temp_ylist    = new List <double>();
                x             = new EnumerableDataSource <DateTime>(temp_datelist);
                x.SetXMapping(x => xAxis.ConvertToDouble(x));
                y = new EnumerableDataSource <double>(temp_ylist);
                y.SetYMapping(y => y);
                composite = new CompositeDataSource(x, y);
                line      = plotter.AddLineGraph(composite, Colors.Green, 2, list.ElementAt(nowSelectIndex));//添加曲线
                if (dt.Rows[nowSelectIndex].Field <object>("upper") != null)
                {
                    temp_datelist_upper = new List <DateTime>();
                    temp_ylist_upper    = new List <double>();

                    x_upper = new EnumerableDataSource <DateTime>(temp_datelist_upper);
                    x_upper.SetXMapping(x_upper => xAxis.ConvertToDouble(x_upper));
                    y_upper = new EnumerableDataSource <double>(temp_ylist_upper);
                    y_upper.SetYMapping(y_upper => y_upper);
                    composite_upper = new CompositeDataSource(x_upper, y_upper);

                    Pen pen = new Pen();
                    pen.Brush     = new SolidColorBrush(Colors.Red);
                    pen.DashStyle = new DashStyle(new double[] { 2, 5 }, 2);
                    pen.Thickness = 2;//新建虚线画笔

                    PenDescription description = new PenDescription("上限");
                    line_upper = plotter.AddLineGraph(composite_upper, pen, description);//添加上曲线
                }
                if (dt.Rows[nowSelectIndex].Field <object>("lower") != null)
                {
                    temp_datelist_lower = new List <DateTime>();
                    temp_ylist_lower    = new List <double>();

                    x_lower = new EnumerableDataSource <DateTime>(temp_datelist_lower);
                    x_lower.SetXMapping(x_lower => xAxis.ConvertToDouble(x_lower));
                    y_lower = new EnumerableDataSource <double>(temp_ylist_lower);
                    y_lower.SetYMapping(y_lower => y_lower);
                    composite_lower = new CompositeDataSource(x_lower, y_lower);

                    Pen pen = new Pen();
                    pen.Brush     = new SolidColorBrush(Colors.Red);
                    pen.DashStyle = new DashStyle(new double[] { 2, 5 }, 2);
                    pen.Thickness = 2;//新建虚线画笔

                    PenDescription description = new PenDescription("下限");
                    line_upper = plotter.AddLineGraph(composite_lower, pen, description);//添加下限曲线
                }
                pie_x = new List <string>();
                pie_y = new List <string>();
                pie_x.Add("正常率");
                pie_x.Add("过高率");
                pie_x.Add("过低率");
                pie_y.Add("0");
                pie_y.Add("0");
                pie_y.Add("0");
                chart.Width  = 580;
                chart.Height = 380;
                CreateChartPie("", pie_x, pie_y);
                // chart.Width = 20;
            }
            else
            {
                return;
            }
        }