Exemple #1
0
        private void c1Chart1_LayoutLabels(object sender, EventArgs e)
        {
            Point p = c1Chart1.ChartArea.PlotArea.Location;

            if (c1Chart1.Legend.Visible)
            {
                c1Chart1.Legend.Location = new Point(p.X + 20, p.Y + 20);
            }

            if (c1Chart1.ChartLabels.LabelsCollection.Count > 0)
            {
                C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels[0];

                p.X += c1Chart1.ChartArea.PlotArea.Size.Width - 10;
                p.Y += c1Chart1.ChartArea.PlotArea.Size.Height / 2;

                lbl.AttachMethodData.X = p.X;
                lbl.AttachMethodData.Y = p.Y;
            }

            if (c1Chart1.ChartLabels.LabelsCollection.Count > 1)
            {
                C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels[1];

                p = c1Chart1.ChartArea.PlotArea.Location;

                p.X += c1Chart1.ChartArea.PlotArea.Size.Width / 2;
                p.Y += c1Chart1.ChartArea.PlotArea.Size.Height - 10;


                lbl.AttachMethodData.X = p.X;
                lbl.AttachMethodData.Y = p.Y;
            }
        }
Exemple #2
0
        private void AnnotateSlices(C1.Win.C1Chart.C1Chart chart)
        {
            Style s = chart.ChartLabels.DefaultLabelStyle;

            s.BackColor          = SystemColors.Info;
            s.Opaque             = true;
            s.Border.BorderStyle = BorderStyleEnum.Solid;

            ChartDataSeriesCollection series = chart.ChartGroups[0].ChartData.SeriesList;

            chart.ChartLabels.LabelsCollection.Clear();
            // Attach labels to each slice
            for (int i = 0; i < series.Count; i++)
            {
                C1.Win.C1Chart.Label label = chart.ChartLabels.LabelsCollection.AddNewLabel();
                label.Text         = String.Format("{0:C0}", series[i].Y[0]);
                label.Compass      = LabelCompassEnum.Radial;
                label.Offset       = 20;
                label.Connected    = true;
                label.Visible      = true;
                label.AttachMethod = AttachMethodEnum.DataIndex;
                AttachMethodData am = label.AttachMethodData;
                am.GroupIndex  = 0;
                am.SeriesIndex = i;
                am.PointIndex  = 0;

                series[i].Offset = 0;
            }
        }
Exemple #3
0
        // Add Chart Labels with beginning and ending dates for each data point
        // in the Gantt chart.  Labels are placed inside on the western edge.
        private void AddGanttTaskLabels(C1Chart chart, ChartDataSeriesCollection cdsc)
        {
            ChartLabels cl = chart.ChartLabels;

            cl.DefaultLabelStyle.BackColor           = Color.Transparent;
            cl.DefaultLabelStyle.GradientStyle       = GradientStyleEnum.None;
            cl.DefaultLabelStyle.ForeColor           = Color.Azure;
            cl.DefaultLabelStyle.HorizontalAlignment = AlignHorzEnum.Far;

            C1.Win.C1Chart.LabelsCollection clc = cl.LabelsCollection;
            clc.Clear();

            int slen = cdsc.Count;

            for (int s = 0; s < cdsc.Count; s++)
            {
                ChartDataSeries cds = cdsc[s];
                for (int p = 0; p < cds.Length; p++)
                {
                    C1.Win.C1Chart.Label lab   = clc.AddNewLabel();
                    DateTime             start = (DateTime)cds.Y[p];
                    DateTime             end   = (DateTime)cds.Y1[p];
                    lab.Text         = start.ToString("ddMMM") + "-" + end.ToString("ddMMM");
                    lab.AttachMethod = AttachMethodEnum.DataIndex;
                    lab.AttachMethodData.GroupIndex  = 0;
                    lab.AttachMethodData.SeriesIndex = s;
                    lab.AttachMethodData.PointIndex  = p;
                    lab.Compass = LabelCompassEnum.West;
                    lab.Offset  = 0;
                    lab.Visible = true;
                }
            }
        }
        /// <summary>
        /// Sets the labels for each slice.
        /// </summary>
        private void SetDiskLabels()
        {
            C1.Win.C1Chart.Label lbl = null;
            for (int i = 0; i < diskCount; i++)
            {
                // Add a chart label for each disk
                lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                lbl.AttachMethod             = AttachMethodEnum.Coordinate;
                lbl.Compass                  = C1.Win.C1Chart.LabelCompassEnum.South;
                lbl.Style.BackColor          = Color.Transparent;
                lbl.Style.Border.BorderStyle = C1.Win.C1Chart.BorderStyleEnum.None;
                lbl.Text    = "Drive " + arrDiskInfo[i].DeviceID.ToUpper();
                lbl.Offset  = 0;
                lbl.Visible = true;
            }

            // Add a chart label for the summary pie
            lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
            lbl.AttachMethod             = AttachMethodEnum.Coordinate;
            lbl.Compass                  = C1.Win.C1Chart.LabelCompassEnum.South;
            lbl.Style.BackColor          = Color.Transparent;
            lbl.Style.Border.BorderStyle = C1.Win.C1Chart.BorderStyleEnum.None;
            lbl.Text    = "Total";
            lbl.Offset  = 0;
            lbl.Visible = true;
        }
        void CreateLineChart(int npoints)
        {
            ChartData cd = c1Chart1.ChartGroups[0].ChartData;

            cd.SeriesList.Clear();

            ChartLabels lbls = c1Chart1.ChartLabels;

            lbls.LabelsCollection.Clear();

            int[] x = new int[npoints];
            int[] y = new int[npoints];

            ChartDataSeries ds = cd.SeriesList.AddNewSeries();

            ds.SymbolStyle.Shape = SymbolShapeEnum.None;
            ds.LineStyle.Color   = Color.Blue;

            for (int i = 0; i < npoints; i++)
            {
                x[i] = i;

                if (i == 0)
                {
                    y[i] = _rnd.Next(1000);
                }
                else
                {
                    y[i] = y[i - 1] + (_rnd.Next(1000) - 500) / 3;
                }

                if (i % 5 == 0)
                {
                    C1.Win.C1Chart.Label lbl = lbls.LabelsCollection.AddNewLabel();
                    lbl.Text = y[i].ToString();

                    lbl.AttachMethod = AttachMethodEnum.DataIndex;
                    lbl.AttachMethodData.GroupIndex  = 0;
                    lbl.AttachMethodData.SeriesIndex = 0;
                    lbl.AttachMethodData.PointIndex  = i;
                    lbl.Offset                   = 1;
                    lbl.Connected                = true;
                    lbl.Style.ForeColor          = Color.Red;
                    lbl.Style.BackColor          = Color.White;
                    lbl.Style.Border.BorderStyle = BorderStyleEnum.Solid;
                    lbl.Visible                  = true;
                }
            }

            ds.X.CopyDataIn(x);
            ds.Y.CopyDataIn(y);

            c1Chart1.ChartArea.AxisX.ScrollBar.Min     = 0;
            c1Chart1.ChartArea.AxisX.ScrollBar.Max     = 499;
            c1Chart1.ChartArea.AxisX.ScrollBar.Visible = true;

            btnArrangeLine.Enabled = true;
        }
Exemple #6
0
 private void setLabelRotationOverride(double angle)
 {
     if (c1Chart1.ChartLabels.LabelsCollection.Count > 0)
     {
         C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels[0];
         lab.RotationOverride = (int)angle;
         picSelect.Refresh();
     }
 }
 /// <summary>
 /// Builds a chart label with the specified properties.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="location"></param>
 /// <param name="compass"></param>
 private void makeLabel(string text, Point location, LabelCompassEnum compass)
 {
     C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
     lab.Style.Border.BorderStyle = BorderStyleEnum.Solid;
     lab.Text                      = text;
     lab.AttachMethod              = AttachMethodEnum.Coordinate;
     lab.AttachMethodData.X        = location.X;
     lab.AttachMethodData.Y        = location.Y;
     lab.Style.HorizontalAlignment = AlignHorzEnum.Near;
     lab.Compass                   = compass;
     lab.Visible                   = true;
 }
        /// <summary>
        /// Position the disk labels
        /// </summary>
        private void PositionDiskLabels()
        {
            if (first)
            {
                return;
            }

            for (int i = 0; i < diskCount + 1; i++)
            {
                Point p = this.GetDiskLabelPosition(i);

                C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels.LabelsCollection[i];
                lbl.AttachMethodData.X = p.X;
                lbl.AttachMethodData.Y = p.Y;
            }
        }
        /// <summary>
        /// Sets the labels for each slice.
        /// </summary>
        private void SetSizeLabels(bool create)
        {
            if (create)
            {
                // Set labels for Used Space
                for (int i = 0; i < diskCount + 1; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        ChartDataSeries series = c1Chart1.ChartGroups[0].ChartData.SeriesList[j];
                        // Add a chart label for each slice
                        C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                        lbl.AttachMethod = AttachMethodEnum.DataIndex;
                        lbl.Text         = GetSizeString((Int64)series.Y[i], this.Format);
                        if (j == 0)
                        {
                            lbl.Compass = LabelCompassEnum.North;
                        }
                        else
                        {
                            lbl.Compass = LabelCompassEnum.South;
                        }
                        lbl.Offset  = 0;
                        lbl.Visible = true;

                        AttachMethodData amd = lbl.AttachMethodData;
                        amd.GroupIndex  = 0;
                        amd.SeriesIndex = j;
                        amd.PointIndex  = i;
                    }
                }
            }
            else
            {
                for (int i = 0; i < diskCount + 1; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        ChartDataSeries series = c1Chart1.ChartGroups[0].ChartData.SeriesList[j];
                        // Add a chart label for each slice
                        C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels.LabelsCollection[diskCount + 1 + i * 2 + j];
                        lbl.Text = GetSizeString((Int64)series.Y[i], this.Format);
                    }
                }
            }
        }
Exemple #10
0
        //adds image
        private void AnnotatePie(C1.Win.C1Chart.C1Chart chart)
        {
            Style s = chart.ChartLabels.DefaultLabelStyle;

            s.Opaque             = false;
            s.Border.BorderStyle = BorderStyleEnum.None;

            C1.Win.C1Chart.Label label = chart.ChartLabels.LabelsCollection.AddNewLabel();
            label.Text         = chart.ChartGroups[0].ChartData.SeriesList[0].X[0].ToString();
            label.Compass      = LabelCompassEnum.South;
            label.Visible      = true;
            label.AttachMethod = AttachMethodEnum.Coordinate;

            PlotArea plot = chart.ChartArea.PlotArea;

            label.AttachMethodData.X = plot.Location.X;
            label.AttachMethodData.Y = plot.Location.Y + (plot.Size.Width / 2);
        }
Exemple #11
0
        private void c1Chart1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string newLabText = e.Data.GetData(DataFormats.Text).ToString();

            if (newLabText != null && newLabText.Length > 0)
            {
                // convert the event screen coords to client coords
                // of the chart object.
                Point      pnt = c1Chart1.PointToClient(new Point(e.X, e.Y));
                ChartGroup grp = c1Chart1.ChartGroups[0];
                int        s = -1, p = -1, d = -1;

                // the cursor MUST be on a bar.
                if (grp.CoordToDataIndex(pnt.X, pnt.Y, CoordinateFocusEnum.XandYCoord, ref s, ref p, ref d))
                {
                    if (s >= 0 && p >= 0 && d == 0)
                    {
                        // create the label name
                        string labName = "barLabel_" + s.ToString() + "_" + p.ToString();

                        // now get the existing label or create it if necessary
                        C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels[labName];
                        if (lab == null)
                        {
                            // create the label
                            lab              = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                            lab.Name         = labName;
                            lab.Compass      = LabelCompassEnum.East;
                            lab.Connected    = true;
                            lab.Offset       = 10;
                            lab.AttachMethod = AttachMethodEnum.DataIndex;
                            lab.AttachMethodData.GroupIndex  = 0;
                            lab.AttachMethodData.SeriesIndex = s;
                            lab.AttachMethodData.PointIndex  = p;
                            lab.Style.BackColor = Color.Transparent;
                        }
                        lab.Text    = newLabText;
                        lab.Visible = true;
                    }
                }
            }
        }
        private void SetupHistogram()
        {
            // Create a Histogram in the second chart group using the scatter data
            // and the distance from the marker intersection as data for the histogram.
            ChartGroup cg = c1Chart1.ChartGroups[1];

            // Start by adding a Normal (Gaussian) distribution curve.  This is available
            // as a convenient reference to compare the histogram shape.
            NormalCurve nc = cg.Histogram.NormalDisplay;

            nc.FillStyle.Alpha  = 64;
            nc.FillStyle.Color1 = Color.Yellow;
            nc.Visible          = chkShowNormal.Checked;

            cg.ChartType = Chart2DTypeEnum.Histogram;

            ChartDataSeries cds = cg.ChartData.SeriesList.AddNewSeries();

            cds.FitType          = FitTypeEnum.Spline;
            cds.FillStyle.Alpha  = 64;
            cds.FillStyle.Color1 = Color.Blue;

            cds.Histogram.IntervalCreationMethod = IntervalMethodEnum.SemiAutomatic;
            cds.Histogram.DisplayType            = DisplayTypeEnum.Histogram;
            cds.Histogram.IntervalStart          = 0;
            cds.Histogram.IntervalWidth          = 10;
            cds.Histogram.IntervalNumber         = 10;

            C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
            lab.AttachMethod                = AttachMethodEnum.DataCoordinate;
            lab.AttachMethodData.X          = 100;
            lab.AttachMethodData.Y          = 0;
            lab.AttachMethodData.GroupIndex = 0;
            lab.Offset  = 50;
            lab.Name    = "overflow";
            lab.Text    = "";
            lab.Compass = LabelCompassEnum.South;
            lab.Visible = true;
        }
        void CreateScatterChart(int nseries)
        {
            ChartData cd = c1Chart1.ChartGroups[0].ChartData;

            cd.SeriesList.Clear();

            ChartLabels lbls = c1Chart1.ChartLabels;

            lbls.LabelsCollection.Clear();

            for (int i = 0; i < nseries; i++)
            {
                ChartDataSeries ds = cd.SeriesList.AddNewSeries();

                ds.X.Add(_rnd.Next(100));
                ds.Y.Add(_rnd.Next(100));

                ds.SymbolStyle.Color = GetGradientColor(Color.Red, Color.Blue, i / (nseries - 1.0f));
                ds.SymbolStyle.Shape = SymbolShapeEnum.Dot;

                C1.Win.C1Chart.Label lbl = lbls.LabelsCollection.AddNewLabel();
                lbl.Text = ds.Label;

                lbl.AttachMethod = AttachMethodEnum.DataIndex;
                lbl.AttachMethodData.GroupIndex  = 0;
                lbl.AttachMethodData.SeriesIndex = i;
                lbl.AttachMethodData.PointIndex  = 0;
                lbl.Offset                   = 1;
                lbl.Connected                = true;
                lbl.Style.ForeColor          = ds.SymbolStyle.Color;
                lbl.Style.BackColor          = Color.White;
                lbl.Style.Border.BorderStyle = BorderStyleEnum.Solid;
                lbl.Visible                  = true;
            }

            c1Chart1.ChartArea.AxisX.ScrollBar.Visible = false;
            c1Chart1.ChartArea.AxisX.AutoMin           = true;
            c1Chart1.ChartArea.AxisX.AutoMax           = true;
        }
Exemple #14
0
        //set up chart labels
        private void SetUpChart()
        {
            double[] values = (double[])c1Chart1.ChartGroups.Group0.ChartData.SeriesList[0].Y.CopyDataOut();
            Array.Sort(values);

            //add the chart labels, they will be positioned later
            ChartLabels labels = c1Chart1.ChartLabels;

            labels.DefaultLabelStyle.BackColor = c1Chart1.Style.BackColor;
            labels.DefaultLabelStyle.Font      = new Font("Tahoma", 10, FontStyle.Bold);

            C1.Win.C1Chart.Label lab = null;
            for (int i = 0; i < 5; i++)
            {
                lab                 = labels.LabelsCollection.AddNewLabel();
                lab.Text            = ZoneText[i];
                lab.Size            = new Size(100, 22);
                lab.Style.BackColor = ZoneColor[i];
                lab.AttachMethod    = AttachMethodEnum.Coordinate;
                lab.Visible         = true;
            }
            PositionLegends();
        }
Exemple #15
0
        private void PositionLegends()
        {
            //reposition the legend and labels
            C1.Win.C1Chart.ChartLabels labels = c1Chart1.ChartLabels;
            if (labels == null || labels.LabelsCollection.Count < 5)
            {
                return;
            }

            c1Chart1.Update();

            PlotArea plota = c1Chart1.ChartArea.PlotArea;
            Legend   leg   = c1Chart1.Legend;

            //get left alignment with the legend, and
            //center about the plot area centerline
            Point labP = leg.Location;

            labP.Y = plota.Location.Y + plota.Size.Height / 2;

            //get the height of the labels and legend
            int labHeight = labels[0].Size.Height;
            int h         = labHeight * 5 + leg.Size.Height;

            labP.Y -= h / 2;

            for (int i = 0; i < 5; i++)
            {
                C1.Win.C1Chart.Label lab = labels[i];
                lab.AttachMethodData.X = labP.X;
                lab.AttachMethodData.Y = labP.Y;
                labP.Y += labHeight;
            }

            leg.LocationDefault = new Point(-1, labP.Y);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // Populate the Logarithmic Base combo box.	 Note that the base value
            // is the base of the log used for both axes.  It can be any double value
            // greater than zero.  "e" is interpreted as the "natural" algorithm.
            string [] strItems = new string[] { "e", "2", "3", "5", "7.5", "10", "16" };
            comboBoxLogBase.Items.AddRange(strItems);
            comboBoxLogBase.SelectedIndex = comboBoxLogBase.FindStringExact("10");

            // Populate the chart with some Power Series values as these
            // readily show logarithmic behavior.
            const int pointCount = 10;

            int[] baseValues = new int[] { 2, 4, 5, 10 };

            ChartDataSeriesCollection cdsc = c1Chart1.ChartGroups.Group0.ChartData.SeriesList;

            cdsc.RemoveAll();

            for (int bi = 0; bi < baseValues.Length; bi++)
            {
                int baseValue = baseValues[bi];

                // create the Power Series data array
                PointF[] points = new PointF[pointCount];
                for (int i = 1; i < pointCount; i++)
                {
                    points[i].X = i;
                    points[i].Y = (float)Math.Pow(baseValue, i);
                }

                // Create and add a new ChartDataSeries and copy in the data array.
                ChartDataSeries cds = cdsc.AddNewSeries();
                cds.PointData.CopyDataIn(points);
                cds.Label = "y = Math.Pow(" + baseValue.ToString() + ",x)";

                // Create a Chart Label to indicate the equation used to generate the data
                // and attach it to the series appropriately.
                C1.Win.C1Chart.ChartLabels clabs = c1Chart1.ChartLabels;
                clabs.AutoArrangement.Method = AutoLabelArrangementMethodEnum.FindingOptimum;

                C1.Win.C1Chart.Label lab = clabs.LabelsCollection.AddNewLabel();
                lab.Text         = cds.Label;
                lab.AttachMethod = AttachMethodEnum.DataIndex;
                lab.AttachMethodData.GroupIndex  = 0;
                lab.AttachMethodData.PointIndex  = pointCount / 2 + bi;
                lab.AttachMethodData.SeriesIndex = bi;
                lab.Connected = true;
                lab.Compass   = LabelCompassEnum.Auto;
                lab.Style.Border.BorderStyle = BorderStyleEnum.Solid;
                lab.Visible = true;
            }

            // set the initial Logarithmic base values for the X and Y axes.
            Area area = c1Chart1.ChartArea;

            area.AxisX.LogarithmicBase = 10;
            area.AxisX.Thickness       = 1;
            area.AxisY.LogarithmicBase = 10;
            area.AxisY.Thickness       = 1;

            // call the check box handler to set axes values appropriate for
            // log or non-log axes.
            checkLOG_CheckedChanged(checkXLOG, null);
            checkLOG_CheckedChanged(checkYLOG, null);

            // Add some cosmetic attributes
            Style style = c1Chart1.Style;

            style.BackColor           = Color.DarkRed;
            style.BackColor2          = Color.OrangeRed;
            style.GradientStyle       = GradientStyleEnum.DiagonalCenter;
            style.Border.Rounding.All = 20;

            style               = c1Chart1.ChartArea.Style;
            style.BackColor     = Color.White;
            style.GradientStyle = GradientStyleEnum.None;
        }
Exemple #17
0
        private void GetLineChart(DataTable dt, string XDataName, string[] YCols, int Groupindex)
        {
            try
            {
                DataView dv           = dt.DefaultView;
                int      countColumns = YCols.Length;     //多少列 ;第一列未x坐标值 ;其他为数据
                int      countRows    = dt.Rows.Count;

                PointF[][] data = new PointF[countColumns][]; //视图的数据

                for (int i = 0; i < countColumns; i++)
                {
                    data[i] = new PointF[countRows];
                }
                //各列对应的数据
                for (int j = 0; j < countColumns; j++)
                {
                    for (int i = 0; i < countRows; i++)
                    {
                        string data1 = dv[i][YCols[j]].ToString().Replace("天", "").Trim();
                        float  y     = 0;
                        if (!string.IsNullOrEmpty(data1))
                        {
                            y = float.Parse(data1);
                        }
                        data[j][i] = new PointF(i, y);
                    }
                }
                //绑定数据
                ChartDataSeriesCollection collSeries = c1Chart1.ChartGroups[Groupindex].ChartData.SeriesList;

                collSeries.Clear();

                for (int i = 0; i < countColumns; i++) //如果是双条,则显示
                {
                    ChartDataSeries series = collSeries.AddNewSeries();
                    series.PointData.CopyDataIn(data[i]);
                    series.FitType           = C1.Win.C1Chart.FitTypeEnum.Line;
                    series.LineStyle.Pattern = LinePatternEnum.Solid;
                    //series.Label = dt.Columns[i].ColumnName;
                }
                for (int i = 0; i < countColumns; i++) //如果是双条,则显示
                {
                    //lend,对三种颜色Bar块的描述
                    c1Chart1.ChartGroups[Groupindex].ChartData.SeriesList[i].Label = YCols[i];
                }

                ChartDataSeriesCollection dscoll = c1Chart1.ChartGroups[Groupindex].ChartData.SeriesList;                //dscoll.Remove(c1Chart1.ChartGroups[0].ChartData.SeriesList[3]);
                if (Groupindex == 0)
                {
                    c1Chart1.ChartLabels.LabelsCollection.Clear();
                }
                for (int i = 0; i < dscoll.Count; i++)
                {
                    ChartDataSeries series = dscoll[i];
                    for (int j = 0; j < dv.Count; j++)
                    {
                        //加标签,在Bar块上面显示数据
                        C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                        string data1             = dv[j][YCols[i]].ToString().Replace("天", "").Trim();
                        if (!string.IsNullOrEmpty(data1))
                        {
                            lbl.Text = string.Format("{0}", float.Parse(data1));
                        }

                        lbl.Compass = LabelCompassEnum.North;
                        //lbl.Style.BackColor = Color.Brown;
                        lbl.Style.ForeColor = Color.Blue;
                        lbl.Offset          = 10;
                        lbl.Connected       = false;
                        lbl.Visible         = true;
                        lbl.AttachMethod    = AttachMethodEnum.DataIndex;
                        AttachMethodData am = lbl.AttachMethodData;
                        am.GroupIndex  = Groupindex; //0
                        am.SeriesIndex = i;          //i
                        am.PointIndex  = j;          //0
                    }
                }
                if (Groupindex == 0)
                {
                    //显示X轴标签
                    Axis ax = c1Chart1.ChartArea.AxisX;
                    //ax.Min = 10;
                    ax.TickMinor = TickMarksEnum.None;
                    ax.ValueLabels.Clear();
                    ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;
                    for (int i = 0; i < dv.Count; i++)
                    {
                        ax.ValueLabels.Add(i, dv[i][XDataName].ToString());
                    }
                    //ax.TickLabels = TickLabelsEnum.High;
                    Axis ay = c1Chart1.ChartArea.AxisY;
                    //ay.TickMinor = TickMarksEnum.None;
                    ay.GridMajor.Visible = true;
                    ay.GridMajor.Color   = Color.White;
                    ay.Min = 0;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #18
0
        private void GetPieChart(DataTable dt, string XDataName, string[] YCols)
        {
            try
            {
                DataView   dv           = dt.DefaultView;
                int        countColumns = YCols.Length;               //多少列
                int        allNum       = 0;
                PointF[][] data         = new PointF[countColumns][]; //视图的数据

                for (int i = 0; i < countColumns; i++)
                {
                    data[i] = new PointF[dv.Count];
                }
                for (int j = 0; j < countColumns; j++)
                {
                    //各列对应的数据
                    for (int i = 0; i < dv.Count; i++)
                    {
                        float y = float.Parse((dv[i][j]).ToString());
                        data[j][i] = new PointF(i, y);
                    }
                }
                //绑定数据
                ChartDataSeriesCollection collSeries = c1Chart1.ChartGroups[0].ChartData.SeriesList;

                collSeries.Clear();
                for (int i = 0; i < countColumns; i++) //如果是双条,则显示
                {
                    ChartDataSeries series = collSeries.AddNewSeries();
                    series.PointData.CopyDataIn(data[i]);
                    //collSeries[i].LineStyle.Pattern = LinePatternEnum.DashDot;
                    series.FitType = C1.Win.C1Chart.FitTypeEnum.Beziers;
                    //series.PointData.CopyDataIn(data[i]);// 这里的data是PointF类型
                    //series.FitType = C1.Win.C1Chart.FitTypeEnum.Spline;
                    series.Label = YCols[i];
                }
                for (int i = 0; i < countColumns; i++) //如果是双条,则显示
                {
                    //lend,对三种颜色Bar块的描述
                    c1Chart1.ChartGroups[0].ChartData.SeriesList[i].Label = YCols[i];
                }
                // c1Chart1.ChartGroups[0].ChartData.SeriesList[2].Label = "英语成绩";
                //c1Chart1.ChartGroups[0].ChartData[3].LineStyle.Color = Color.LightSteelBlue;
                //c1Chart1.ChartGroups[0].ChartData[3].LineStyle.Thickness = 0;
                //c1Chart1.ChartGroups[0].ChartData.SeriesList[3].Group.Visible = true;                  //坐标上的柱被隐藏
                //c1Chart1.ChartGroups[0].ChartData.SeriesList[3].Display = SeriesDisplayEnum.Hide;
                // c1Chart1.ChartGroups[0].ChartData.SeriesList[3].Display = SeriesDisplayEnum.Exclude;

                //c1Chart1.ChartGroups[0].ChartData[3].Display = SeriesDisplayEnum.Exclude;
                //c1Chart1.Legend
                //在Bar中显示值
                ChartDataSeriesCollection dscoll = c1Chart1.ChartGroups[0].ChartData.SeriesList;
                //dscoll.Remove(c1Chart1.ChartGroups[0].ChartData.SeriesList[3]);
                c1Chart1.ChartLabels.LabelsCollection.Clear();
                for (int i = 0; i < dscoll.Count; i++)
                {
                    ChartDataSeries series = dscoll[i];
                    for (int j = 0; j < dv.Count; j++)
                    {
                        allNum = 0;
                        for (int k = 0; k < YCols.Length; k++)
                        {
                            allNum += int.Parse(dv[j][YCols[k]].ToString());
                        }
                        //加标签,在Bar块上面显示数据
                        C1.Win.C1Chart.Label lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();

                        string c1Label  = string.Format("{0}", float.Parse(dv[j][series.Label].ToString()));
                        float  labelNum = float.Parse(dv[j][series.Label].ToString());//显示的实际数值
                        lbl.Text  = series.Label;
                        lbl.Text += ":" + labelNum.ToString();
                        if (allNum != 0)
                        {
                            float percent = labelNum * 100 / allNum;
                            lbl.Text += ", " + String.Format("{0:F2} ", percent) + "%";
                        }

                        //lbl.Text = string.Format("{0}", float.Parse(dv[j][series.Label].ToString()));

                        lbl.Compass = LabelCompassEnum.Radial;
                        //lbl.Style.BackColor = Color.Brown;
                        lbl.Style.ForeColor = Color.Blue;
                        lbl.Offset          = 10;
                        lbl.Connected       = false;
                        lbl.Visible         = true;
                        lbl.AttachMethod    = AttachMethodEnum.DataIndex;
                        AttachMethodData am = lbl.AttachMethodData;
                        am.GroupIndex  = 0; //0
                        am.SeriesIndex = i; //i
                        am.PointIndex  = j; //0
                    }
                }
                //显示X轴标签
                //Axis ax = c1Chart1.ChartArea.AxisX;
                //ax.ValueLabels.Clear();
                //ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;

                //for (int i = 0; i < dv.Count; i++)
                //{
                //    //ax.ValueLabels.Add(i, dv[i]["path_code"].ToString());
                //}
                ////显示X轴标签
                //Axis ay = c1Chart1.ChartArea.AxisY;
                //ay.Text=""
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #19
0
        void SetChart(DataTable table1)
        {
            try
            {
                c1Chart1.Reset();
                c1Chart1.ChartLabels.LabelsCollection.Clear();
                c1Chart1.ChartArea.AxisX.ValueLabels.Clear();
                c1Chart1.ChartArea.AxisX.Text            = "日期";
                c1Chart1.ChartArea.AxisY.Text            = "数值";
                c1Chart1.Legend.Visible                  = false;
                c1Chart1.Legend.Orientation              = LegendOrientationEnum.Auto;
                c1Chart1.Legend.Text                     = "平均时间(分)";
                c1Chart1.Legend.Style.Border.BorderStyle = BorderStyleEnum.Solid;
                //c1Chart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.Area;
                c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear();

                if (table1 != null)
                {
                    DataTable objTable = table1;

                    if (objTable == null)
                    {
                        return;
                    }
                    //非饼图的数据加载

                    for (int j = 1; j < objTable.Columns.Count; j++)
                    {
                        //if (j > 1)
                        //    continue;

                        ChartDataSeries tval = new ChartDataSeries();
                        c1Chart1.ChartArea.AxisX.AnnoMethod = C1.Win.C1Chart.AnnotationMethodEnum.ValueLabels;
                        tval.DataLabel.Visible = true;
                        tval.Label             = objTable.Columns[j].ColumnName;
                        for (int i = 0; i < objTable.Rows.Count; i++)
                        {
                            float fvalue = 0;
                            float.TryParse(objTable.Rows[i][j].ToString(), out fvalue);
                            tval.PointData.Add(new PointF(i, fvalue));
                            #region 具体每一项的值显示
                            C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                            lab.AttachMethod = AttachMethodEnum.DataIndex;
                            AttachMethodData amd = lab.AttachMethodData;
                            amd.GroupIndex  = 0;
                            amd.PointIndex  = i;
                            amd.SeriesIndex = j - 1;                          //数据集的索引
                            lab.Text        = objTable.Rows[i][j].ToString(); //标签值
                            //lab.Visible = chklabVisable.Checked;
                            lab.Visible     = true;
                            lab.Compass     = LabelCompassEnum.NorthEast; //值显示的位置
                            lab.Connected   = false;
                            lab.Offset      = 20;                         //值显示的位置的偏移量
                            lab.TooltipText = objTable.Columns[j].ColumnName + ":" + lab.Text;
                            #endregion
                            if (j == 1)
                            {
                                //X轴中的内容标签
                                ValueLabel vlbl = new ValueLabel();
                                vlbl.NumericValue = i;
                                vlbl.Text         = objTable.Rows[i]["月份"].ToString() + "月";
                                c1Chart1.ChartArea.AxisX.ValueLabels.Add(vlbl);
                            }
                        }
                        c1Chart1.ChartGroups[0].ChartData.SeriesList.Add(tval);
                    }
                }
            }
            catch (Exception ex) { ex.Message.ToString(); }
        }
Exemple #20
0
        private void StepChart_Load(object sender, System.EventArgs e)
        {
            // position the controls
            hScrollBar1.Location = new Point(c1Chart1.Left, 0);
            vScrollBar1.Location = new Point(c1Chart1.Left - vScrollBar1.Width, hScrollBar1.Height);
            c1Chart1.Location    = new Point(hScrollBar1.Left, vScrollBar1.Top);

            // set 3D effects scrollbars visibility
            bool is3d = chkShow3D.Checked;

            vScrollBar1.Visible = is3d;
            hScrollBar1.Visible = is3d;

            // set up the charts
            ChartGroup cg = c1Chart1.ChartGroups.Group0;

            cg.Use3D = is3d;

            // ChartType is a Step chart.
            cg.ChartType = Chart2DTypeEnum.Step;

            ChartData cd = cg.ChartData;
            ChartDataSeriesCollection cdsc = cd.SeriesList;

            cdsc.Clear();                       // remove existing data.

            // create some data using this application GetData() routine
            PointF[] pfa = GetData();

            // add the data to the chart
            ChartDataSeries cds = cdsc.AddNewSeries();

            cds.PointData.CopyDataIn(pfa);
            cds.LineStyle.Thickness = 3;
            cds.TooltipText         = "Step0";
            cds.TooltipTextLegend   = "Step0 Legend";
            cds.SymbolStyle.Size    = 15;

            // add a second series using the application AdjustYValues
            // routine.  This data is similar to show behavior when
            // excluding the data holes found in the first data.
            cds = cdsc.AddNewSeries();
            cds.PointData.CopyDataIn(AdjustYValues(pfa, 1f, 2f));
            cds.LineStyle.Thickness = 3;
            cds.SymbolStyle.Size    = 15;
            cds.TooltipText         = "Step1";
            cds.TooltipTextLegend   = "Step1 Legend";
            cds.Display             = SeriesDisplayEnum.ExcludeHoles;

            // set up the 3D view object and scrollbars.  When
            // the 3D view is shown, the scrollbars can adjust
            // the angles.
            const int initialAngles = 30;
            View3D    v3d           = c1Chart1.ChartArea.PlotArea.View3D;

            v3d.Depth     = initialAngles;
            v3d.Elevation = initialAngles;
            v3d.Rotation  = initialAngles;

            hScrollBar1.Maximum = 45;
            hScrollBar1.Minimum = -45;
            hScrollBar1.Value   = -initialAngles;

            vScrollBar1.Maximum = 45;
            vScrollBar1.Minimum = -45;
            vScrollBar1.Value   = initialAngles;

            updnDepth.Value   = initialAngles;
            labDepth.Visible  = is3d;
            updnDepth.Visible = is3d;

            // in chart labels to label the scroll bars.
            C1.Win.C1Chart.LabelsCollection labs = c1Chart1.ChartLabels.LabelsCollection;
            C1.Win.C1Chart.Label            lab  = labs.AddNewLabel();
            lab.AttachMethod              = AttachMethodEnum.Coordinate;
            lab.AttachMethodData.X        = 1;
            lab.AttachMethodData.Y        = 1;
            lab.Compass                   = LabelCompassEnum.SouthEast;
            lab.SizeDefault               = new Size(c1Chart1.Size.Width, 12);
            lab.Style.HorizontalAlignment = AlignHorzEnum.Center;
            lab.Name    = "hbar";
            lab.Text    = "3D Rotation";
            lab.Visible = is3d;

            lab = labs.AddNewLabel();
            lab.AttachMethod              = AttachMethodEnum.Coordinate;
            lab.AttachMethodData.X        = 1;
            lab.AttachMethodData.Y        = 1;
            lab.Compass                   = LabelCompassEnum.SouthEast;
            lab.SizeDefault               = new Size(12, c1Chart1.Size.Height);
            lab.Style.Rotation            = RotationEnum.Rotate270;
            lab.Style.HorizontalAlignment = AlignHorzEnum.Center;
            lab.Name    = "vbar";
            lab.Text    = "3D Elevation";
            lab.Visible = is3d;

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

            header.Style.Font = new Font("Arial Black", 16);
            header.Style.Border.BorderStyle = BorderStyleEnum.Solid;
            if (is3d)
            {
                header.Text = "3D Step Chart";
            }
            else
            {
                header.Text = "2D Step Chart";
            }

            // clear the position CoordInfo label
            labCoordInfo.Text    = "";
            labCoordInfo.Visible = false;

            // force a resize to allow everything reposition.
            StepChart_Resize(null, null);
        }
        /// <summary>
        /// Handles the chart MouseDown event.  Based on the location of the click
        /// different chart dialogs are displayed.  If a property grid is desired,
        /// use the right mouse button for the click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Clicking on the individual series entries in the Legend toggles the
        /// display of the series in the PlotArea.  When hidden, the legend display
        /// is grayed to show it is hidden in the PlotArea.
        /// </remarks>
        private void c1Chart1_MouseDown(object sender, MouseEventArgs e)
        {
            ChartRegionEnum cre = c1Chart1.ChartRegionFromCoord(e.X, e.Y);

            if (cre == ChartRegionEnum.Legend)
            {
                Legend leg = c1Chart1.Legend;
                int    groupIndex = -1, seriesIndex = -1;

                if (leg.SeriesFromCoord(e.X, e.Y, ref groupIndex, ref seriesIndex))
                {
                    // Toggle chart series display by clicking on the series in the legend
                    ChartDataSeries cds = c1Chart1.ChartGroups[groupIndex].ChartData.SeriesList[seriesIndex];
                    if (cds.Display == SeriesDisplayEnum.Show)
                    {
                        cds.Display                  = SeriesDisplayEnum.Hide;
                        cds.Tag                      = new Color[] { cds.LineStyle.Color, cds.SymbolStyle.Color, cds.SymbolStyle.OutlineColor };
                        cds.LineStyle.Color          = Color.Gray;
                        cds.SymbolStyle.Color        = Color.Gray;
                        cds.SymbolStyle.OutlineColor = Color.DarkSlateGray;
                    }
                    else
                    {
                        Color[] clrs = cds.Tag as Color[];
                        cds.LineStyle.Color          = clrs[0];
                        cds.SymbolStyle.Color        = clrs[1];
                        cds.SymbolStyle.OutlineColor = clrs[2];
                        cds.Display = SeriesDisplayEnum.Show;
                    }
                }
                else
                {
                    // Show property dialog for the chart Legend, in this case when a specific series is not clicked.
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        c1Chart1.ShowProperties(PropertyPageFlags.AppearanceLegend);
                    }
                    else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                    {
                        showPropertyGridForm(c1Chart1.Legend, "Legend properties");
                    }
                }
            }

            else if (cre == ChartRegionEnum.XAxis)
            {
                // Show property dialog for the chart X Axis, including Scaling, Fonts, Colors, and annotations etc.
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    c1Chart1.ShowProperties(PropertyPageFlags.AxisXScale | PropertyPageFlags.AxisX | PropertyPageFlags.AxisXAnno);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    showPropertyGridForm(c1Chart1.ChartArea.AxisX, "X axis properties");
                }
            }

            else if (cre == ChartRegionEnum.YAxis)
            {
                // Show property dialog for the chart Y Axis, including Scaling, Fonts, Colors, and annotations etc.
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    c1Chart1.ShowProperties(PropertyPageFlags.AxisYScale | PropertyPageFlags.AxisY | PropertyPageFlags.AxisYAnno);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    showPropertyGridForm(c1Chart1.ChartArea.AxisY, "Y axis properties");
                }
            }

            else if (cre == ChartRegionEnum.Footer)
            {
                // Show property dialog for the chart Footer
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    c1Chart1.ShowProperties(PropertyPageFlags.AppearanceFooter);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    showPropertyGridForm(c1Chart1.Footer.Style, "Footer Style properties");
                }
            }

            else if (cre == ChartRegionEnum.Header)
            {
                // Show property dialog for the chart Header
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    c1Chart1.ShowProperties(PropertyPageFlags.AppearanceHeader);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    showPropertyGridForm(c1Chart1.Header.Style, "Header Style properties");
                }
            }

            else if (cre == ChartRegionEnum.PlotArea)
            {
                // Show property dialog for the chart PlotArea
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    c1Chart1.ShowProperties(PropertyPageFlags.AppearancePlotArea | PropertyPageFlags.Group0Data);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    if ((Control.ModifierKeys | Keys.Shift) == 0)
                    {
                        showPropertyGridForm(c1Chart1.ChartArea.PlotArea, "PlotArea properties");
                    }
                    else
                    {
                        showPropertyGridForm(c1Chart1.ChartGroups.Group0, "Group 0 properties");
                    }
                }
            }

            else if (cre == ChartRegionEnum.ChartLabel)
            {
                // Toggle the forecolor of the clicked label, or for right clicks,
                // show a modal form with a property page.
                int labIndex = -1;
                if (c1Chart1.ChartLabels.LabelFromCoord(e.X, e.Y, ref labIndex))
                {
                    C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels[labIndex];
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        if (lab.Style.ForeColor != Color.Red)
                        {
                            lab.Style.ForeColor = Color.Red;
                        }
                        else
                        {
                            lab.Style.ForeColor = Color.Black;
                        }
                    }
                    else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                    {
                        showPropertyGridForm(lab.Style, "Style properties for " + lab.Name);
                    }
                }
            }

            else
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    c1Chart1.ShowProperties(PropertyPageFlags.All);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    showPropertyGridForm(c1Chart1, "Chart Properties");
                }
            }
        }
        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Center the form
            this.CenterToParent();

            // All properties can be set at Design time, however
            // for instructional purposes, it is easier to see if
            // the properties are set at runtime.

            // Set up the Chart Appearance
            c1Chart1.Width                    = this.ClientSize.Width - c1Chart1.Left;
            c1Chart1.Height                   = this.ClientSize.Height;
            c1Chart1.Anchor                   = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;//!!VBPassThru
            c1Chart1.Style.BackColor          = Color.CadetBlue;
            c1Chart1.Style.Border.BorderStyle = BorderStyleEnum.InsetBevel;

            // Add in the header
            Title hdr = c1Chart1.Header;

            hdr.Text                     = "Pie Chart Stuff";
            hdr.Style.Font               = new Font("Arial Black", 16);
            hdr.Style.BackColor          = Color.Tan;
            hdr.Style.Border.BorderStyle = BorderStyleEnum.RaisedBevel;
            hdr.Style.Border.Thickness   = 4;

            // Add in the footer
            Title ftr = c1Chart1.Footer;

            ftr.Text            = "Nowhere";
            ftr.Style.Font      = new Font("Arial Narrow", 12, FontStyle.Bold);
            ftr.LocationDefault = new Point(10, -1);

            // Setup the legend.
            Legend lgd = c1Chart1.Legend;

            lgd.Compass = CompassEnum.East;
            lgd.Style.Border.BorderStyle = BorderStyleEnum.RaisedBevel;
            lgd.Style.Border.Color       = Color.CadetBlue;
            lgd.Style.Border.Thickness   = 4;
            lgd.Style.Font = new Font("Arial Narrow", 10);
            lgd.Style.HorizontalAlignment = AlignHorzEnum.Center;
            lgd.Text    = "Series";
            lgd.Visible = true;

            // Set the Chart area style.
            Area area = c1Chart1.ChartArea;

            area.Style.Border.BorderStyle = BorderStyleEnum.RaisedBevel;
            area.Style.Border.Thickness   = 4;

            // Set the default label style.  By using the default style,
            // all the labels styles can be handled uniformly
            c1Chart1.ChartLabels.DefaultLabelStyle.BackColor          = SystemColors.Info;
            c1Chart1.ChartLabels.DefaultLabelStyle.Border.BorderStyle = BorderStyleEnum.Solid;

            // Set up a Pie chart with 8 slices
            ChartGroup grp = c1Chart1.ChartGroups[0];

            grp.ChartType       = Chart2DTypeEnum.Pie;
            grp.Pie.OtherOffset = 0;
            grp.Pie.Start       = int.Parse(txtStartAngle.Text);

            // Clear existing, and add new data.
            ChartData dat = grp.ChartData;

            dat.SeriesList.Clear();

            // SliceValue is the relative value of the slice in the whole.
            // These are the Y values.
            int [] SliceValue = new int [] { 30, 18, 26, 10, 40, 26, 12, 35 };

            // Pick a nice color for each Series.
            Color [] ColorValue = new Color []
            {
                Color.Red, Color.Tan, Color.LightGreen, Color.MediumTurquoise,
                Color.Blue, Color.Magenta, Color.GreenYellow, Color.MediumBlue
            };

            for (int slice = 0; slice < SliceValue.Length; slice++)
            {
                ChartDataSeries series = dat.SeriesList.AddNewSeries();
                series.PointData.Length = 1;
                series.PointData[0]     = new PointF(1f, SliceValue[slice]);
                series.LineStyle.Color  = ColorValue[slice];
                series.Label            = slice.ToString();

                // set the DataLabel to show each value and percent of the whole
                DataLabel dlab = series.DataLabel;
                dlab.Compass                  = LabelCompassEnum.RadialText;
                dlab.Offset                   = -2;
                dlab.Text                     = "{#YVAL} ({%YVAL:0.00%})";
                dlab.Style.BackColor          = Color.Transparent;
                dlab.Style.Border.BorderStyle = BorderStyleEnum.None;
                dlab.Visible                  = radioDataLabOn.Checked;

                // Add a chart label for each slice
                C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                lab.AttachMethod = AttachMethodEnum.DataIndex;

                AttachMethodData amd = lab.AttachMethodData;
                amd.GroupIndex  = 0;
                amd.PointIndex  = 0;
                amd.SeriesIndex = slice;

                lab.Text      = "Chart Label " + slice.ToString();
                lab.Compass   = LabelCompassEnum.Radial;
                lab.Connected = true;
                lab.Offset    = 10;
                lab.Visible   = radioLabelsOn.Checked;
            }

            udDepth.Minimum   = 5;
            udDepth.Maximum   = 100;
            udDepth.Value     = 30;
            udDepth.Increment = 5;

            udElev.Minimum   = 5;
            udElev.Maximum   = 85;
            udElev.Value     = 45;
            udElev.Increment = 5;
        }
Exemple #23
0
        private void AddBarValueLabel(int x, int y, bool leftButtonDown)
        {
            const string labName = "barValueLabel";

            C1.Win.C1Chart.Label lab = null;

            if (x < 0 || y < 0)
            {
                lab = c1Chart1.ChartLabels[labName];
                if (lab != null)
                {
                    c1Chart1.ChartLabels.LabelsCollection.Remove(lab);
                    UpdateFooter();
                }
                oldSeries = -1;
                oldPoint  = -1;
                return;
            }

            int        s = -1, p = -1, d = -1;
            ChartGroup grp = c1Chart1.ChartGroups[0];

            if (grp.CoordToDataIndex(x, y, CoordinateFocusEnum.XCoord, ref s, ref p, ref d))
            {
                if (s >= 0 && p >= 0 && d == 0)
                {
                    if (leftButtonDown)
                    {
                        // if the left mouse button is down, then
                        // change the data point Y value at s & p
                        float newx = 0f, newy = 0f;
                        if (grp.CoordToDataCoord(x, y, ref newx, ref newy))
                        {
                            grp.ChartData[s].Y[p] = newy;
                        }
                    }
                    else
                    {
                        // see if it's the same as the last call.
                        if (s == oldSeries && p == oldPoint)
                        {
                            return;
                        }
                    }

                    lab = c1Chart1.ChartLabels[labName];
                    if (lab == null)
                    {
                        lab      = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                        lab.Name = labName;
                        lab.Style.Border.BorderStyle = BorderStyleEnum.None;
                        lab.Style.BackColor          = Color.Transparent;
                        lab.Compass      = LabelCompassEnum.West;
                        lab.Connected    = false;
                        lab.Offset       = 10;
                        lab.AttachMethod = AttachMethodEnum.DataIndex;
                        lab.AttachMethodData.GroupIndex  = 0;
                        lab.AttachMethodData.SeriesIndex = s;
                        lab.AttachMethodData.PointIndex  = p;
                        lab.Text    = ((float)(grp.ChartData[s].Y[p])).ToString("0.##");
                        lab.Visible = true;

                        UpdateFooter();
                    }
                    else
                    {
                        lab.AttachMethodData.SeriesIndex = s;
                        lab.AttachMethodData.PointIndex  = p;
                        lab.Text = ((float)(grp.ChartData[s].Y[p])).ToString("0.##");
                    }
                    return;
                }
            }

            AddBarValueLabel(-1, -1, false);
        }
Exemple #24
0
        private void HighlightObject(object obj)
        {
            // do nothing if still same object
            if (obj != null)
            {
                if (obj.Equals(highlightedObject))
                {
                    return;
                }
            }

            // since they are different, clear the original
            // object if it's not null
            highlightedObject = null;
            if (highlightedObjectStyle != null)
            {
                highlightedObjectStyle.BackColor = objectBackColor;
                objectBackColor        = Color.Empty;
                highlightedObjectStyle = null;
            }

            C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels[labName];
            if (lab != null)
            {
                c1Chart1.ChartLabels.LabelsCollection.Remove(lab);
            }

            if (obj == null)
            {
                UpdateFooter();
                return;
            }

            // handle the changes for the new object highlighting
            string           describe = null;
            Point            atPoint  = Point.Empty;
            LabelCompassEnum cp       = LabelCompassEnum.NorthWest;

            if (obj is Legend)
            {
                Legend leg = (Legend)obj;
                describe = " This is the Legend! ";
                atPoint  = leg.Location;
                highlightedObjectStyle = leg.Style;
            }
            else if (obj is Title)
            {
                Title t = (Title)obj;
                highlightedObjectStyle = t.Style;
                if (highlightedObjectStyle.Border.BorderStyle.Equals(BorderStyleEnum.None))
                {
                    describe   = " This is the Footer! ";
                    atPoint    = t.Location;
                    atPoint.X += t.Size.Width;
                    cp         = LabelCompassEnum.NorthEast;
                }
                else
                {
                    describe   = " This is the \nHeader! ";
                    atPoint    = t.Location;
                    atPoint.X += t.Size.Width;
                    atPoint.Y += t.Size.Height;
                    cp         = LabelCompassEnum.SouthEast;
                }
            }

            if (!atPoint.IsEmpty)
            {
                C1.Win.C1Chart.Label nl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                nl.Compass                   = cp;
                nl.Name                      = labName;
                nl.Connected                 = true;
                nl.Offset                    = 10;
                nl.AttachMethod              = AttachMethodEnum.Coordinate;
                nl.AttachMethodData.X        = atPoint.X;
                nl.AttachMethodData.Y        = atPoint.Y;
                nl.Style.BackColor           = Color.RosyBrown;
                nl.Style.Border.BorderStyle  = BorderStyleEnum.Solid;
                nl.Style.Border.Thickness    = 2;
                nl.Style.Font                = new Font(nl.Style.Font.Name, 10, FontStyle.Bold);
                nl.Style.HorizontalAlignment = AlignHorzEnum.Center;
                nl.Text                      = describe;
                nl.Visible                   = true;

                objectBackColor = highlightedObjectStyle.BackColor;
                highlightedObjectStyle.BackColor = Color.RosyBrown;
                highlightedObject = obj;
            }

            UpdateFooter();
        }
        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Size the form to fit any screen
            this.ClientSize = new Size(600, 400);

            // Center the form
            this.CenterToParent();

            // Fill the form client area with the chart
            c1Chart1.Dock = DockStyle.Fill;

            // Get the data arrays and data.
            int[] StudentScores  = this.GetStudentPointTotals();
            int[] StudentNumbers = (int[])Array.CreateInstance(typeof(int), StudentScores.Length);
            int   nStudents      = StudentScores.Length;
            int   i;

            for (i = 0; i < nStudents; i++)
            {
                StudentNumbers[i] = i;
            }

            // Get the statistics
            double mean   = FindMean(StudentScores);
            double stddev = FindStdDev(StudentScores, mean);

            // Set up the header
            c1Chart1.Header.Text       = "Student Scores and Grades";
            c1Chart1.Header.Style.Font = new Font("Tahoma", 18, FontStyle.Bold);

            // Set the background color
            c1Chart1.Style.BackColor = Color.FromArgb(128, 192, 150);

            // Clear the existing data
            c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear();

            // Add the data
            ChartData data = c1Chart1.ChartGroups[0].ChartData;
            ChartDataSeriesCollection series = data.SeriesList;

            //plot the student scores
            ChartDataSeries StuSeries = series.AddNewSeries();

            StuSeries.Label             = "raw scores";
            StuSeries.LineStyle.Pattern = LinePatternEnum.None;
            StuSeries.LineStyle.Color   = c1Chart1.Style.BackColor;
            StuSeries.SymbolStyle.Shape = SymbolShapeEnum.Star;
            StuSeries.SymbolStyle.Color = Color.DarkRed;
            StuSeries.X.CopyDataIn(StudentNumbers);
            StuSeries.Y.CopyDataIn(StudentScores);
            StuSeries = null;

            // mean + 2 s
            LinePatternEnum [] LinePatterns = new LinePatternEnum[]
            {
                LinePatternEnum.Dash, LinePatternEnum.DashDot,
                LinePatternEnum.Solid,
                LinePatternEnum.DashDotDot, LinePatternEnum.Dot
            };
            for (i = 2; i >= -2; i--)
            {
                ChartDataSeries StatSeries = series.AddNewSeries();
                double []       xd         = new double [] { 0, nStudents };
                double []       yd         = new double [] { mean + i * stddev, mean + i * stddev };

                StatSeries.X.CopyDataIn(xd);
                StatSeries.Y.CopyDataIn(yd);
                StatSeries.SymbolStyle.Shape   = SymbolShapeEnum.None;
                StatSeries.LineStyle.Pattern   = LinePatterns[i + 2];
                StatSeries.LineStyle.Color     = Color.Black;
                StatSeries.LineStyle.Thickness = 1;

                if (i > 0)
                {
                    StatSeries.Label = "m+" + i.ToString() + "s";
                }
                else if (i < 0)
                {
                    StatSeries.Label = "m" + i.ToString() + "s";
                }
                else
                {
                    StatSeries.Label = "mean";
                    StatSeries.LineStyle.Thickness = 2;
                    StatSeries.LineStyle.Pattern   = LinePatternEnum.Solid;
                }
            }

            // box the plot area
            c1Chart1.ChartArea.PlotArea.Boxed = true;

            // Show the legend
            c1Chart1.Legend.Visible = true;

            // Set the Axis titles
            c1Chart1.ChartArea.AxisX.Text = "Student Number";
            c1Chart1.ChartArea.AxisY.Text = "Student Accumulated Points";

            // sort the student scores so they can be analyzed
            Array.Sort(StudentScores);

            // Define each of the letter grades
            string [] GradeLetter = new String[] { "A", "B", "C", "D", "F" };

            // Get the bounds of each letter grade
            // At most 95% of the students will not get an A
            // At most 75% of the students will not get a B or higher
            // At most 25% of the students will not get a C or higher
            // At most 5% of the students will not get a D or higher
            int [] GradeBounds = new int[]
            {
                StudentScores[GetBoundingIndex(StudentScores, 0.95)],
                StudentScores[GetBoundingIndex(StudentScores, 0.75)],
                StudentScores[GetBoundingIndex(StudentScores, 0.25)],
                StudentScores[GetBoundingIndex(StudentScores, 0.05)]
            };

            // get the color codes for each grade
            Color [] GradeColor = new Color[]
            {
                Color.FromArgb(128, 128, 225), Color.FromArgb(128, 255, 128),
                Color.FromArgb(255, 228, 128), Color.FromArgb(55, 228, 228),
                Color.FromArgb(255, 192, 192)
            };

            // Add the chart labels.  They will be positioned later
            ChartLabels labels = c1Chart1.ChartLabels;

            labels.DefaultLabelStyle.BackColor = c1Chart1.Style.BackColor;
            labels.DefaultLabelStyle.Font      = new Font("Courier New", 16, FontStyle.Bold);

            C1.Win.C1Chart.Label lab = null;
            for (i = 0; i < 5; i++)
            {
                lab                 = labels.LabelsCollection.AddNewLabel();
                lab.Text            = GradeLetter[i];
                lab.Style.BackColor = GradeColor[i];
                lab.AttachMethod    = AttachMethodEnum.Coordinate;
                lab.Visible         = true;
            }

            // Below are calculations and settings that depend upon auto
            // positioning of the chart.  The auto positions are only
            // calculated during rendering of the chart.  Force the
            // chart to be rendered so the chart element positions are
            // calculated.

            // Force calculation of chart element positions
            c1Chart1.GetImage();

            // Add and show the alarm zones
            AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones;

            for (i = 0; i < 5; i++)
            {
                AlarmZone zone = zones.AddNewZone();

                zone.Name      = GradeLetter[i];
                zone.BackColor = GradeColor[i];

                if (i == 0)
                {
                    zone.UpperExtent = c1Chart1.ChartArea.AxisY.Max;
                }
                else
                {
                    zone.UpperExtent = zones[i - 1].LowerExtent;
                }

                if (i == 4)
                {
                    zone.LowerExtent = c1Chart1.ChartArea.AxisY.Min;
                }
                else
                {
                    zone.LowerExtent = GradeBounds[i];
                }

                zone.Visible = true;
            }

            PositionLegends();
        }