示例#1
0
        /// <summary>
        /// Converts movements to a graphical line and polygon
        /// </summary>
        /// <param name="results"></param>
        /// <param name="color"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public static LineAndPolygon ConvertResultsToMovementLineAndPolygon(float[] results, Color color, string label)
        {
            // Create the Line
            ChartPrimitive chartLine = new ChartPrimitive();

            chartLine.Color        = color;
            chartLine.Label        = label;
            chartLine.ShowInLegend = true;
            chartLine.HitTest      = true;

            for (int monthNo = 0; monthNo < results.Length; ++monthNo)
            {
                chartLine.AddSmoothHorizontalBar(new Point(monthNo + .5f, results[monthNo]));
            }

            // Create the polygon
            ChartPrimitive polygon = ChartUtilities.ChartLineToBaseLinedPolygon(chartLine);

            color.A              = (byte)(alpha * color.A);
            polygon.Color        = color;
            polygon.ShowInLegend = false;
            polygon.HitTest      = false;

            return(new LineAndPolygon(chartLine, polygon));
        }
示例#2
0
        }        //GetPlotRectangle

        /// <summary>
        /// Converts a ChartLine object to a ChartPolygon object that has
        /// one edge along the bottom Horizontal base line in the plot.
        /// </summary>
        /// <param name="chartLine"></param>
        /// <returns></returns>
        public static ChartPrimitive ChartLineToBaseLinedPolygon(ChartPrimitive chartLine)
        {
            ChartPrimitive chartPolygon = chartLine.Clone();

            Point firstPoint = chartPolygon.Points[0];

            firstPoint.Y = 0;
            Point lastPoint = chartPolygon.Points[chartPolygon.Points.Count - 1];

            lastPoint.Y = 0;

            chartPolygon.InsertPoint(firstPoint, null, 0);
            chartPolygon.AddPoint(lastPoint);
            chartPolygon.Filled = true;

            return(chartPolygon);
        }
示例#3
0
 /// <summary>
 /// Copy constructor. Deep copies the ChartPrimitive passed in.
 /// </summary>
 /// <param name="chartPrimitive"></param>
 protected ChartPrimitive(ChartPrimitive chartPrimitive) : this()
 {
     points.AddRange(chartPrimitive.Points);
     foreach (KeyValuePair <Point, object> dataObject in chartPrimitive.pointsData)
     {
         pointsData[dataObject.Key] = dataObject.Value;
     }
     minPoint      = chartPrimitive.MinPoint;
     maxPoint      = chartPrimitive.MaxPoint;
     color         = chartPrimitive.Color;
     label         = chartPrimitive.Label;
     lastPoint     = chartPrimitive.lastPoint;
     filled        = chartPrimitive.Filled;
     showInLegend  = chartPrimitive.ShowInLegend;
     hitTest       = chartPrimitive.HitTest;
     lineThickness = chartPrimitive.LineThickness;
     paths         = chartPrimitive.paths.Clone();
 }
示例#4
0
        /// <summary>
        /// Takes two lines and creates a polyon between them
        /// </summary>
        /// <param name="baseLine"></param>
        /// <param name="topLine"></param>
        /// <returns></returns>
        public static ChartPrimitive LineDiffToPolygon(ChartPrimitive baseLine, ChartPrimitive topLine)
        {
            ChartPrimitive polygon        = new ChartPrimitive();
            List <Point>   baseLinePoints = baseLine.Points;
            List <Point>   topLinePoints  = topLine.Points;

            for (int pointNo = baseLinePoints.Count - 1; pointNo >= 0; --pointNo)
            {
                polygon.AddPoint(baseLinePoints[pointNo]);
            }
            for (int pointNo = 0; pointNo < topLinePoints.Count; ++pointNo)
            {
                polygon.AddPoint(topLinePoints[pointNo]);
            }

            polygon.Filled = true;

            return(polygon);
        }
示例#5
0
        /// <summary>
        /// Gets ChartLines and ChartPolygons for the population line, and
        /// the target line.
        /// </summary>
        public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartPrimitive populationLine, float[] results, Color color, string label)
        {
            // Calculate Target Primitives
            ChartPrimitive targetLine = new ChartPrimitive();

            targetLine.Color        = color;
            targetLine.Dashed       = true;
            targetLine.Label        = label + " Target";
            targetLine.ShowInLegend = false;
            targetLine.HitTest      = true;

            if (populationLine.Points.Count == results.Length)
            {
                for (int monthNo = 0; monthNo < results.Length; monthNo += 2)
                {
                    targetLine.AddPoint(new Point(monthNo * .5f, results[monthNo]));
                    targetLine.AddPoint(new Point(monthNo * .5f + 1f, results[monthNo + 1]));
                }
            }
            else
            {
                for (int monthNo = 0; monthNo < results.Length; ++monthNo)
                {
                    targetLine.AddPoint(new Point(monthNo, results[monthNo]));
                    targetLine.AddPoint(new Point(monthNo + 1f, results[monthNo]));
                }
            }

            ChartPrimitive targetPolygon = ChartUtilities.LineDiffToPolygon(populationLine, targetLine);

            color.A                    = (byte)(alpha * color.A);
            targetPolygon.Color        = color;
            targetPolygon.Dashed       = true;
            targetPolygon.ShowInLegend = false;
            targetLine.HitTest         = false;

            return(new LineAndPolygon(targetLine, targetPolygon));
        }
示例#6
0
        /// <summary>
        /// Converts population level to a line and polygon
        /// </summary>
        /// <param name="results"></param>
        /// <param name="color"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(float[] results, Color color, string label)
        {
            ChartPrimitive populationLine = new ChartPrimitive();

            populationLine.Color        = color;
            populationLine.Label        = label;
            populationLine.ShowInLegend = true;
            populationLine.HitTest      = true;

            for (int monthNo = 0; monthNo < results.Length; monthNo += 2)
            {
                populationLine.AddPoint(new Point(monthNo * .5f, results[monthNo]));
                populationLine.AddPoint(new Point(monthNo * .5f + 1f, results[monthNo + 1]));
            }

            ChartPrimitive populationPolygon = ChartUtilities.ChartLineToBaseLinedPolygon(populationLine);

            color.A = (byte)(alpha * color.A);
            populationPolygon.Color        = color;
            populationPolygon.ShowInLegend = false;
            populationPolygon.HitTest      = false;

            return(new LineAndPolygon(populationLine, populationPolygon));
        }
示例#7
0
        /// <summary>
        /// Adds a set of lines to the chart for test purposes
        /// </summary>
        /// <param name="xyLineChart"></param>
        public static void AddTestLines(XYLineChart xyLineChart)
        {
            // Add test Lines to demonstrate the control

            xyLineChart.Primitives.Clear();

            double limit     = 5;
            double increment = 1;

            // Create 3 normal lines
            ChartPrimitive[] lines = new ChartPrimitive[3];

            //for (int lineNo = 0; lineNo < 3; ++lineNo)
            //{
            //    ChartPrimitive line = new ChartPrimitive();

            //    // Label the lines
            //    line.Filled = true;
            //    line.Dashed = false;
            //    line.ShowInLegend = false;
            //    line.AddPoint(0, 0);

            //    // Draw 3 sine curves
            //    for (double x = 0; x < limit + increment*.5; x += increment)
            //    {
            //        line.AddPoint(x, Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5));
            //    }
            //    line.AddPoint(limit, 0);

            //    // Add the lines to the chart
            //    xyLineChart.Primitives.Add(line);
            //    lines[lineNo] = line;
            //}

            //// Set the line colors to Red, Green, and Blue
            //lines[0].Color = Color.FromArgb(90,255,0,0);
            //lines[1].Color = Color.FromArgb(90, 0, 180, 0);
            //lines[2].Color = Color.FromArgb(90, 0, 0, 255);

            for (int lineNo = 0; lineNo < 3; ++lineNo)
            {
                ChartPrimitive line = new ChartPrimitive();

                // Label the lines
                line.Label = "Test Line " + (lineNo + 1);
                //line.ShowInLegend = true;
                //line.HitTest = true;

                line.LineThickness = 1.5;
                // Draw 3 sine curves
                DateTime date = DateTime.Now;
                int      i    = 0;
                for (double x = 0; x < limit + increment * .5; x += increment)
                {
                    line.AddPoint(date.Add(new TimeSpan(0, i++, 0)).Ticks, -2 * Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5));
                }

                // Add the lines to the chart
                xyLineChart.Primitives.Add(line);
                lines[lineNo] = line;
            }
            // Set the line colors to Red, Green, and Blue
            lines[0].Color = Colors.Red;
            lines[1].Color = Colors.Green;
            lines[2].Color = Colors.Blue;

            xyLineChart.Title      = "Test Chart Title";
            xyLineChart.XAxisLabel = "Test Chart X Axis";
            xyLineChart.YAxisLabel = "Test Chart Y Axis";

            xyLineChart.RedrawPlotLines();
        }