ZedGraph

来源:互联网 发布:求剑若此不亦惑乎 编辑:程序博客网 时间:2024/04/30 19:40
 数据源既拼出来的数组,X Y 轴对应数组使用List<String> 从数据源添加最后转换为数组public partial class frmZed_1 : Form    {        DataGridView gridview = null;        DateTime _date_s, _date_e;        GraphPane myPane;        List<string> list_Steel = null;        List<string> List_Mat = null;        public frmZed_1()        {            InitializeComponent();        }        public frmZed_1(DataGridView gridview, DateTime _date_s, DateTime _date_e, List<string> list_Steel,        List<string> List_Mat )            : this()        {            this.gridview = gridview;            this._date_s = _date_s;            this._date_e = _date_e;            this.list_Steel = list_Steel;            this.List_Mat = List_Mat;        }            private void frmZed_1_Load(object sender, EventArgs e)        {            comboBox_Mat.DataSource = List_Mat;            comboBox_Steel.DataSource = list_Steel;            myPane = zed.GraphPane;            myPane.Title.Text = "消耗趋势图";            myPane.Title.FontSpec.Size = 10;            myPane.XAxis.Title.Text = "炉号";            myPane.XAxis.Title.FontSpec.Size = 8;            myPane.YAxis.Title.FontSpec.Size = 8;             zed.IsShowPointValues = true;            myPane.Legend.FontSpec.Size = 5;  //显示信息大小图例            myPane.YAxis.Title.Text="消耗量";            myPane.XAxis.Scale.FontSpec.Angle = 90;//X轴90度            myPane.YAxis.Scale.FontSpec.Size = 5;            myPane.YAxis.Scale.FontSpec.Family = "Times New Roman";            myPane.XAxis.Scale.FontSpec.Size = 5;            myPane.XAxis.Scale.MinorStep = 1;//刻度            CreateChat(gridview);        }        private void CreateChartByColumnName(DataGridView dataGridview)        {            if (dataGridview.DataSource == null) return;            //生成X轴钢种坐标            string Unit = "T";            //if (comboBox_Mat.Text.Contains("线"))            //{            //    Unit = "M";            //}           if (comboBox_Mat.Text.Contains("电"))            {                Unit = "KWH";            }            else            {                Unit = "T";            }              myPane.YAxis.Title.Text=string.Format("消耗量({0})",Unit);              myPane.Title.Text = string.Format("钢种{0}时间从{1}到{2}消耗趋势图", comboBox_Steel.Text, _date_s.ToString("yyyy-MM-dd HH:mm:ss"), _date_e.ToString("yyyy-MM-dd HH:mm:ss"));            DataTable dt = dataGridview.DataSource as DataTable;            DataView dv = new DataView(dt);            dv.RowFilter = string.Format("钢种='{0}'", this.comboBox_Steel.Text);            dv.Sort = "炉号 ASC";            List<string> listlables = new List<string>();             List<double> list_Y = new List<double>();                             //炼钢用铁水,            // sum(cl."废钢铁统料") 废钢铁统料,            // sum(cl."炼钢用铁块") 炼钢用铁块            myPane.CurveList.Clear();                        foreach (DataRowView drv in dv)            {                listlables.Add(drv["炉号"].ToString());                list_Y.Add((drv[comboBox_Mat.Text].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv[comboBox_Mat.Text].ToString()));            }            string[] labels = listlables.ToArray();            myPane.CurveList.Clear();            LineItem curve = myPane.AddCurve(comboBox_Mat.Text,                null, list_Y.ToArray(), Color.Red, SymbolType.Circle);                       curve.Line.Width = 1.5F;            curve.Symbol.Fill = new Fill(Color.Red);            curve.Symbol.Size = 2;            curve.Line.IsSmooth = true;             myPane.XAxis.Type = AxisType.Text;             myPane.XAxis.Scale.TextLabels = labels; //设置X轴坐标                      zed.AxisChange();            zed.Refresh();        }        #region        /// <summary>        ///  生成曲线图        /// </summary>        /// <param name="dataGridview"></param>        private void CreateChat(DataGridView dataGridview)        {            //if (dataGridview.DataSource == null) return;            //生成X轴钢种坐标            //myPane.Title.Text = string.Format("钢种{0}当天【{1}】消耗趋势图", this.comboBox_Steel.Text, _date.ToString("yyyy年MM月dd日"));            //DataTable dt = dataGridview.DataSource as DataTable;     //       DataView dv = new DataView(dt);     //       dv.RowFilter = string.Format("钢种='{0}'", this.steel);     //       dv.Sort = "炉号 ASC";     //       List<string> listlables = new List<string>();     //       List<Double> list_Y_1 = new List<double>();     //       List<Double> list_Y_2 = new List<double>();     //       List<Double> list_Y_3 = new List<double>();     //       //  sum(cl."铝锰铁") "铝锰铁",     //       //sum(cl."电炉低碳锰铁") "电炉低碳锰铁",     //       //sum(cl."低铝硅铁") "低铝硅铁",     //       //sum(cl."高碳锰铁") "高碳锰铁",     //       //sum(cl."锰硅合金6517") "锰硅合金6517",     //       //sum(cl."高硅硅锰(2)") "高硅硅锰(2))",     //       //sum(cl."钒氮合金(VN12)") "钒氮合金(VN12)",      //       //sum(cl."硅铁") "硅铁",     //       //sum(cl."电炉中碳锰铁") "电炉中碳锰铁"     //       List<Double> list_Y_4 = new List<double>();     //       List<Double> list_Y_5 = new List<double>();     //       List<Double> list_Y_6 = new List<double>();     //       List<Double> list_Y_7 = new List<double>();     //       List<Double> list_Y_8 = new List<double>();     //       List<Double> list_Y_9 = new List<double>();     //       List<Double> list_Y_10 = new List<double>();     //       List<Double> list_Y_11 = new List<double>();     //       List<Double> list_Y_12 = new List<double>();     //       //炼钢用铁水,     //       // sum(cl."废钢铁统料") 废钢铁统料,     //       // sum(cl."炼钢用铁块") 炼钢用铁块     //       foreach (DataRowView drv in dv)     //       {     //           listlables.Add(drv["炉号"].ToString());     //           list_Y_1.Add((drv["炼钢用铁水"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["炼钢用铁水"].ToString()));     //           list_Y_2.Add((drv["废钢铁统料"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["废钢铁统料"].ToString()));     //           list_Y_3.Add((drv["炼钢用铁块"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["炼钢用铁块"].ToString()));     //           list_Y_4.Add((drv["铝锰铁"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["铝锰铁"].ToString()));     //           list_Y_5.Add((drv["电炉低碳锰铁"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["电炉低碳锰铁"].ToString()));     //           list_Y_6.Add((drv["低铝硅铁"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["低铝硅铁"].ToString()));     //           list_Y_7.Add((drv["高碳锰铁"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["高碳锰铁"].ToString()));     //           list_Y_8.Add((drv["锰硅合金6517"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["锰硅合金6517"].ToString()));     //           list_Y_9.Add((drv["高硅硅锰(2))"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["高硅硅锰(2))"].ToString()));     //           list_Y_10.Add((drv["钒氮合金(VN12)"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["钒氮合金(VN12)"].ToString()));     //           list_Y_11.Add((drv["硅铁"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["硅铁"].ToString()));     //           list_Y_12.Add((drv["电炉中碳锰铁"].Equals(DBNull.Value)) ? 0 : Convert.ToDouble(drv["电炉中碳锰铁"].ToString()));     //       }     //       string[] labels = listlables.ToArray();     //       myPane.CurveList.Clear();     //       LineItem myCurve_1 = myPane.AddCurve("炼钢用铁水",     //           null, list_Y_1.ToArray(), Color.Red, SymbolType.Circle);     //       LineItem myCurve_2 = myPane.AddCurve("废钢铁统料",     //        null, list_Y_2.ToArray(), Color.Blue, SymbolType.Circle);     //       LineItem myCurve_3 = myPane.AddCurve("炼钢用铁块",     //    null, list_Y_3.ToArray(), Color.Magenta, SymbolType.Circle);     //       LineItem myCurve_4 = myPane.AddCurve("铝锰铁",     //null, list_Y_4.ToArray(), Color.Maroon, SymbolType.Circle);     //       LineItem myCurve_5 = myPane.AddCurve("电炉低碳锰铁",     //null, list_Y_5.ToArray(), Color.Fuchsia, SymbolType.Circle);     //       LineItem myCurve_6 = myPane.AddCurve("低铝硅铁",     //null, list_Y_6.ToArray(), Color.DarkRed, SymbolType.Circle);     //       LineItem myCurve_7 = myPane.AddCurve("高碳锰铁",     //null, list_Y_7.ToArray(), Color.Purple, SymbolType.Circle);     //       LineItem myCurve_8 = myPane.AddCurve("锰硅合金6517",     //null, list_Y_8.ToArray(), Color.DarkBlue, SymbolType.Circle);     //       LineItem myCurve_9 = myPane.AddCurve("高硅硅锰(2))",     //null, list_Y_9.ToArray(), Color.BlueViolet, SymbolType.Circle);     //       LineItem myCurve_10 = myPane.AddCurve("钒氮合金(VN12)",     //null, list_Y_10.ToArray(), Color.Chocolate, SymbolType.Circle);     //       LineItem myCurve_11 = myPane.AddCurve("硅铁",     //null, list_Y_11.ToArray(), Color.Coral, SymbolType.Circle);     //       LineItem myCurve_12 = myPane.AddCurve("电炉中碳锰铁",     //null, list_Y_12.ToArray(), Color.CornflowerBlue, SymbolType.Circle);             //       ;     //       myPane.CurveList.ForEach(new Action<CurveItem>(delegate(CurveItem item)     //       {     //           LineItem curve = item as LineItem; curve.Line.Width = 1.5F;     //           curve.Symbol.Fill = new Fill(Color.Red);      //           curve.Symbol.Size = 2;     //           curve.Line.IsSmooth = true;     //       }));             //       myPane.XAxis.Type = AxisType.Text;     //       //myPane.XAxis.Scale.MajorStep = 0;     //       myPane.XAxis.Scale.TextLabels = labels;     //       myPane.XAxis.Scale.FontSpec.Angle = 40;     //       myPane.YAxis.Scale.FontSpec.Size = 5;     //       myPane.XAxis.Scale.FontSpec.Size = 5;     //       myPane.XAxis.Scale.MinorStep = 1;     //       zed.IsShowPointValues = true;     //       myPane.Legend.FontSpec.Size = 5;     //       zed.AxisChange();     //       zed.Refresh();        }        #endregion             private void btn_Chat_Click(object sender, EventArgs e)        {            CreateChartByColumnName(this.gridview);        }    }


原创粉丝点击