Helper class that creates a histogram chart. Histogram is a data distribution chart which shows how many values, from the data series, are inside each segment interval. You can define how many intervals you want to have using the SegmentIntervalNumber field or the exact length of the interval using the SegmentIntervalWidth field. Actual segment interval number can be slightly different due to the automatic interval rounding.
Example #1
1
        private void UpdateChartSettings()
        {
            if(!this.loadingData)
            {
                // Create a histogram series
                HistogramChartHelper histogramHelper = new HistogramChartHelper();
                histogramHelper.SegmentIntervalNumber = int.Parse(comboBoxIntervalNumber.Text);
                histogramHelper.ShowPercentOnSecondaryYAxis = checkBoxShowPercents.Checked;
                // NOTE: Interval width may be specified instead of interval number
                //histogramHelper.SegmentIntervalWidth = 15;
                histogramHelper.CreateHistogram(chart1, "RawData", "Histogram");

                // Set same X axis scale and interval in the single axis data distribution
                // chart area as in the histogram chart area.
                chart1.ChartAreas["Default"].AxisX.Minimum = chart1.ChartAreas["HistogramArea"].AxisX.Minimum;
                chart1.ChartAreas["Default"].AxisX.Maximum = chart1.ChartAreas["HistogramArea"].AxisX.Maximum;
                chart1.ChartAreas["Default"].AxisX.Interval = chart1.ChartAreas["HistogramArea"].AxisX.Interval;
            }
        }
Example #2
1
        private void button1_Click(object sender, EventArgs e)
        {
            Random r = new Random(DateTime.Now.Millisecond);
            double aleatorio = 0;

            chart1.Series.Clear();
            chart1.ChartAreas.Clear();

            textBox5.Enabled = true;
            textBox5.Text = "";

            try
            {

            //Captura de indicaciones del usuario
            int numero_aleatorios = Convert.ToInt16(textBox10.Text);

            //Indicar el tamaño máximo de la barra de seguimiento
            progressBar1.Maximum = numero_aleatorios;
            progressBar1.Value = 0;

            //Captura de datos sobre Ley de Funcionamiento
            string Ley_Funcionamiento = comboBox1.Text;
            double parametro1 = Convert.ToDouble(textBox1.Text);
            double parametro2 = Convert.ToDouble(textBox2.Text);
            double Minimo_Admisible = Convert.ToDouble(textBox3.Text);
            double Maximo_Admisible = Convert.ToDouble(textBox4.Text);

              //Control de los valores maximos y minimos introducidos

              if(ChequeoTextboxNumeosAleatorios(comboBox1, textBox1, textBox2, textBox3, textBox4)==0)
              //lanzamos la simulación
               {
            chart1.ChartAreas.Add("ChartArea1");
            chart1.Series.Add("Datos");

            for (int i = 1; i <= numero_aleatorios; i++)
            {
                //Generar los numeros aleatorios
                if (Ley_Funcionamiento == "Uniforme") aleatorio = GeneradoresDeAleatorios.Generador_Aleatorio_Uniforme(Minimo_Admisible, Maximo_Admisible, r);
                if (Ley_Funcionamiento == "Exponencial") aleatorio = GeneradoresDeAleatorios.Generador_Aleatorio_Exponencial(parametro1, 1/parametro2, Minimo_Admisible, Maximo_Admisible, r);
                if (Ley_Funcionamiento == "Weibull") aleatorio = GeneradoresDeAleatorios.Generador_Aleatorio_Weibull_2P(parametro1, parametro2, Minimo_Admisible, Maximo_Admisible, r);
                if (Ley_Funcionamiento == "Normal") aleatorio = GeneradoresDeAleatorios.Generador_Aleatorio_Normal(parametro1, parametro2, Minimo_Admisible, Maximo_Admisible, r);

                chart1.Series["Datos"].Points.AddY(aleatorio);

                //Presentar los resultados numéricos en el TextBox de pantalla
                textBox5.Text += Convert.ToString(i) + "     " + Convert.ToString(aleatorio) + "\r\n";

                //Incrementar la barra indicadora
                progressBar1.Increment(1);

            }

            HistogramChartHelper histo = new HistogramChartHelper();

            // Show the percent frequency on the right Y axis.
            histo.ShowPercentOnSecondaryYAxis = true;

            // Specify number of segment intervals
            histo.SegmentIntervalNumber = 10;

            // Or you can specify the exact length of the interval
            // histogramHelper.SegmentIntervalWidth = 15;

            // Create histogram series
            histo.CreateHistogram(chart1, "Datos", "Histogram");

               }
            }
            catch
            {
                MessageBox.Show("Se ha producido un error en los datos de entrada", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }