C#zedGraphControl图形绘制

首先下载的组件包,然后到VS找到引用–浏览–找到下载好的文件包–zedgraph_dll_v515
找到ZedGraph.dll、ZedGraph.Web.dll这两个dll文件进行引用

zedgraph_dll_v515文件包下载
下载链接:https://pan.baidu.com/s/1XZ17Ygh_BVWnY-NWET-5Bg
提取码:a9sg

private void frmJJwh_Load(object sender, EventArgs e)
        {
            //开始ZedGraphControl图形绘制//控件名称、标头、X轴名称、Y轴名称
            LhPubFunc.FormartZgc(zedGraphControl1, "线图名称", "X轴名称", "Y轴名称");
        }
private  void GetZedGraphControl()
{
	PointPairList _list = null;
	string[] months = null;
	//图形绘制
	GetCharList(dtW, ref _list, ref months);
	LhPubFunc.loadLineChart(zedGraphControl1, _list, months, SymbolType.None);//SymbolType.None图像是否显示点
}
/// 
        /// 获取CharList数据
        /// 
        /// 
        /// 
        /// 
        private void GetCharList(DataTable dtTemp, ref PointPairList _list, ref string[] months)
        {
            string _DayTime = "date";
            if (dtTemp == null || dtTemp.Rows.Count == 0) return;
            DataRow[] rows = dtTemp.Select();
            months = new string[rows.Length];
            _list = new PointPairList();
            if (rows.Length > 0)
            {
                for (int i = 0; i < rows.Length; i++)
                {
                    months[i] = rows[i][_DayTime].ToString().Trim();
                    _list.Add(Convert.ToDouble(i), Convert.ToDouble(rows[i]["jz"].ToString().Trim()));
                }
            }
        }
/// 
/// 传入数据线图绘制
/// 
static public void loadLineChart(ZedGraphControl zgc, PointPairList list, string[] months, SymbolType name)
        {
            GraphPane mPane = zgc.GraphPane;
            //清空绘制区
            mPane.CurveList.Clear();
            mPane.GraphObjList.Clear();

            mPane.XAxis.Scale.TextLabels = null;
            zgc.Refresh();
            if (months == null || list == null)
            {
                return;
            }
            if (list.Count == 0) return;
            mPane.XAxis.Scale.TextLabels = months;
            LineItem curve = mPane.AddCurve("", list, Color.Red, name);//点Circle,
            curve.Line.Width = 1.8F;
            curve.Symbol.Fill = new Fill(Color.LightSalmon);
            curve.Symbol.Size = 6.0F;
            curve.Line.IsAntiAlias = false;
            mPane.AxisChange();
            zgc.AxisChange();
            zgc.Refresh();
        }
/// 
        /// ZedGraphControl图表绘制
        /// 
        /// ZedGraphControl名称
        /// Title标头
        /// X轴名称
        /// Y轴名称
        static public void FormartZgc(ZedGraphControl zgcName, string Title, string XA, string YA)
        {
            ZedGraphControl[] zgcs = new ZedGraphControl[1] { zgcName };

            string _charTile = Title;
            string[] xyTitle = new string[2];
            xyTitle[0] = XA;
            xyTitle[1] = YA;
            foreach (ZedGraphControl zgc in zgcs)
            {
                GraphPane mPane = zgc.GraphPane;
                
                zgc.IsShowContextMenu = false;
                zgc.IsShowPointValues = true;//获取数据点数据
                zgc.IsEnableVZoom = false;
                mPane.Chart.Border.Color = Color.Gray;
                mPane.Title.FontSpec.IsBold = false;
                mPane.Title.FontSpec.Size = mPane.Title.FontSpec.Size - 1;
                mPane.Title.Text = _charTile;

                mPane.XAxis.Title.Text = xyTitle[0];
                mPane.XAxis.Title.FontSpec.IsBold = false;
                mPane.XAxis.Title.FontSpec.Size = mPane.Title.FontSpec.Size - 1;
                mPane.XAxis.Scale.FontSpec.Size = mPane.Title.FontSpec.Size - 3;

                mPane.XAxis.MajorGrid.IsVisible = true;//竖线
                mPane.XAxis.MajorGrid.Color = Color.LightGray;
                mPane.XAxis.MajorGrid.DashOn = 5.0F;
                mPane.XAxis.MajorGrid.DashOff = 2.0F;
                mPane.XAxis.MajorGrid.PenWidth = 1.0F;

                mPane.XAxis.MajorTic.IsInside = false;
                mPane.XAxis.MajorTic.IsOpposite = false;
                mPane.XAxis.MajorTic.IsOutside = false;

                mPane.XAxis.MinorTic.IsInside = false;
                mPane.XAxis.MinorTic.IsOutside = false;
                mPane.XAxis.MinorTic.IsOpposite = false;

                mPane.YAxis.Title.Text = xyTitle[1];
                mPane.YAxis.Title.FontSpec.IsBold = false;
                mPane.YAxis.Title.FontSpec.Size = mPane.Title.FontSpec.Size - 1;
                mPane.YAxis.Scale.FontSpec.Size = mPane.YAxis.Scale.FontSpec.Size -3;

                mPane.YAxis.MajorGrid.IsVisible = false;//横线
                mPane.YAxis.MajorGrid.Color = Color.LightGray;
                mPane.YAxis.MajorGrid.DashOff = 2.0F;
                mPane.YAxis.MajorGrid.DashOn = 5.0F;
                mPane.YAxis.MajorGrid.PenWidth = 1.0F;

                mPane.YAxis.MajorTic.IsInside = false;
                mPane.YAxis.MajorTic.IsOutside = false;
                mPane.YAxis.MajorTic.IsOpposite = false;

                mPane.YAxis.MinorTic.IsInside = false;
                mPane.YAxis.MinorTic.IsOutside = false;
                mPane.YAxis.MinorTic.IsOpposite = false;
                mPane.Legend.IsVisible = false;

                mPane.XAxis.Type = ZedGraph.AxisType.Text;

                mPane.XAxis.Scale.Min = 0;
                mPane.YAxis.Scale.MagAuto = false;
                mPane.YAxis.Scale.Format = "#,##0.00";

                mPane.Chart.Fill = new Fill(Color.White);
                mPane.AxisChange();

                zgc.AxisChange();
                zgc.Refresh();
            }
        }

你可能感兴趣的:(c#)