147 lines
6.0 KiB
C#
147 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DrawGraph;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Resources;
|
|
using System.Drawing.Imaging;
|
|
using System.Drawing.Drawing2D;
|
|
|
|
namespace DrawGraph
|
|
{
|
|
public class Util
|
|
{
|
|
public static FontSpec Font14 = new FontSpec("宋体", 14.0f, Color.Black, true, false, false);
|
|
public static FontSpec Font16 = new FontSpec("宋体", 16.0f, Color.Black, true, false, false);
|
|
|
|
public static void DrawText(string letter, double x, double y, ZedGraphControl zedGraph, FontSpec font)
|
|
{
|
|
TextObj text = new TextObj(letter, x, y, CoordType.PaneFraction);
|
|
text.FontSpec = font;
|
|
text.FontSpec.Border.IsVisible = false;
|
|
text.FontSpec.Fill.IsVisible = false;
|
|
text.Location.AlignH = AlignH.Left;
|
|
text.Location.AlignV = AlignV.Top;
|
|
text.ZOrder = ZOrder.A_InFront;
|
|
zedGraph.MasterPane.GraphObjList.Add(text);
|
|
}
|
|
|
|
public static void DrawLine(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph)
|
|
{
|
|
LineObj line = new LineObj(Color.Gray, x1, y1, x2, y2);
|
|
line.IsVisible = true;
|
|
line.ZOrder = ZOrder.A_InFront;
|
|
line.Location.AlignH = AlignH.Left;
|
|
line.Location.AlignV = AlignV.Top;
|
|
line.Location.CoordinateFrame = CoordType.PaneFraction;
|
|
zedGraph.MasterPane.GraphObjList.Add(line);
|
|
}
|
|
|
|
public static void DrawLine(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph, string tag, Color LineColor)
|
|
{
|
|
LineObj lineObj = new LineObj(LineColor, x1, y1, x2, y2);
|
|
lineObj.IsVisible = true;
|
|
lineObj.ZOrder = ZOrder.A_InFront;
|
|
lineObj.Location.AlignH = AlignH.Left;
|
|
lineObj.Location.AlignV = AlignV.Top;
|
|
lineObj.Location.CoordinateFrame = CoordType.PaneFraction;
|
|
lineObj.Tag = tag;
|
|
zedGraph.MasterPane.GraphObjList.Add(lineObj);
|
|
}
|
|
/// <summary>
|
|
/// 在Zedgraph上绘图
|
|
/// </summary>
|
|
/// <param name="imgObj">已定义好的ImageObj对象</param>
|
|
/// <param name="zedGraph">ZedGraphControl</param>
|
|
public static void DrawImage(ImageObj imgObj, ZedGraphControl zedGraph)
|
|
{
|
|
zedGraph.MasterPane.GraphObjList.Add(imgObj);
|
|
}
|
|
/// <summary>
|
|
/// 根据自定义好的TextObj绘制文字
|
|
/// </summary>
|
|
/// <param name="text">已定义的TextObj</param>
|
|
/// <param name="zedGraph">ZedGraphControl</param>
|
|
public static void DrawText(TextObj text, ZedGraphControl zedGraph)
|
|
{
|
|
zedGraph.MasterPane.GraphObjList.Add(text);
|
|
}
|
|
/// <summary>
|
|
/// 绘制矩形
|
|
/// </summary>
|
|
/// <param name="box">已定义的BoxObj对象</param>
|
|
/// <param name="zedGraph">ZedGraphControl</param>
|
|
public static void DrawBox(BoxObj box, ZedGraphControl zedGraph)
|
|
{
|
|
zedGraph.MasterPane.GraphObjList.Add(box);
|
|
}
|
|
/// <summary>
|
|
/// 画出带标签的线
|
|
/// </summary>
|
|
/// <param name="x1">起点X坐标</param>
|
|
/// <param name="y1">起点Y坐标</param>
|
|
/// <param name="x2">终点X坐标</param>
|
|
/// <param name="y2">终点Y坐标</param>
|
|
/// <param name="zedGraph">ZedGraphControl</param>
|
|
/// <param name="tag">线标签</param>
|
|
public static void DrawLine(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph, string tag, Color LineColor, DashStyle style = DashStyle.Solid)
|
|
{
|
|
LineObj line = new LineObj(LineColor, x1, y1, x2, y2);
|
|
line.IsVisible = true;
|
|
line.ZOrder = ZOrder.B_BehindLegend;
|
|
line.Location.AlignH = AlignH.Left;
|
|
line.Location.AlignV = AlignV.Top;
|
|
line.Location.CoordinateFrame = CoordType.PaneFraction;
|
|
line.Tag = tag;
|
|
line.Line.Style = style;
|
|
zedGraph.MasterPane.GraphObjList.Add(line);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取TextObj字体的相对宽度
|
|
/// </summary>
|
|
/// <param name="text"></param>
|
|
/// <param name="zgc"></param>
|
|
public static float GetColWidthFraction(TextObj text, ZedGraphControl zgc)
|
|
{
|
|
GraphPane pane = zgc.GraphPane;
|
|
float ratio = pane.CalcScaleFactor();
|
|
Graphics g = zgc.CreateGraphics();
|
|
float absoluteWidth = text.FontSpec.GetWidth(g, text.Text, ratio);
|
|
float paneWidth = pane.Rect.Width;
|
|
return absoluteWidth / paneWidth;
|
|
}
|
|
/// <summary>
|
|
/// 获取TextObj字体的相对高度
|
|
/// </summary>
|
|
/// <param name="oTxt"></param>
|
|
/// <param name="baseZed"></param>
|
|
/// <returns></returns>
|
|
public static float GetColHeightFraction(TextObj text, ZedGraphControl zgc)
|
|
{
|
|
GraphPane pane = zgc.GraphPane;
|
|
float ratio = pane.CalcScaleFactor();
|
|
Graphics g = zgc.CreateGraphics();
|
|
float absoluteHeight = text.FontSpec.GetHeight(ratio);
|
|
float paneHeight = pane.Rect.Height;
|
|
return absoluteHeight / paneHeight;
|
|
}
|
|
/////////////////////////////////////////////////////////////////////////
|
|
public static void DrawLineWidth(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph, string tag, Color LineColor, int width = 1)
|
|
{
|
|
LineObj line = new LineObj(LineColor, x1, y1, x2, y2);
|
|
line.IsVisible = true;
|
|
line.ZOrder = ZOrder.A_InFront;
|
|
line.Location.AlignH = AlignH.Left;
|
|
line.Location.AlignV = AlignV.Top;
|
|
line.Location.CoordinateFrame = CoordType.PaneFraction;
|
|
line.Tag = tag;
|
|
line.Line.Style = DashStyle.Solid;
|
|
line.Line.Width = width;
|
|
zedGraph.MasterPane.GraphObjList.Add(line);
|
|
}
|
|
}
|
|
}
|