private void ValueLabelChangedHandler(object sender, EventArgs e)
        {
            ValueLabelsCollection vls = c1Chart1.ChartArea.AxisX.ValueLabels;
            string minMarker = "M1", maxMarker = "M2";

            if (vls["M1"].NumericValue > vls["M2"].NumericValue)
            {
                minMarker = "M2";  maxMarker = "M1";
            }

            float minValue = (float)vls[minMarker].NumericValue;
            float maxValue = (float)vls[maxMarker].NumericValue;

            string    name = (string)zoneSelect.Items[3];
            AlarmZone az   = c1Chart1.ChartArea.PlotArea.AlarmZones[name];

            int             gi  = az.GroupIndex;
            int             si  = az.PolygonData.SeriesIndex;
            ChartGroup      cg  = c1Chart1.ChartGroups[gi];
            ChartDataSeries cds = cg.ChartData.SeriesList[si];

            PointF[] pfs = (PointF[])cds.PointData.CopyDataOut();
            int      pmin = -1, pmax = -1;
            float    minY = float.MaxValue, maxY = float.MinValue;

            for (int p = 0; p < pfs.Length; p++)
            {
                if (pmin < 0 && pfs[p].X >= minValue)
                {
                    pmin = p;
                }

                if (pmax < 0 && pfs[p].X >= maxValue)
                {
                    pmax = (pfs[p].X == maxValue) ? p :  p - 1;
                    break;
                }

                if (pmin >= 0)
                {
                    if (pfs[p].Y < minY)
                    {
                        minY = pfs[p].Y;
                    }
                    if (pfs[p].Y > maxY)
                    {
                        maxY = pfs[p].Y;
                    }
                }
            }

            az.NearExtent  = pfs[pmin].X;
            az.FarExtent   = pfs[pmax].X;
            az.UpperExtent = maxY;
            az.LowerExtent = minY;
        }
Example #2
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            // center the form.
            this.CenterToParent();

            // setup the chart to fill the form, then set the appearance.
            c1Chart1.Dock = DockStyle.Fill;

            // set the chart itself
            c1Chart1.Style.BackColor          = Color.LightBlue;
            c1Chart1.Style.Border.BorderStyle = BorderStyleEnum.InsetBevel;
            c1Chart1.Style.Border.Thickness   = 4;

            // set up the area
            Area area = c1Chart1.ChartArea;

            area.Style.BackColor          = Color.LightYellow;
            area.Style.Border.BorderStyle = BorderStyleEnum.InsetBevel;
            area.Style.Border.Thickness   = 4;

            // set up the plot area
            PlotArea parea = area.PlotArea;

            parea.BackColor = Color.AntiqueWhite;

            // set up the header
            Title hdr = c1Chart1.Header;

            hdr.Text       = "Radar Chart for System Adaptability";
            hdr.Style.Font = new Font("Arial Black", 14);
            hdr.Style.Border.BorderStyle = BorderStyleEnum.Raised;
            hdr.Style.Border.Color       = Color.PaleTurquoise;

            // set up the Legend
            Legend leg = c1Chart1.Legend;

            leg.Style.Font               = new Font("Arial Narrow", 9);
            leg.Style.BackColor          = Color.AntiqueWhite;
            leg.Style.Border.BorderStyle = BorderStyleEnum.Raised;
            leg.Visible = true;

            // set up axes
            Axis ax = area.AxisX;

            ax.AnnoMethod        = AnnotationMethodEnum.ValueLabels;
            ax.Font              = new Font("Arial", 10);
            ax.Reversed          = true;
            ax.Thickness         = 0;
            ax.GridMajor.Color   = Color.Black;
            ax.GridMajor.Pattern = LinePatternEnum.Dot;
            ax.GridMajor.Visible = true;

            // set the chart type to radar and add the data
            ChartGroup grp = c1Chart1.ChartGroups[0];

            grp.ChartType = Chart2DTypeEnum.Radar;

            // set the axis information.  Not that the compass
            // information is limited by the chart type, so it is
            // necessary to set the chart type first.
            Axis ay = area.AxisY;

            ay.GridMajor.Color   = Color.Black;
            ay.GridMajor.Pattern = LinePatternEnum.Dot;
            ay.GridMajor.Visible = true;
            ay.Compass           = CompassEnum.North;

            ChartDataSeriesCollection series = grp.ChartData.SeriesList;

            series.Clear();

            // there will be 3 new series, all with the same 7 x values:
            int []   x  = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            float [] y0 = new float[] { 2.8f, 3.5f, 3.3f, 2f, 4f, 3f, 2.9f };
            float [] y1 = new float[] { 3.2f, 3.3f, 3.5f, 2.4f, 3.8f, 3.4f, 4.2f };
            float [] y2 = new float[] { 3.6f, 5f, 3.3f, 5f, 3.6f, 4.3f, 3.8f };

            // series 0
            ChartDataSeries s = series.AddNewSeries();

            s.X.CopyDataIn(x);
            s.Y.CopyDataIn(y0);
            s.LineStyle.Color = Color.Orange;
            s.Label           = "New Transport";

            // series 1
            s = series.AddNewSeries();
            s.X.CopyDataIn(x);
            s.Y.CopyDataIn(y1);
            s.LineStyle.Color = Color.Blue;
            s.Label           = "OTIS";

            // series 2
            s = series.AddNewSeries();
            s.X.CopyDataIn(x);
            s.Y.CopyDataIn(y2);
            s.LineStyle.Color = Color.Green;
            s.Label           = "Mobile Walk";

            // add in the value labels for the x axis.
            ValueLabelsCollection vlabs = ax.ValueLabels;

            vlabs.Add(x[0], "Introduce");
            vlabs.Add(x[1], "Response");
            vlabs.Add(x[2], "Travel Time");
            vlabs.Add(x[3], "Get On/Off");
            vlabs.Add(x[4], "Comfort");
            vlabs.Add(x[5], "Social");
            vlabs.Add(x[6], "Operate");
        }