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图像是否显示点
}
/// <summary>
        /// 获取CharList数据
        /// </summary>
        /// <param name="dtTemp"></param>
        /// <param name="_list"></param>
        /// <param name="months"></param>
        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()));
                }
            }
        }
/// <summary>
/// 传入数据线图绘制
/// </summary>
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();
        }
/// <summary>
        /// ZedGraphControl图表绘制
        /// </summary>
        /// <param name="zgcName">ZedGraphControl名称</param>
        /// <param name="Title">Title标头</param>
        /// <param name="XA">X轴名称</param>
        /// <param name="YA">Y轴名称</param>
        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();
            }
        }
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值