示例#1
0
文件: Basic.cs 项目: BrettJohn/CAT
        /// =======================================================================================================
        public static Xy Max(List <List <Xy> > input)
        {
            Xy     max      = new Xy(0, 0);
            double largestY = 0.0;

            foreach (List <Xy> wave in input)
            {
                foreach (Xy sample in wave)
                {
                    if (sample.Y > largestY)
                    {
                        max      = sample;
                        largestY = sample.Y;
                    }
                }
            }
            return(max);
        }
示例#2
0
文件: Graph.cs 项目: BrettJohn/CAT
        /// =======================================================================================================
        public static Chart Milliseconds(ChartData input, string title, int height = 100,
                                         double vertical_scale = 1.0, int width = 500, double interval_s = 1.0)
        {
            Chart graph = new Chart()
            {
                Name = string.IsNullOrWhiteSpace(title) ? "Graph" + GraphCounter : CAT.Simplify(title),
                Font = CAT.CATFont, Height = height, Dock = DockStyle.None, BackColor = Color.Black, ForeColor = Color.White
            };
            ChartArea chartArea = new ChartArea()
            {
                Name = "ChartArea"
            };

            graph.ChartAreas.Add(chartArea);
            Color[] linecolors = { Color.Blue, Color.Purple, Color.Green, Color.Orange, Color.Beige, Color.Pink };
            graph.ChartAreas[0].BackColor = Color.Black;
            graph.ChartAreas[0].Axes[0].MajorGrid.LineColor = Color.Yellow;
            graph.ChartAreas[0].Axes[0].MinorGrid.LineColor = Color.DimGray;
            graph.ChartAreas[0].Position.Auto            = false;
            graph.ChartAreas[0].Position.X               = 0;
            graph.ChartAreas[0].Position.Y               = 0;
            graph.ChartAreas[0].Position.Width           = 100;
            graph.ChartAreas[0].Position.Height          = 90;
            graph.ChartAreas[0].InnerPlotPosition.Auto   = false;
            graph.ChartAreas[0].InnerPlotPosition.X      = 0;
            graph.ChartAreas[0].InnerPlotPosition.Y      = 0;
            graph.ChartAreas[0].InnerPlotPosition.Width  = 100;
            graph.ChartAreas[0].InnerPlotPosition.Height = 90;


            // Lines
            List <double> newwaveX = new List <double>();
            List <double> newwaveY = new List <double>();
            int           count    = 0;

            foreach (List <Xy> xy in input.Data)
            {
                newwaveX = new List <double>();
                newwaveY = new List <double>();
                for (int i = 0; i < xy.Count; i++)
                {
                    newwaveX.Add(xy[i].X);
                    newwaveY.Add(xy[i].Y * vertical_scale);
                }
                graph.Series.Add(count.ToString());
                graph.Series[count].Points.DataBindXY(newwaveX.ToArray(), newwaveY.ToArray());
                graph.Series[count].Color             = linecolors[count];
                graph.Series[count].ChartType         = SeriesChartType.Line;
                graph.Series[count].YValueMembers     = "Y";
                graph.Series[count].XValueMember      = "X";
                graph.Series[count].IsVisibleInLegend = false;
                graph.DataBind();
                count++;
            }

            // Grids
            Xy     max       = Maths.Max(input.Data);
            double smallestx = newwaveX[0];
            double largestx  = newwaveX[newwaveX.Count - 1];

            graph.ChartAreas[0].AxisX.Minimum                 = smallestx;
            graph.ChartAreas[0].AxisX.Maximum                 = largestx;
            graph.ChartAreas[0].AxisX.MinorGrid.Interval      = interval_s;
            graph.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
            graph.ChartAreas[0].AxisX.LabelStyle.ForeColor    = Color.White;
            graph.ChartAreas[0].AxisY.Maximum                 = 0.5;
            graph.ChartAreas[0].AxisY.Minimum                 = -0.5;
            //graph.ChartAreas[0].AxisX.IsMarginVisible = true;
            //  graph.ChartAreas[0].AxisY.IsMarginVisible = false;

            // Determine graph dimensions
            string text = "";

            if (input.Type == ChartType.Time)
            {
                graph.Width = width;
                graph.ChartAreas[0].AxisX.Interval = input.Time.TimeBaseSeconds;
                //graph.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
                //graph.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                text = max.Y.ToString("F2") + " at " + (int)(max.X % (int)input.Time.TimeBaseSeconds) + "ms";
            }
            else
            {
                graph.Width = width;
                graph.ChartAreas[0].AxisX.Interval = largestx;
                // graph.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
                // graph.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                text = "";
            }
            graph.BorderlineColor = Color.White;
            graph.Titles.Add(new Title(string.IsNullOrWhiteSpace(title) ? text : title, Docking.Top, CAT.CATFont, Color.White));
            return(graph);
        }