public SimpleArrangerSample()
        {
            InitializeComponent();

            // first layer with automatic label positioning
            var arranger = new SimpleArranger();

            lbls = new ChartLabels()
            {
                LabelArranger = arranger
            };
            chart.View.Layers.Add(lbls);

            // second layer with user-movable labels
            lbls2 = new ChartLabels();
            chart.View.Layers.Add(lbls2);
            lbls2.LayoutUpdated += new EventHandler(lbls2_LayoutUpdated);

            NewData(5);

            chart.Actions.Add(new ZoomAction());
            chart.Actions.Add(new TranslateAction()
            {
                Modifiers = ModifierKeys.Shift
            });
            chart.Actions.Add(new ScaleAction()
            {
                Modifiers = ModifierKeys.Control
            });

            chart.MouseLeftButtonDown += new MouseButtonEventHandler(chart_MouseLeftButtonDown);
        }
Beispiel #2
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;
                }
            }
        }
        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;
        }
Beispiel #4
0
 private void ZoomChartLabels(ZoomBoundsInfo infos, ChartLabels labels)
 {
     if (labels == null)
     {
         return;
     }
     foreach (Label label in labels.LabelsCollection)
     {
         ZoomChartLabel(infos, label);
     }
 }
Beispiel #5
0
 private void ZoomChartLabels(ZoomFontInfo infos, ChartLabels labels)
 {
     if (labels == null)
     {
         return;
     }
     ZoomStyle(infos, labels.DefaultLabelStyle);
     foreach (Label label in labels.LabelsCollection)
     {
         ZoomChartLabel(infos, label);
     }
 }
        private void btnArrange_Click(object sender, System.EventArgs e)
        {
            c1Chart1.ChartLabels.AutoArrangement.Options = AutoLabelArrangementOptions.Default;
            c1Chart1.ChartLabels.AutoArrangement.Method  = AutoLabelArrangementMethodEnum.FindingOptimum;

            ChartLabels lbls = c1Chart1.ChartLabels;

            foreach (C1.Win.C1Chart.Label lbl in lbls.LabelsCollection)
            {
                lbl.Compass = LabelCompassEnum.Auto;
            }

            btnArrange.Enabled = false;
        }
        public DecimatingArrangerSample()
        {
            InitializeComponent();

            var arranger = new DecimatingLabelArranger();

            lbls = new ChartLabels();

            chart.View.Layers.Add(lbls);
            NewData(2);

            cbDecimation.Checked   += (s, e) => lbls.LabelArranger = arranger;
            cbDecimation.Unchecked += (s, e) => lbls.LabelArranger = null;
        }
        private void btnArrangeLine_Click(object sender, System.EventArgs e)
        {
            c1Chart1.ChartLabels.AutoArrangement.Method  = C1.Win.C1Chart.AutoLabelArrangementMethodEnum.Decimation;
            c1Chart1.ChartLabels.AutoArrangement.Options =
                AutoLabelArrangementOptions.Top | AutoLabelArrangementOptions.TopLeft |
                AutoLabelArrangementOptions.TopRight;

            ChartLabels lbls = c1Chart1.ChartLabels;

            foreach (C1.Win.C1Chart.Label lbl in lbls.LabelsCollection)
            {
                lbl.Compass = LabelCompassEnum.Auto;
            }

            btnArrangeLine.Enabled = false;
        }
        public PieArrangerSample()
        {
            InitializeComponent();

            chart.ChartType = ChartType.Pie;

            var arranger = new PieArranger();

            lbls = new ChartLabels()
            {
                LabelArranger = arranger
            };
            chart.View.Layers.Add(lbls);

            NewData();

            SizeChanged += (s, e) => lbls.EndUpdate();
        }
Beispiel #10
0
        public OptimalArrangerSample()
        {
            InitializeComponent();

            var arranger = new OptimalLabelArranger();

            lbls = new ChartLabels()
            {
                LabelArranger = arranger
            };

            chart.View.Layers.Add(lbls);
            chart.MouseLeftButtonDown += new MouseButtonEventHandler(chart_MouseLeftButtonDown);

            NewData(5);

            cbHideOutside.Checked   += (s, e) => arranger.HideLabelsOutsideBorder = true;
            cbHideOutside.Unchecked += (s, e) => arranger.HideLabelsOutsideBorder = false;
        }
        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;
        }
Beispiel #12
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();
        }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChartLabelsBuilderBase{TBuilder}" /> class.
 /// </summary>
 /// <param name="chartLabels">The labels configuration.</param>
 public ChartLabelsBuilderBase(ChartLabels chartLabels)
 {
     labels = chartLabels;
 }
        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();
        }