Пример #1
0
 public CurveGroup(ChartGraph chart)
 {
     base.Chart       = chart;
     this.xAxes       = new XAxes();
     this.CursorPoint = new Point(0, 0);
     this.ShowCursor  = true;
 }
Пример #2
0
 public CurveGroup(ChartGraph chart)
 {
     base.Chart = chart;
     this.xAxes = new XAxes();
     this.CursorPoint = new Point(0, 0);
     this.ShowCursor = true;
 }
Пример #3
0
 public LineCurve(ChartGraph chart, string name, int maxPointCount)
     : base(chart)
 {
     this.Name         = name;
     this.LineWidth    = 1;
     this.LineColor    = Color.Lime;
     this.yAxes        = new YAxes();
     this.TimeDayAlign = false;
 }
Пример #4
0
 public LineArea(ChartGraph chart, string name, bool shareY)
 {
     this.chart        = chart;
     this.Name         = name;
     this.IsShareYAxes = shareY;
     this.YAxes        = new YAxes();
     this.SharedYAxes  = new YAxes();
     this.XFreqScale   = -1;
 }
Пример #5
0
 public LineArea(ChartGraph chart, string name, bool shareY)
 {
     this.chart = chart;
     this.Name = name;
     this.IsShareYAxes = shareY;
     this.YAxes = new YAxes();
     this.SharedYAxes = new YAxes();
     this.XFreqScale = -1;
 }
Пример #6
0
 public LineCurve(ChartGraph chart, string name, int maxPointCount)
     : base(chart)
 {
     this.Name = name;
     this.LineWidth = 1;
     this.LineColor = Color.Lime;
     this.yAxes = new YAxes();
     this.TimeDayAlign = false;
 }
Пример #7
0
        private void DrawTimeTip(Graphics g, RectangleF rect)
        {
            DateTime     time = ChartGraph.ChartTime2DateTime(this.xAxes.OriginalTime);
            StringFormat sf   = new StringFormat();

            sf.Alignment     = StringAlignment.Near;
            sf.LineAlignment = StringAlignment.Near;
            using (Font font = new Font("雅黑", 10f))
            {
                using (Brush brush = new SolidBrush(Color.FromArgb(223, 34, 39)))
                {
                    RectangleF    rectTxt = new RectangleF(rect.X + MarginLeft, rect.Bottom - MarginBottom + 5, 300, 60);
                    StringBuilder sb      = new StringBuilder(time.ToString("yyyy-MM-dd HH:mm:ss") + "    每格:");
                    if (this.xAxes.TimeScale >= LineArea.TicksPerDay)
                    {
                        sb.Append(this.xAxes.TimeScale / LineArea.TicksPerDay + "天");
                    }
                    else if (this.xAxes.TimeScale >= LineArea.TicksPerHour)
                    {
                        sb.Append(this.xAxes.TimeScale / LineArea.TicksPerHour + "小时");
                    }
                    else if (this.xAxes.TimeScale >= LineArea.TicksPerMinute)
                    {
                        sb.Append(this.xAxes.TimeScale / LineArea.TicksPerMinute + "分钟");
                    }
                    else if (this.xAxes.TimeScale >= LineArea.TicksPerSecond)
                    {
                        if (Chart.UseFineScale)
                        {
                            sb.Append((this.xAxes.TimeScale * 1d / LineArea.TicksPerSecond).ToString("0.0") + "秒");
                        }
                        else
                        {
                            sb.Append(this.xAxes.TimeScale / LineArea.TicksPerSecond + "秒");
                        }
                    }
                    else if (this.xAxes.TimeScale >= LineArea.TicksPerMiliSec)
                    {
                        sb.Append(this.xAxes.TimeScale / LineArea.TicksPerMiliSec + "毫秒");
                    }
                    else
                    {
                        sb.Append(this.xAxes.TimeScale + "微妙");
                    }


                    g.DrawString(sb.ToString(), font, brush, rectTxt, sf);
                }
            }
        }
Пример #8
0
        private string GetTimeText(long time)
        {
            XAxes xAxes = CurveGroup.XAxes;

            if (xAxes.XAxesMode == XAxesMode.Absolute)
            {
                DateTime timeTips = ChartGraph.ChartTime2DateTime(time);
                //if (xAxes.TimeScale >= TicksPerDay)
                //{
                //    return timeTips.ToString("yyyy-MM-dd");
                //}
                //else if (xAxes.TimeScale >= TicksPerHour)
                //{
                //    return timeTips.ToString("MM-dd HH:mm");
                //}
                //else
                {
                    return(timeTips.ToString("HH:mm:ss"));
                }
            }
            else if (xAxes.XAxesMode == XAxesMode.Relative)
            {
                double time1 = (double)(time - this.RelativeTime) / 1000000L;
                if (this.XFreqScale < 0)
                {
                    if (xAxes.TimeScale >= TicksPerSecond)
                    {
                        return(time1.ToString("0.000") + "秒");
                    }
                    else if (xAxes.TimeScale >= TicksPerMiliSec)
                    {
                        return((time1 * 1000).ToString("0.") + "毫秒");
                    }
                    else
                    {
                        return((time1 * 1000000).ToString("0.") + "微秒");
                    }
                }
                else
                {
                    return((time1 * 1000000 * this.XFreqScale).ToString("0.00") + "HZ");
                }
            }
            return("");
        }
Пример #9
0
 public BarCurve(ChartGraph chart, string name, int maxPointCount)
     : base(chart)
 {
     this.Name          = name;
     this.MaxPointCount = maxPointCount;
 }
Пример #10
0
        public override void DrawStage2(Graphics g, RectangleF rect)
        {
            if (!this.Visible)
            {
                return;
            }
            if (!this.CurveGroup.ShowCursor)
            {
                return;
            }
            //绘制光标
            RectangleF disRect = this.Rectangle;
            // RectangleF borderRect = new RectangleF(disRect.X, disRect.Top + CaptionHeight, disRect.Width, disRect.Height - CaptionHeight - XScaleHeight);
            RectangleF borderRect = disRect;
            Point      pCursor    = CurveGroup.CursorPoint;

            using (Pen pen = new Pen(Color.LightGray, 1))
            {
                pen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
                pen.DashPattern = new float[] { 4.5f, 4.5f };
                if ((pCursor.X >= borderRect.Left) && (pCursor.X <= borderRect.Right))
                {
                    g.DrawLine(pen, pCursor.X, borderRect.Top, pCursor.X, borderRect.Bottom);
                }
                if (pCursor.Y >= borderRect.Top && pCursor.Y <= borderRect.Bottom)
                {
                    g.DrawLine(pen, borderRect.Left, pCursor.Y, borderRect.Right, pCursor.Y);
                }
            }

            if (borderRect.Contains(pCursor))
            {
                XAxes xAxes = CurveGroup.XAxes;

                List <string> listTipsValue = new List <string>();
                List <string> listTipsTime  = new List <string>();
                List <Color>  listColor     = new List <Color>();

                long cursorTime = 0;


                if (xAxes.XAxesMode == XAxesMode.Absolute)
                {
                    long     timeAbs  = xAxes.OriginalTime + (long)((pCursor.X - borderRect.X) * xAxes.TimeScale / ScaleSize);
                    DateTime timeTips = ChartGraph.ChartTime2DateTime(timeAbs);
                    cursorTime = timeAbs;
                    if (xAxes.TimeScale >= TicksPerDay)
                    {
                        listTipsValue.Add("时间:" + timeTips.ToString("yyyy-MM-dd"));
                    }
                    else if (xAxes.TimeScale >= TicksPerHour)
                    {
                        listTipsValue.Add("时间:" + timeTips.ToString("MM-dd HH:mm"));
                    }
                    else
                    {
                        listTipsValue.Add("时间:" + timeTips.ToString("HH:mm:ss"));
                    }
                    listTipsTime.Add("");
                }
                else if (xAxes.XAxesMode == XAxesMode.Relative)
                {
                    double time = ((pCursor.X - borderRect.X) * xAxes.TimeScale / ScaleSize - (this.RelativeTime - xAxes.OriginalTime)) / 1000000L;
                    cursorTime = (long)(this.RelativeTime + (pCursor.X - borderRect.X) * xAxes.TimeScale / ScaleSize);
                    if (XFreqScale > 0)
                    {
                        {
                            listTipsValue.Add("频率:" + (time * 1000000 * XFreqScale).ToString("0.00") + "Hz");
                        }
                    }
                    else
                    {
                        if (xAxes.TimeScale >= LineArea.TicksPerSecond)
                        {
                            listTipsValue.Add("时间:" + time.ToString("0.000") + "秒");
                        }
                        else if (xAxes.TimeScale >= LineArea.TicksPerMiliSec)
                        {
                            listTipsValue.Add("时间:" + (time * 1000).ToString("0.") + "毫秒");
                        }
                        else
                        {
                            listTipsValue.Add("时间:" + (time * 1000000).ToString("0.") + "微妙");
                        }
                    }


                    listTipsTime.Add("");
                }
                listColor.Add(Color.White);
                for (int i = 0; i < lines.Count; i++)
                {
                    lines[i].CursorValue = float.NaN;
                    if (lines[i].Visible == false)
                    {
                        continue;
                    }
                    List <LinePoint> cPoints = lines[i].GetCursorPoint(false);
                    StringBuilder    sb      = new StringBuilder(lines[i].Name + ":");
                    string           timeTxt = "";
                    if (cPoints.Count == 1)
                    {
                        if (float.IsNaN(cPoints[0].Value) == false)
                        {
                            if (Math.Abs(cursorTime - cPoints[0].Time) < LineArea.TicksPerDay)
                            {
                                sb.Append(cPoints[0].Value.ToString("0.000") + (string.IsNullOrEmpty(this.YAxes.UnitString) ? lines[i].YAxes.UnitString : this.YAxes.UnitString));
                                timeTxt = (this.XFreqScale > 0 ? "频率" : "时间:") + GetTimeText(cPoints[0].Time);
                            }
                        }
                    }
                    else if (cPoints.Count > 1)
                    {
                        for (int k = 0; k < cPoints.Count; k++)
                        {
                            sb.Append("(" + (k + 1) + "):");
                            if (float.IsNaN(cPoints[k].Value) == false)
                            {
                                if (Math.Abs(cursorTime - cPoints[k].Time) < LineArea.TicksPerDay)
                                {
                                    timeTxt = (this.XFreqScale > 0?"频率": "时间:") + GetTimeText(cPoints[k].Time);
                                    sb.Append(cPoints[k].Value.ToString("0.000") + (string.IsNullOrEmpty(this.YAxes.UnitString) ? lines[i].YAxes.UnitString : this.YAxes.UnitString) + "," + timeTxt);
                                    timeTxt = "";
                                }
                            }
                        }
                    }

                    listTipsValue.Add(sb.ToString());
                    listTipsTime.Add(timeTxt);
                    listColor.Add(lines[i].LineColor);
                }



                using (Font font = new Font("雅黑", 8f))
                {
                    float txtLineHeight    = 20;
                    float txtMaxWidth      = 0;
                    float txtDateMaxWidth  = 0;
                    float txtValueMaxWidth = 0;
                    for (int i = 0; i < listTipsValue.Count; i++)
                    {
                        SizeF txtSize = g.MeasureString(listTipsValue[i], font);
                        if (txtSize.Width > txtValueMaxWidth)
                        {
                            txtValueMaxWidth = txtSize.Width;
                        }
                        txtSize = g.MeasureString(listTipsTime[i], font);
                        if (txtSize.Width > txtDateMaxWidth)
                        {
                            txtDateMaxWidth = txtSize.Width;
                        }
                    }
                    txtMaxWidth  = txtDateMaxWidth + txtValueMaxWidth;
                    txtMaxWidth += 10f;
                    RectangleF rectTxt = new RectangleF();
                    rectTxt.Width  = txtMaxWidth;
                    rectTxt.Height = listTipsValue.Count * txtLineHeight;

                    if ((pCursor.X > rect.Width / 2) && (pCursor.Y > rect.Height / 2)) //第一象限
                    {
                        rectTxt.X = pCursor.X - txtMaxWidth;
                        rectTxt.Y = pCursor.Y - txtLineHeight * listTipsValue.Count;
                    }
                    else if ((pCursor.X < rect.Width / 2) && (pCursor.Y > rect.Height / 2))
                    {
                        rectTxt.X = pCursor.X;
                        rectTxt.Y = pCursor.Y - rectTxt.Height;
                    }
                    else if ((pCursor.X < rect.Width / 2) && (pCursor.Y < rect.Height / 2))
                    {
                        rectTxt.X = pCursor.X + 12;
                        rectTxt.Y = pCursor.Y + 15;
                    }
                    else
                    {
                        rectTxt.X = pCursor.X - rectTxt.Width;
                        rectTxt.Y = pCursor.Y;
                    }


                    using (SolidBrush brush = new SolidBrush(Color.FromArgb(150, 88, 119, 211)))
                    {
                        g.FillRectangle(brush, rectTxt.X, rectTxt.Y, rectTxt.Width, rectTxt.Height);

                        for (int i = 0; i < listTipsValue.Count; i++)
                        {
                            brush.Color = listColor[i];
                            g.DrawString(listTipsValue[i], font, brush, new PointF(rectTxt.X + 5, rectTxt.Y + i * txtLineHeight));
                            if (listTipsTime[i] != "")
                            {
                                g.DrawString(listTipsTime[i], font, brush, new PointF(rectTxt.X + 5 + txtValueMaxWidth, rectTxt.Y + i * txtLineHeight));
                            }
                        }
                    }
                }
            }
        }
Пример #11
0
 public LinePoint(DateTime time, float value)
     : this(ChartGraph.DateTime2ChartTime(time), value)
 {
 }
Пример #12
0
 public BarCurve(ChartGraph chart, string name, int maxPointCount)
     : base(chart)
 {
     this.Name = name;
     this.MaxPointCount = maxPointCount;
 }
Пример #13
0
        private void DrawXScale(Graphics g, RectangleF rect, bool print)
        {
            if (this.IsFold)
            {
                return;
            }
            RectangleF disRect    = print ? this.PrintRectangle : this.Rectangle;
            RectangleF borderRect = disRect;


            long timeStart = this.CurveGroup.XAxes.OriginalTime;
            long timeScale = this.CurveGroup.XAxes.TimeScale;

            this.CurveGroup.XAxes.DisTimeLen       = (int)(rect.Width * timeScale / ScaleSize);
            this.CurveGroup.Chart.XAxes.DisTimeLen = this.CurveGroup.XAxes.DisTimeLen;

            long leftTime = timeStart % timeScale;


            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Near;
            using (Font font = new Font("雅黑", 8f))
            {
                using (SolidBrush brush = new SolidBrush(this.chart.ForeColor /*Color.FromArgb(252,210,10)*/))
                {
                    if (print)
                    {
                        brush.Color = Color.Black;
                    }
                    using (Pen pen = new Pen(this.chart.GridColor, 1f))
                    {
                        if (print)
                        {
                            pen.Color = Color.LightGray;
                        }
                        pen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
                        pen.DashPattern = new float[] { 3, 3 };


                        RectangleF rectTxt = new RectangleF(borderRect.X - 100, borderRect.Bottom - 20, 100 - 2, 40);

                        float xScale    = 0;
                        long  scaleTime = timeStart;
                        if (leftTime > 0)
                        {
                            scaleTime += (timeScale - leftTime);
                            xScale    += ((timeScale - leftTime) * ScaleSize * 1f) / timeScale;
                        }
                        long relativeTime = this.RelativeTime;
                        while (xScale < borderRect.Width)
                        {
                            g.DrawLine(pen, borderRect.X + xScale, borderRect.Top, borderRect.X + xScale, borderRect.Bottom);

                            DateTime time = ChartGraph.ChartTime2DateTime(scaleTime);
                            rectTxt = new RectangleF(borderRect.X + xScale - 50, borderRect.Bottom - 14, 100, 40);
                            if (CurveGroup.XAxes.XAxesMode == XAxesMode.Absolute)
                            {
                                if (timeScale >= TicksPerDay)
                                {
                                    g.DrawString(time.ToString("MM-dd"), font, brush, rectTxt, sf);
                                }
                                else if (timeScale >= TicksPerHour)
                                {
                                    if ((scaleTime % TicksPerDay) == 0)
                                    {
                                        g.DrawString(time.ToString("MM-dd"), font, brush, rectTxt, sf);
                                    }
                                    else
                                    {
                                        g.DrawString(time.ToString("HH"), font, brush, rectTxt, sf);
                                    }
                                }
                                else if (timeScale >= TicksPerMinute)
                                {
                                    if ((scaleTime % (TicksPerHour / 2)) == 0)
                                    {
                                        g.DrawString(time.ToString("HH:mm"), font, brush, rectTxt, sf);
                                    }
                                    else
                                    {
                                        g.DrawString(time.ToString("mm"), font, brush, rectTxt, sf);
                                    }
                                }
                                else if (timeScale >= TicksPerSecond)
                                {
                                    if ((scaleTime % TicksPerMinute) == 0)
                                    {
                                        g.DrawString(time.ToString("HH:mm"), font, brush, rectTxt, sf);
                                    }
                                    else
                                    {
                                        g.DrawString(time.ToString("ss"), font, brush, rectTxt, sf);
                                    }
                                }
                                else
                                {
                                    if ((scaleTime % TicksPerSecond) == 0)
                                    {
                                        g.DrawString(time.ToString("mm:ss.fff"), font, brush, rectTxt, sf);
                                    }
                                    else
                                    {
                                        g.DrawString(time.ToString("fff"), font, brush, rectTxt, sf);
                                    }
                                }
                            }
                            else
                            {
                                if (this.XFreqScale > 0)
                                {
                                    double relaVal = (scaleTime - relativeTime) * 1d;
                                    relaVal = relaVal * XFreqScale;
                                    g.DrawString(relaVal.ToString("0.0"), font, brush, rectTxt, sf);
                                }
                                else
                                {
                                    double relaVal = (scaleTime - relativeTime) * 1d / 1000000L;
                                    if (timeScale < 1000L)
                                    {
                                        g.DrawString((relaVal * 1000000).ToString("0."), font, brush, rectTxt, sf);
                                    }
                                    else if (timeScale < 1000L * 1000L)
                                    {
                                        g.DrawString((relaVal * 1000).ToString("0."), font, brush, rectTxt, sf);
                                    }
                                    else
                                    {
                                        if (Chart.UseFineScale)
                                        {
                                            g.DrawString(relaVal.ToString("0.0"), font, brush, rectTxt, sf);
                                        }
                                        else
                                        {
                                            g.DrawString(relaVal.ToString("0."), font, brush, rectTxt, sf);
                                        }
                                    }
                                }
                            }


                            scaleTime += timeScale;
                            xScale    += ScaleSize;
                        }
                    }
                }
            }
        }
Пример #14
0
 public MarkLine(ChartGraph chart, long timePos, int width, Color color)
 {
     this.TimePos   = timePos;
     this.LineWidth = width;
     this.LineColor = color;
 }
Пример #15
0
 public bool SetOrgTime(DateTime time)
 {
     this.SetOrgTime(ChartGraph.DateTime2ChartTime(time), 0);
     return(true);
 }
Пример #16
0
 public Curve(ChartGraph chart)
 {
     this.Chart = chart;
 }
Пример #17
0
 public Curve(ChartGraph chart)
 {
     this.Chart = chart;
 }
Пример #18
0
 public MarkLine(ChartGraph chart, long timePos, int width, Color color)
 {
     this.TimePos = timePos;
        this.LineWidth = width;
        this.LineColor = color;
 }