예제 #1
0
        public void Add(DateTime x, double y)
        {
            DateTimeInt64 t = new DateTimeInt64(x);

            XData.Add(t);
            YData.Add(y);
        }
예제 #2
0
        public void Add(DateTime x, double y)
        {
            DateTimeInt64 t = new DateTimeInt64(x);

            XData.Add(t);
            if (y.IsInfinity())
            {
                y = double.NaN;
            }
            if (y.IsNan())
            {
                ContainsNan = true;
            }
            YData.Add(y);
        }
예제 #3
0
        public string GetLabel(double value, int index, UIAxisType axisType = UIAxisType.Value)
        {
            switch (axisType)
            {
            case UIAxisType.Value:
                return(Formatter != null?Formatter?.Invoke(value, index) : value.ToString("F" + DecimalCount));

            case UIAxisType.DateTime:
                DateTimeInt64 dt = new DateTimeInt64((long)value);
                return(Formatter != null?Formatter?.Invoke(dt, index) : (DateTimeFormat.IsNullOrEmpty() ? dt.ToString() : dt.ToString(DateTimeFormat)));

            case UIAxisType.Category:
                return(Formatter != null?Formatter?.Invoke(value, index) : value.ToString("F0"));
            }

            return(value.ToString("F2"));
        }
예제 #4
0
        private void DrawAxis(Graphics g)
        {
            if (Option.Grid.LeftShow)
            {
                g.DrawLine(ForeColor, Option.Grid.Left, Option.Grid.Top, Option.Grid.Left, Height - Option.Grid.Bottom);
            }
            if (Option.Grid.TopShow)
            {
                g.DrawLine(ForeColor, Option.Grid.Left, Option.Grid.Top, Width - Option.Grid.Right, Option.Grid.Top);
            }
            if (Option.Grid.RightShow)
            {
                g.DrawLine(ForeColor, Width - Option.Grid.Right, Option.Grid.Top, Width - Option.Grid.Right, Height - Option.Grid.Bottom);
            }
            if (Option.Grid.BottomShow)
            {
                g.DrawLine(ForeColor, Option.Grid.Left, Height - Option.Grid.Bottom, Width - Option.Grid.Right, Height - Option.Grid.Bottom);
            }

            float zeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);

            if (zeroPos > Option.Grid.Top && zeroPos < Height - Option.Grid.Bottom)
            {
                if (Option.ShowZeroLine)
                {
                    g.DrawLine(ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos);
                }

                if (Option.ShowZeroValue)
                {
                    SizeF sf = g.MeasureString("0", TempFont);
                    g.DrawString("0", TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, zeroPos - sf.Height / 2.0f);
                }
            }

            if (XScale == null || YScale == null || Y2Scale == null)
            {
                return;
            }

            //X Tick
            {
                double[] XLabels = Option.XAxis.HaveCustomLabels ? Option.XAxis.CustomLabels.LabelValues() : XScale.CalcLabels();
                float[]  labels  = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);

                float xr = 0;
                for (int i = 0; i < labels.Length; i++)
                {
                    float x = labels[i];
                    if (x < Option.Grid.Left || x > Width - Option.Grid.Right)
                    {
                        continue;
                    }

                    if (Option.XAxis.AxisLabel.Show)
                    {
                        string label;
                        if (Option.XAxisType == UIAxisType.DateTime)
                        {
                            if (Option.XAxis.AxisLabel.AutoFormat)
                            {
                                label = new DateTimeInt64(XLabels[i]).ToString(XScale.Format);
                            }
                            else
                            {
                                label = new DateTimeInt64(XLabels[i]).ToString(Option.XAxis.AxisLabel.DateTimeFormat);
                            }
                        }
                        else
                        {
                            if (Option.XAxis.AxisLabel.AutoFormat)
                            {
                                label = XLabels[i].ToString(XScale.Format);
                            }
                            else
                            {
                                label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount);
                            }
                        }

                        if (Option.XAxis.HaveCustomLabels && Option.XAxis.CustomLabels.GetLabel(i).IsValid())
                        {
                            label = Option.XAxis.CustomLabels.GetLabel(i);
                        }

                        SizeF sf = g.MeasureString(label, TempFont);
                        float xx = x - sf.Width / 2.0f;

                        if (xx > xr && xx + sf.Width < Width)
                        {
                            xr = xx + sf.Width;
                            g.DrawString(label, TempFont, ForeColor, xx, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
                        }
                    }

                    if (Option.XAxis.AxisTick.Show)
                    {
                        g.DrawLine(ForeColor, x, DrawOrigin.Y, x, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
                    }

                    if (x.Equals(DrawOrigin.X))
                    {
                        continue;
                    }
                    if (x.Equals(DrawOrigin.X + DrawSize.Width))
                    {
                        continue;
                    }

                    if (Option.XAxis.ShowGridLine)
                    {
                        using (Pen pn = new Pen(ForeColor))
                        {
                            pn.DashStyle   = DashStyle.Dash;
                            pn.DashPattern = new float[] { 3, 3 };
                            g.DrawLine(pn, x, DrawOrigin.Y, x, Option.Grid.Top);
                        }
                    }
                }

                SizeF sfName = g.MeasureString(Option.XAxis.Name, TempFont);
                g.DrawString(Option.XAxis.Name, TempFont, ForeColor,
                             DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f,
                             DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfName.Height);
            }

            //Y Tick
            {
                double[] YLabels  = Option.YAxis.HaveCustomLabels ? Option.YAxis.CustomLabels.LabelValues() : YScale.CalcLabels();
                float[]  labels   = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height);
                float    widthMax = 0;
                for (int i = 0; i < labels.Length; i++)
                {
                    float y = labels[i];
                    if (y < Option.Grid.Top || y > Height - Option.Grid.Bottom)
                    {
                        continue;
                    }

                    string label = YLabels[i].ToString(YScale.Format);
                    SizeF  sf    = g.MeasureString(label, TempFont);
                    widthMax = Math.Max(widthMax, sf.Width);

                    if (Option.YAxis.AxisLabel.Show)
                    {
                        g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
                    }

                    if (Option.YAxis.AxisTick.Show)
                    {
                        g.DrawLine(ForeColor, DrawOrigin.X, y, DrawOrigin.X - Option.YAxis.AxisTick.Length, y);
                    }

                    if (y.Equals(DrawOrigin.Y))
                    {
                        continue;
                    }
                    if (y.Equals(DrawOrigin.X - DrawSize.Height))
                    {
                        continue;
                    }

                    if (Option.YAxis.ShowGridLine)
                    {
                        using (Pen pn = new Pen(ForeColor))
                        {
                            pn.DashStyle   = DashStyle.Dash;
                            pn.DashPattern = new float[] { 3, 3 };
                            g.DrawLine(pn, DrawOrigin.X, y, Width - Option.Grid.Right, y);
                        }
                    }
                }

                SizeF sfName = g.MeasureString(Option.YAxis.Name, TempFont);
                float xx     = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f;
                float yy     = Option.Grid.Top + DrawSize.Height / 2.0f;
                g.DrawStringRotateAtCenter(Option.YAxis.Name, TempFont, ForeColor, new PointF(xx, yy), 270);
            }

            //Y2 Tick
            if (Option.HaveY2)
            {
                double[] Y2Labels = Option.Y2Axis.HaveCustomLabels ? Option.Y2Axis.CustomLabels.LabelValues() : Y2Scale.CalcLabels();
                float[]  labels   = Y2Scale.CalcYPixels(Y2Labels, DrawOrigin.Y, DrawSize.Height);
                float    widthMax = 0;
                for (int i = 0; i < labels.Length; i++)
                {
                    float y = labels[i];
                    if (y < Option.Grid.Top || y > Height - Option.Grid.Bottom)
                    {
                        continue;
                    }

                    if (Option.Y2Axis.AxisLabel.Show)
                    {
                        string label = Y2Labels[i].ToString(Y2Scale.Format);
                        SizeF  sf    = g.MeasureString(label, TempFont);
                        widthMax = Math.Max(widthMax, sf.Width);
                        g.DrawString(label, TempFont, ForeColor, Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length, y - sf.Height / 2.0f);
                    }

                    if (Option.Y2Axis.AxisTick.Show)
                    {
                        g.DrawLine(ForeColor, Width - Option.Grid.Right, y, Width - Option.Grid.Right + Option.YAxis.AxisTick.Length, y);
                    }

                    if (y.Equals(DrawOrigin.Y))
                    {
                        continue;
                    }
                    if (y.Equals(DrawOrigin.X - DrawSize.Height))
                    {
                        continue;
                    }

                    using (Pen pn = new Pen(ForeColor))
                    {
                        pn.DashStyle   = DashStyle.Dash;
                        pn.DashPattern = new float[] { 3, 3 };
                        //g.DrawLine(pn, DrawOrigin.X, y, Width - Option.Grid.Right, y);
                    }
                }

                SizeF sfName = g.MeasureString(Option.Y2Axis.Name, TempFont);
                float xx     = Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length + widthMax + sfName.Height / 2.0f;
                float yy     = Option.Grid.Top + DrawSize.Height / 2.0f;
                g.DrawStringRotateAtCenter(Option.Y2Axis.Name, TempFont, ForeColor, new PointF(xx, yy), 90);
            }
        }
예제 #5
0
        private void DrawAxis(Graphics g)
        {
            g.DrawRectangle(ChartStyle.ForeColor, Option.Grid.Left, Option.Grid.Top, DrawSize.Width, DrawSize.Height);
            float zeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);

            g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos);
            if (XScale == null || YScale == null)
            {
                return;
            }

            //X Tick
            if (Option.XAxis.AxisTick.Show)
            {
                float[] labels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);
                for (int i = 0; i < labels.Length; i++)
                {
                    float x = labels[i];
                    if (Option.XAxis.AxisLabel.Show)
                    {
                        string label;
                        if (Option.XAxisType == UIAxisType.DateTime)
                        {
                            if (Option.XAxis.AxisLabel.AutoFormat)
                            {
                                label = new DateTimeInt64(XLabels[i]).ToString(XScale.Format);
                            }
                            else
                            {
                                label = new DateTimeInt64(XLabels[i]).ToString(Option.XAxis.AxisLabel.DateTimeFormat);
                            }
                        }
                        else
                        {
                            if (Option.XAxis.AxisLabel.AutoFormat)
                            {
                                label = XLabels[i].ToString(XScale.Format);
                            }
                            else
                            {
                                label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount);
                            }
                        }

                        SizeF sf = g.MeasureString(label, SubFont);
                        g.DrawString(label, SubFont, ChartStyle.ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
                    }

                    if (x.Equals(DrawOrigin.X))
                    {
                        continue;
                    }
                    if (x.Equals(DrawOrigin.X + DrawSize.Width))
                    {
                        continue;
                    }

                    using (Pen pn = new Pen(ChartStyle.ForeColor))
                    {
                        pn.DashStyle   = DashStyle.Dash;
                        pn.DashPattern = new float[] { 3, 3 };
                        g.DrawLine(pn, x, DrawOrigin.Y, x, Option.Grid.Top);
                    }
                }

                SizeF sfName = g.MeasureString(Option.XAxis.Name, SubFont);
                g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor,
                             DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f,
                             DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfName.Height);
            }

            //Y Tick
            if (Option.YAxis.AxisTick.Show)
            {
                float[] labels   = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height);
                float   widthMax = 0;
                for (int i = 0; i < labels.Length; i++)
                {
                    float y = labels[i];
                    if (Option.YAxis.AxisLabel.Show)
                    {
                        string label = YLabels[i].ToString(YScale.Format);
                        SizeF  sf    = g.MeasureString(label, SubFont);
                        widthMax = Math.Max(widthMax, sf.Width);
                        g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
                    }

                    if (y.Equals(DrawOrigin.Y))
                    {
                        continue;
                    }
                    if (y.Equals(DrawOrigin.X - DrawSize.Height))
                    {
                        continue;
                    }

                    using (Pen pn = new Pen(ChartStyle.ForeColor))
                    {
                        pn.DashStyle   = DashStyle.Dash;
                        pn.DashPattern = new float[] { 3, 3 };
                        g.DrawLine(pn, DrawOrigin.X, y, Width - Option.Grid.Right, y);
                    }
                }


                SizeF sfName = g.MeasureString(Option.YAxis.Name, SubFont);
                int   xx     = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height);
                int   yy     = (int)(Option.Grid.Top + (DrawSize.Height - sfName.Width) / 2);
                g.DrawString(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(xx, yy),
                             new StringFormat()
                {
                    Alignment = StringAlignment.Center
                }, 270);
            }
        }
예제 #6
0
파일: UIOption.cs 프로젝트: yhuse/SunnyUI
 public UIScaleLine(string name, DateTime value, Color color)
 {
     Name  = name;
     Color = color;
     Value = new DateTimeInt64(value);
 }