示例#1
0
        /// <summary>
        /// Obtener los gráficos de tipo Historigrama ligados a un reporte.
        /// </summary>
        /// <param name="r">Reporte para el cual se busca obtener los gráficos ligados al mismo</param>
        public void obtenerGraficosHistograma(ref Reporte r)
        {
            SqlDataReader datareader = null;
            SqlCommand    comando    = _manejador.obtenerProcedimiento("SelectGraficosHistograma");

            _manejador.agregarParametro(comando, "@reporte", r.ID, SqlDbType.TinyInt);

            try
            {
                datareader = _manejador.ejecutarConsultaDatos(comando);

                while (datareader.Read())
                {
                    short  id            = (short)datareader["pk_ID"];
                    string nombre        = (string)datareader["Nombre"];
                    string descripcion   = (string)datareader["Descripcion"];
                    string procedimiento = (string)datareader["Procedimiento"];
                    string campo_y       = (string)datareader["Campo_Y"];
                    string serie         = (string)datareader["Serie"];

                    GraficoHistograma grafico = new GraficoHistograma(id, nombre, descripcion, procedimiento, campo_y, serie);
                    r.agregarGrafico(grafico);
                }

                comando.Connection.Close();
            }
            catch (Exception)
            {
                comando.Connection.Close();
                throw new Excepcion("ErrorDatosConexion");
            }
        }
示例#2
0
        /// <summary>
        /// Crear un gráfico de tipo Histograma.
        /// </summary>
        private void crearGraficoHistograma(GraficoHistograma grafico, DataTable dat_datos)
        {
            // Mostrar las opciones del gráfico BoxPlot

            gbOpcionesHistograma.Visible = true;

            // Calcular los valores del gráfico

            int total = dat_datos.Rows.Count;

            double minimo    = Convert.ToDouble(dat_datos.Compute("Min(Efectividad)", string.Empty));
            double maximo    = Convert.ToDouble(dat_datos.Compute("Max(Efectividad)", string.Empty));
            double rango     = maximo - minimo;
            double intervalo = Math.Round(rango / Math.Sqrt(total), 2);

            // Definir los rangos

            List <double> limites = new List <double>();

            do
            {
                limites.Add(minimo);
                minimo = Math.Min(minimo + intervalo, maximo);
            }while (minimo < maximo);

            // Clasificar los valores

            List <double> porcentajes = new List <double>();
            List <double> cantidades  = new List <double>();

            foreach (double limite in limites)
            {
                string expresion = ("Efectividad >= " + limite).Replace(',', '.');

                double cantidad   = Convert.ToDouble(dat_datos.Compute("COUNT(Efectividad)", expresion));
                double porcentaje = (cantidad / total) * 100;

                cantidades.Add(cantidad);
                porcentajes.Add(Math.Round(porcentaje, 2));
            }

            for (int contador = 0; contador < porcentajes.Count - 1; contador++)
            {
                porcentajes[contador] -= porcentajes[contador + 1];
                cantidades[contador]  -= cantidades[contador + 1];
            }

            // Agregar la serie que muestra los porcentajes

            Series serie_porcentajes = new Series();

            serie_porcentajes.Name      = grafico.Nombre_serie + "(Porcentaje)";
            serie_porcentajes.ChartType = SeriesChartType.Column;
            serie_porcentajes.Points.DataBindY(porcentajes);
            serie_porcentajes.IsValueShownAsLabel = true;

            crtGrafico.Series.Add(serie_porcentajes);

            // Agregar la serie que muestra las cantidades

            Series serie_cantidades = new Series();

            serie_cantidades.Name      = grafico.Nombre_serie + "(Cantidad)";
            serie_cantidades.ChartType = SeriesChartType.Column;
            serie_cantidades.Points.DataBindY(cantidades);
            serie_cantidades.IsValueShownAsLabel = true;

            crtGrafico.Series.Add(serie_cantidades);

            // Agregar las etiquetas del eje x

            int posicion = 0;

            for (posicion = 0; posicion < porcentajes.Count; posicion++)
            {
                double limite = Math.Round(limites[posicion], 2);

                crtGrafico.ChartAreas[0].AxisX.CustomLabels.Add(posicion, posicion + 1, limite.ToString());
            }

            maximo = Math.Round(maximo, 2);
            crtGrafico.ChartAreas[0].AxisX.CustomLabels.Add(posicion, posicion + 1, maximo.ToString());

            // Dar formato al gráfico

            Title titulo = new Title(grafico.Nombre);

            crtGrafico.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
            crtGrafico.Titles.Add(titulo);

            cboValor.SelectedIndex = 0;
        }