none
¿Cómo insertar línea promedio en gráfico Range? RRS feed

  • Pregunta

  • Hola, tengo un gráfico tipo Range con cuatro valores y estoy intentando insertar la media de cada uno de los valores pero no veo el modo.
    el código que tengo para crear el gráfico es:
    If valor = 1 Then 'SI SELECCIONAMOS UN MES ÚNICAMENTE
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE to_char (fecha,'MM')= to_char(current_date ,'MM');", conexion)
    
                        adapter.Fill(MiDt)
    
                        conexion.Close()
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DE ESTE MES."
    
                    End Using
    
                Else 'SI SELECCIONAMOS VARIOS MESES
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE fecha BETWEEN '01/" & Mes & "/" & anio & "' AND CURRENT_DATE;", conexion)
    
                        adapter.Fill(MiDt)
    
                        conexion.Close()
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DESDE " & nombre & " HASTA HOY."
    
                    End Using
    
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
            'CALCULAMOS LAS MEDIAS
    
            conexion.Open()
    
            Using mediasSQL As New NpgsqlCommand("SELECT ROUND (AVG (sistolica),1), ROUND (AVG (diastolica),1)," _
            & "ROUND (AVG (pulsaciones)),ROUND (AVG (saturacion)) FROM valores;", conexion)
    
                Dim medSisto As Decimal
                Dim medDiast As Decimal
                Dim puls As Int16
                Dim sat As Int16
                lector = mediasSQL.ExecuteReader()
                lector.Read()
    
                medSisto = lector(0)
                medDiast = lector(1)
                puls = lector(2)
                sat = lector(3)
    
                'conexion.Close()
    
            End Using
    
            Chart1.Titles.Clear()
    
            Chart1.Titles.Add(titulo)
            Chart1.Series(0).LegendText = "Valores."
    
            Chart1.Series.Clear()
    
            Chart1.Series.Add(MiDt.Columns(4).ColumnName)
            Chart1.Series.Add(MiDt.Columns(3).ColumnName)
            Chart1.Series.Add(MiDt.Columns(1).ColumnName)
            Chart1.Series.Add(MiDt.Columns(2).ColumnName)
    
            'FORMATO COLUMNA SATURACIÓN
    
            Chart1.Series(MiDt.Columns(4).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).YValueMembers = MiDt.Columns(4).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).ChartType = SeriesChartType.Range
            Chart1.Series(MiDt.Columns(4).ColumnName).Color = color.Aqua
    
            'FORMATO COLUMNA PULSACIONES
    
            Chart1.Series(MiDt.Columns(3).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).YValueMembers = MiDt.Columns(3).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).ChartType = SeriesChartType.Range
            Chart1.Series(MiDt.Columns(3).ColumnName).Color = color.DodgerBlue
    
            'FORMATO COLUMNA SISTÓLICA
    
            Chart1.Series(MiDt.Columns(1).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).YValueMembers = MiDt.Columns(1).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).ChartType = SeriesChartType.Range
            Chart1.Series(MiDt.Columns(1).ColumnName).Color = color.RoyalBlue
    
            'FORMATO COLUMNA DIASTÓLICA
    
            Chart1.Series(MiDt.Columns(2).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).YValueMembers = MiDt.Columns(2).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).ChartType = SeriesChartType.Range
            Chart1.Series(MiDt.Columns(2).ColumnName).Color = color.MediumBlue
    
            Chart1.BackColor = color.SlateGray
            Chart1.ChartAreas(0).BackColor = color.CadetBlue
            Chart1.BackSecondaryColor = color.Gainsboro
            Chart1.BackGradientStyle = GradientStyle.TopBottom
            Chart1.BorderlineDashStyle = ChartDashStyle.Solid
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
            Chart1.BorderlineColor = color.Bisque
    
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisY.Interval = 2
            Chart1.ChartAreas(0).AxisY.Minimum = 4
            Chart1.ChartAreas(0).AxisY.Maximum = 100
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -90
    
            Chart1.ChartAreas(0).AxisY.Title = "VALORES"
            Chart1.ChartAreas(0).AxisX.Title = "FECHA"
            Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisX.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisX.TitleAlignment = StringAlignment.Center
            Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisY.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisY.TitleAlignment = StringAlignment.Center
    
            Chart1.Titles(0).Font = New Font("Trebuchet MS", 24, FontStyle.Bold) 'FUENTE, TAMAÑO Y ESTILO DEL TÍTULO.
            Chart1.Titles(0).ForeColor = color.DarkSlateGray 'COLOR DE LA FUENTE DEL TÍTULO.
            Chart1.Titles(0).ShadowOffset = 3 'TAMAÑO DE LA SOMBRA DEL TÍTULO.
            Chart1.Titles(0).ShadowColor = color.DarkGray 'COLOR DE LA SOMBRA DEL TÍTULO.
    
            Chart1.DataSource = MiDt
    
            conexion.Close()
    
        End Sub
    
    ¿Puede alguien explicarme como puedo hacerlo? Gracias.
    jueves, 7 de abril de 2022 10:54

Todas las respuestas

  • Deleted
    jueves, 7 de abril de 2022 12:53
  • Hola, gracias por tu interés, he hecho lo que me dices, o eso creo, y me da error, me dice que no existe la columna med_sist:

    Te he hecho caso y he cambiado el tipo de gráfico por el de áreas.

    If valor = 1 Then 'SI SELECCIONAMOS UN MES ÚNICAMENTE
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE to_char (fecha,'MM')= to_char(current_date ,'MM');", conexion)
    
                        adapter.Fill(MiDt)
    
                        conexion.Close()
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DE ESTE MES."
    
                    End Using
    
                Else 'SI SELECCIONAMOS VARIOS MESES
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE fecha BETWEEN '01/" & Mes & "/" & anio & "' AND CURRENT_DATE;", conexion)
    
                        adapter.Fill(MiDt)
    
                        conexion.Close()
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DESDE " & nombre & " HASTA HOY."
    
                    End Using
    
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
            'CALCULAMOS LAS MEDIAS
    
            conexion.Open()
    
            Using mediasSQL As New NpgsqlDataAdapter("SELECT (ROUND (AVG (sistolica),1)) as med_sist, (ROUND (AVG (diastolica),1)) as med_diast," _
            & " (ROUND (AVG (pulsaciones))) as med_puls, (ROUND (AVG (saturacion))) as med_sat FROM valores;", conexion)
    
                mediasSQL.Fill(datos)
    
                'conexion.Close()
    
            End Using
    
            Chart1.Titles.Clear()
    
            Chart1.Titles.Add(titulo)
            Chart1.Series(0).LegendText = "Valores."
    
            Chart1.Series.Clear()
    
            Chart1.Series.Add(MiDt.Columns(4).ColumnName)
            Chart1.Series.Add(datos.Columns(3).ColumnName)
            Chart1.Series.Add(MiDt.Columns(3).ColumnName)
            Chart1.Series.Add(datos.Columns(2).ColumnName)
            Chart1.Series.Add(MiDt.Columns(1).ColumnName)
            Chart1.Series.Add(datos.Columns(0).ColumnName)
            Chart1.Series.Add(MiDt.Columns(2).ColumnName)
            Chart1.Series.Add(datos.Columns(1).ColumnName)
    
            'FORMATO COLUMNA SATURACIÓN
    
            Chart1.Series(MiDt.Columns(4).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).YValueMembers = MiDt.Columns(4).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(4).ColumnName).Color = color.Aqua
    
            'Chart1.Series(datos.Columns(3).ColumnName).XValueMember = datos.Columns(0).ColumnName
            Chart1.Series(datos.Columns(3).ColumnName).YValueMembers = datos.Columns(3).ColumnName
            Chart1.Series(datos.Columns(3).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(datos.Columns(3).ColumnName).Color = color.Black
    
            'FORMATO COLUMNA PULSACIONES
    
            Chart1.Series(MiDt.Columns(3).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).YValueMembers = MiDt.Columns(3).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(3).ColumnName).Color = color.DodgerBlue
    
            'FORMATO COLUMNA SISTÓLICA
    
            Chart1.Series(MiDt.Columns(1).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).YValueMembers = MiDt.Columns(1).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(1).ColumnName).Color = color.RoyalBlue
    
            'FORMATO COLUMNA DIASTÓLICA
    
            Chart1.Series(MiDt.Columns(2).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).YValueMembers = MiDt.Columns(2).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(2).ColumnName).Color = color.MediumBlue
    
            Chart1.BackColor = color.SlateGray
            Chart1.ChartAreas(0).BackColor = color.CadetBlue
            Chart1.BackSecondaryColor = color.Gainsboro
            Chart1.BackGradientStyle = GradientStyle.TopBottom
            Chart1.BorderlineDashStyle = ChartDashStyle.Solid
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
            Chart1.BorderlineColor = color.Bisque
    
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisY.Interval = 2
            Chart1.ChartAreas(0).AxisY.Minimum = 4
            Chart1.ChartAreas(0).AxisY.Maximum = 100
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -90
    
            Chart1.ChartAreas(0).AxisY.Title = "VALORES"
            Chart1.ChartAreas(0).AxisX.Title = "FECHA"
            Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisX.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisX.TitleAlignment = StringAlignment.Center
            Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisY.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisY.TitleAlignment = StringAlignment.Center
    
            Chart1.Titles(0).Font = New Font("Trebuchet MS", 24, FontStyle.Bold) 'FUENTE, TAMAÑO Y ESTILO DEL TÍTULO.
            Chart1.Titles(0).ForeColor = color.DarkSlateGray 'COLOR DE LA FUENTE DEL TÍTULO.
            Chart1.Titles(0).ShadowOffset = 3 'TAMAÑO DE LA SOMBRA DEL TÍTULO.
            Chart1.Titles(0).ShadowColor = color.DarkGray 'COLOR DE LA SOMBRA DEL TÍTULO.
    
            Chart1.DataSource = MiDt
    
            conexion.Close()
    
        End Sub

    jueves, 7 de abril de 2022 13:40
  • Deleted
    jueves, 7 de abril de 2022 14:04
  • Hola, ya he modificado lo que me dices, pero no muestra las líneas en el gráfico.

    El código queda así:

    Private Sub mes_lbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles mes_lbox.SelectedIndexChanged
    
            Dim valor As Short
            Dim Mes As Short
    
            valor = mes_lbox.SelectedItem
            Mes = Now.Month
    
            'EXTRAEMOS EL NÚMERO DE MESES QUE QUEREMOS MOSTRAR EN LA GRÁFICA
    
            If valor = Now.Month Then 'SÓLO UN MES
    
                Mes = (Mes - valor) + 1
    
            Else Mes = (Mes - (valor - 1)) 'VARIOS MESES
    
            End If
    
            Dim nombre As String = UCase(MonthName(Mes))
            Dim titulo As String = ""
    
            MiDt.Clear() 'LIMPIAMOS EL DATATABLE PARA PODER CARGAR DE NUEVO VALORES
    
            Try
    
                If valor = 1 Then 'SI SELECCIONAMOS UN MES ÚNICAMENTE
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE to_char (fecha,'MM')= to_char(current_date ,'MM');", conexion)
    
                        adapter.Fill(MiDt)
    
                        conexion.Close()
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DE ESTE MES."
    
                    End Using
    
                Else 'SI SELECCIONAMOS VARIOS MESES
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE fecha BETWEEN '01/" & Mes & "/" & anio & "' AND CURRENT_DATE;", conexion)
    
                        adapter.Fill(MiDt)
    
                        conexion.Close()
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DESDE " & nombre & " HASTA HOY."
    
                    End Using
    
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
            'CALCULAMOS LAS MEDIAS
    
            conexion.Open()
    
            Using mediasSQL As New NpgsqlDataAdapter("SELECT (ROUND (AVG (sistolica),1)) as med_sist, (ROUND (AVG (diastolica),1)) as med_diast," _
            & " (ROUND (AVG (pulsaciones))) as med_puls, (ROUND (AVG (saturacion))) as med_sat FROM valores;", conexion)
    
                mediasSQL.Fill(MiDt)
    
                'conexion.Close()
    
            End Using
    
            Chart1.Titles.Clear()
    
            Chart1.Titles.Add(titulo)
            Chart1.Series(0).LegendText = "Valores."
    
            Chart1.Series.Clear()
    
            Chart1.Series.Add(MiDt.Columns(4).ColumnName)
            Chart1.Series.Add(MiDt.Columns(8).ColumnName)
            Chart1.Series.Add(MiDt.Columns(3).ColumnName)
            Chart1.Series.Add(MiDt.Columns(7).ColumnName)
            Chart1.Series.Add(MiDt.Columns(1).ColumnName)
            Chart1.Series.Add(MiDt.Columns(5).ColumnName)
            Chart1.Series.Add(MiDt.Columns(2).ColumnName)
            Chart1.Series.Add(MiDt.Columns(6).ColumnName)
    
            'FORMATO COLUMNA SATURACIÓN
    
            Chart1.Series(MiDt.Columns(4).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).YValueMembers = MiDt.Columns(4).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(4).ColumnName).Color = color.Aqua
    
            Chart1.Series(MiDt.Columns(8).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).YValueMembers = MiDt.Columns(8).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(8).ColumnName).Color = color.Red
    
            'FORMATO COLUMNA PULSACIONES
    
            Chart1.Series(MiDt.Columns(3).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).YValueMembers = MiDt.Columns(3).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(3).ColumnName).Color = color.DodgerBlue
    
            Chart1.Series(MiDt.Columns(7).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).YValueMembers = MiDt.Columns(7).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(7).ColumnName).Color = color.Red
    
            'FORMATO COLUMNA SISTÓLICA
    
            Chart1.Series(MiDt.Columns(1).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).YValueMembers = MiDt.Columns(1).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(1).ColumnName).Color = color.RoyalBlue
    
            Chart1.Series(MiDt.Columns(5).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).YValueMembers = MiDt.Columns(5).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(5).ColumnName).Color = color.Red
    
            'FORMATO COLUMNA DIASTÓLICA
    
            Chart1.Series(MiDt.Columns(2).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).YValueMembers = MiDt.Columns(2).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(2).ColumnName).Color = color.MediumBlue
    
            Chart1.Series(MiDt.Columns(6).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).YValueMembers = MiDt.Columns(6).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(6).ColumnName).Color = color.Red
    
            Chart1.BackColor = color.SlateGray
            Chart1.ChartAreas(0).BackColor = color.CadetBlue
            Chart1.BackSecondaryColor = color.Gainsboro
            Chart1.BackGradientStyle = GradientStyle.TopBottom
            Chart1.BorderlineDashStyle = ChartDashStyle.Solid
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
            Chart1.BorderlineColor = color.Bisque
    
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisY.Interval = 2
            Chart1.ChartAreas(0).AxisY.Minimum = 4
            Chart1.ChartAreas(0).AxisY.Maximum = 100
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -90
    
            Chart1.ChartAreas(0).AxisY.Title = "VALORES"
            Chart1.ChartAreas(0).AxisX.Title = "FECHA"
            Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisX.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisX.TitleAlignment = StringAlignment.Center
            Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisY.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisY.TitleAlignment = StringAlignment.Center
    
            Chart1.Titles(0).Font = New Font("Trebuchet MS", 24, FontStyle.Bold) 'FUENTE, TAMAÑO Y ESTILO DEL TÍTULO.
            Chart1.Titles(0).ForeColor = color.DarkSlateGray 'COLOR DE LA FUENTE DEL TÍTULO.
            Chart1.Titles(0).ShadowOffset = 3 'TAMAÑO DE LA SOMBRA DEL TÍTULO.
            Chart1.Titles(0).ShadowColor = color.DarkGray 'COLOR DE LA SOMBRA DEL TÍTULO.
    
            Chart1.DataSource = MiDt
    
            conexion.Close()
    
        End Sub

    jueves, 7 de abril de 2022 14:43
  • Deleted
    jueves, 7 de abril de 2022 15:28
  • Hola de nuevo, estás escribiendo en C#, yo en VB.Net, a parte de eso, ¿Dónde se supone que encaja lo que propones?. No entiendo como puedo encajar el resultado del DataAdapter en el For Each

     MiDt.Columns.Add("promsat")
    
        For Each dr In MiDt.AsEnumerable()
            dr("promsat") = sat
            dr("blabla") = bla
        Next

    jueves, 7 de abril de 2022 15:58
  • Deleted
    jueves, 7 de abril de 2022 16:10
  • Hola de nuevo, en primer lugar gracias por tu tiempo. He implementado tu código en el mío y me queda así:

    Private Sub mes_lbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles mes_lbox.SelectedIndexChanged
    
            Dim valor As Short
            Dim Mes As Short
    
            valor = mes_lbox.SelectedItem
            Mes = Now.Month
    
            'EXTRAEMOS EL NÚMERO DE MESES QUE QUEREMOS MOSTRAR EN LA GRÁFICA
    
            If valor = Now.Month Then 'SÓLO UN MES
    
                Mes = (Mes - valor) + 1
    
            Else Mes = (Mes - (valor - 1)) 'VARIOS MESES
    
            End If
    
            Dim nombre As String = UCase(MonthName(Mes))
            Dim titulo As String = ""
    
            MiDt.Clear() 'LIMPIAMOS EL DATATABLE PARA PODER CARGAR DE NUEVO VALORES
    
            Try
    
                If valor = 1 Then 'SI SELECCIONAMOS UN MES ÚNICAMENTE
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE to_char (fecha,'MM')= to_char(current_date ,'MM');", conexion)
    
                        adapter.Fill(MiDt)
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DE ESTE MES."
    
                    End Using
    
                Else 'SI SELECCIONAMOS VARIOS MESES
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE fecha BETWEEN '01/" & Mes & "/" & anio & "' AND CURRENT_DATE;", conexion)
    
                        adapter.Fill(MiDt)
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DESDE " & nombre & " HASTA HOY."
    
                    End Using
    
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
            'CALCULAMOS LAS MEDIAS
    
            Using mediasSQL As New NpgsqlCommand("SELECT (ROUND (AVG (sistolica),1)) as sist_med, (ROUND (AVG (diastolica),1)) as diast_med," _
            & " (ROUND (AVG (pulsaciones))) as puls_med, (ROUND (AVG (saturacion))) as sat_med FROM valores;", conexion)
    
                Dim medSisto As Decimal
                Dim medDiast As Decimal
                Dim medPuls As Int16
                Dim medSat As Int16
    
                lector = mediasSQL.ExecuteReader()
                lector.Read()
    
                medSisto = lector(0)
                medDiast = lector(1)
                medPuls = lector(2)
                medSat = lector(3)
    
                MiDt.Columns.Add("medSisto")
                MiDt.Columns.Add("medDiast")
                MiDt.Columns.Add("medPuls")
                MiDt.Columns.Add("medSat")
    
                For Each dr As DataRow In MiDt.AsEnumerable()
    
                    dr("medSisto") = medSisto
                    dr("medDiast") = medDiast
                    dr("medPuls") = medPuls
                    dr("medSat") = medSat
    
                Next
    
                conexion.Close()
    
            End Using
    
            'AÑADIMOS DATOS Y DIBUJAMOS EL GRÁFICO
    
            Chart1.Titles.Clear()
    
            Chart1.Titles.Add(titulo)
            Chart1.Series(0).LegendText = "Valores."
    
            Chart1.Series.Clear()
    
            Chart1.Series.Add(MiDt.Columns(4).ColumnName)
            Chart1.Series.Add(MiDt.Columns(8).ColumnName)
            Chart1.Series.Add(MiDt.Columns(3).ColumnName)
            Chart1.Series.Add(MiDt.Columns(7).ColumnName)
            Chart1.Series.Add(MiDt.Columns(1).ColumnName)
            Chart1.Series.Add(MiDt.Columns(5).ColumnName)
            Chart1.Series.Add(MiDt.Columns(2).ColumnName)
            Chart1.Series.Add(MiDt.Columns(6).ColumnName)
    
            'FORMATO COLUMNA SATURACIÓN
    
            Chart1.Series(MiDt.Columns(4).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).YValueMembers = MiDt.Columns(4).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(4).ColumnName).Color = color.Aqua
    
            Chart1.Series(MiDt.Columns(8).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).YValueMembers = MiDt.Columns(8).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(8).ColumnName).Color = color.Red
    
            'FORMATO COLUMNA PULSACIONES
    
            Chart1.Series(MiDt.Columns(3).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).YValueMembers = MiDt.Columns(3).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(3).ColumnName).Color = color.DodgerBlue
    
            Chart1.Series(MiDt.Columns(7).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).YValueMembers = MiDt.Columns(7).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(7).ColumnName).Color = color.Black
    
            'FORMATO COLUMNA SISTÓLICA
    
            Chart1.Series(MiDt.Columns(1).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).YValueMembers = MiDt.Columns(1).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(1).ColumnName).Color = color.RoyalBlue
    
            Chart1.Series(MiDt.Columns(5).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).YValueMembers = MiDt.Columns(5).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(5).ColumnName).Color = color.Yellow
    
            'FORMATO COLUMNA DIASTÓLICA
    
            Chart1.Series(MiDt.Columns(2).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).YValueMembers = MiDt.Columns(2).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(2).ColumnName).Color = color.MediumBlue
    
            Chart1.Series(MiDt.Columns(6).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).YValueMembers = MiDt.Columns(6).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(6).ColumnName).Color = color.GreenYellow
    
            Chart1.BackColor = color.SlateGray
            Chart1.ChartAreas(0).BackColor = color.CadetBlue
            Chart1.BackSecondaryColor = color.Gainsboro
            Chart1.BackGradientStyle = GradientStyle.TopBottom
            Chart1.BorderlineDashStyle = ChartDashStyle.Solid
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
            Chart1.BorderlineColor = color.Bisque
    
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisY.Interval = 2
            Chart1.ChartAreas(0).AxisY.Minimum = 4
            Chart1.ChartAreas(0).AxisY.Maximum = 100
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -90
    
            Chart1.ChartAreas(0).AxisY.Title = "VALORES"
            Chart1.ChartAreas(0).AxisX.Title = "FECHA"
            Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisX.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisX.TitleAlignment = StringAlignment.Center
            Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisY.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisY.TitleAlignment = StringAlignment.Center
    
            Chart1.Titles(0).Font = New Font("Trebuchet MS", 24, FontStyle.Bold) 'FUENTE, TAMAÑO Y ESTILO DEL TÍTULO.
            Chart1.Titles(0).ForeColor = color.DarkSlateGray 'COLOR DE LA FUENTE DEL TÍTULO.
            Chart1.Titles(0).ShadowOffset = 3 'TAMAÑO DE LA SOMBRA DEL TÍTULO.
            Chart1.Titles(0).ShadowColor = color.DarkGray 'COLOR DE LA SOMBRA DEL TÍTULO.
    
            Chart1.DataSource = MiDt
    
            conexion.Close()
    
        End Sub
    El problema es que no muestra todas las medias y hay una que no coincide con su valor, a parte, si cambio de mes a mostrar me dice: System.Data.DuplicateNameException: 'La columna 'medSisto' ya pertenece a DataTable.', supongo que con las restantes pasará lo mismo.
    jueves, 7 de abril de 2022 16:46
  • Deleted
    jueves, 7 de abril de 2022 16:57
  • Hola, he hecho lo que me dices y sigue sin mostrar la media sistólica y la diastólica da un valor incorrecto. Te dejo el código con las modificaciones que tengo para poder cambiar de meses sin que de errores.

    Private Sub mes_lbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles mes_lbox.SelectedIndexChanged
    
            If conexion.State = ConnectionState.Closed Then
    
                conexion.Open()
    
                'Else conexion.Open()
    
            End If
    
            'conexion.Open()
    
            Dim valor As Short
            Dim Mes As Short
    
            valor = mes_lbox.SelectedItem
            Mes = Now.Month
    
            'EXTRAEMOS EL NÚMERO DE MESES QUE QUEREMOS MOSTRAR EN LA GRÁFICA
    
            If valor = Now.Month Then 'SÓLO UN MES
    
                Mes = (Mes - valor) + 1
    
            Else Mes = (Mes - (valor - 1)) 'VARIOS MESES
    
            End If
    
            Dim nombre As String = UCase(MonthName(Mes))
            Dim titulo As String = ""
    
            MiDt.Clear() 'LIMPIAMOS EL DATATABLE PARA PODER CARGAR DE NUEVO VALORES
            Chart1.Titles.Clear()
    
            Try
    
                If valor = 1 Then 'SI SELECCIONAMOS UN MES ÚNICAMENTE
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE to_char (fecha,'MM')= to_char(current_date ,'MM');", conexion)
    
                        adapter.Fill(MiDt)
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DE ESTE MES."
    
                    End Using
    
                Else 'SI SELECCIONAMOS VARIOS MESES
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE fecha BETWEEN '01/" & Mes & "/" & anio & "' AND CURRENT_DATE;", conexion)
    
                        adapter.Fill(MiDt)
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DESDE " & nombre & " HASTA HOY."
    
                    End Using
    
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
            'CALCULAMOS LAS MEDIAS
    
            Using mediasSQL As New NpgsqlCommand("SELECT (ROUND (AVG (sistolica),1)) as sist_med, (ROUND (AVG (diastolica),1)) as diast_med," _
            & " (ROUND (AVG (pulsaciones))) as puls_med, (ROUND (AVG (saturacion))) as sat_med FROM valores;", conexion)
    
                Dim medSisto As Decimal
                Dim medDiast As Decimal
                Dim medPuls As Int16
                Dim medSat As Int16
    
                lector = mediasSQL.ExecuteReader()
                lector.Read()
    
                medSisto = lector(0)
                medDiast = lector(1)
                medPuls = lector(2)
                medSat = lector(3)
    
                'SI LAS COLUMNAS CON LAS MEDIAS EXISTEN LAS ELIMINAMOS ANTES DE EMPEZAR
    
                Dim columns As DataColumnCollection = MiDt.Columns
    
                If columns.Contains("medSisto") Then
    
                    If columns.CanRemove(columns("medSisto")) Then
    
                        columns.Remove("medSisto")
    
                    End If
    
                End If
    
                If columns.Contains("medDiast") Then
    
                    If columns.CanRemove(columns("medDiast")) Then
    
                        columns.Remove("medDiast")
    
                    End If
    
                End If
    
                If columns.Contains("medPuls") Then
    
                    If columns.CanRemove(columns("medPuls")) Then
    
                        columns.Remove("medPuls")
    
                    End If
    
                End If
    
                If columns.Contains("medSat") Then
    
                    If columns.CanRemove(columns("medSat")) Then
    
                        columns.Remove("medSat")
    
                    End If
    
                End If
    
                MiDt.Columns.Add("medSisto")
                MiDt.Columns.Add("medDiast")
                MiDt.Columns.Add("medPuls")
                MiDt.Columns.Add("medSat")
    
                For Each dr As DataRow In MiDt.AsEnumerable()
    
                    dr("medSisto") = medSisto
                    dr("medDiast") = medDiast
                    dr("medPuls") = medPuls
                    dr("medSat") = medSat
    
                Next
    
                conexion.Close()
    
            End Using
    
            'AÑADIMOS DATOS Y DIBUJAMOS EL GRÁFICO
    
            'Chart1.Titles.Clear()
    
            Chart1.Titles.Add(titulo)
            Chart1.Series(0).LegendText = "Valores."
    
            Chart1.Series.Clear()
    
            Chart1.Series.Add(MiDt.Columns(4).ColumnName)
            Chart1.Series.Add(MiDt.Columns(8).ColumnName)
            Chart1.Series.Add(MiDt.Columns(3).ColumnName)
            Chart1.Series.Add(MiDt.Columns(7).ColumnName)
            Chart1.Series.Add(MiDt.Columns(1).ColumnName)
            Chart1.Series.Add(MiDt.Columns(5).ColumnName)
            Chart1.Series.Add(MiDt.Columns(2).ColumnName)
            Chart1.Series.Add(MiDt.Columns(6).ColumnName)
    
            'FORMATO COLUMNA SATURACIÓN
    
            Chart1.Series(MiDt.Columns(4).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).YValueMembers = MiDt.Columns(4).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(4).ColumnName).Color = color.Aqua
    
            Chart1.Series(MiDt.Columns(8).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).YValueMembers = MiDt.Columns(8).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(8).ColumnName).Color = color.Red
    
            'FORMATO COLUMNA PULSACIONES
    
            Chart1.Series(MiDt.Columns(3).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).YValueMembers = MiDt.Columns(3).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(3).ColumnName).Color = color.DodgerBlue
    
            Chart1.Series(MiDt.Columns(7).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).YValueMembers = MiDt.Columns(7).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(7).ColumnName).Color = color.Black
    
            'FORMATO COLUMNA SISTÓLICA
    
            Chart1.Series(MiDt.Columns(1).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).YValueMembers = MiDt.Columns(1).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(1).ColumnName).Color = color.RoyalBlue
    
            Chart1.Series(MiDt.Columns(5).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).YValueMembers = MiDt.Columns(5).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(5).ColumnName).Color = color.Yellow
    
            'FORMATO COLUMNA DIASTÓLICA
    
            Chart1.Series(MiDt.Columns(2).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).YValueMembers = MiDt.Columns(2).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(2).ColumnName).Color = color.MediumBlue
    
            Chart1.Series(MiDt.Columns(6).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).YValueMembers = MiDt.Columns(6).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(6).ColumnName).Color = color.Orange
    
            Chart1.BackColor = color.SlateGray
            Chart1.ChartAreas(0).BackColor = color.CadetBlue
            Chart1.BackSecondaryColor = color.Gainsboro
            Chart1.BackGradientStyle = GradientStyle.TopBottom
            Chart1.BorderlineDashStyle = ChartDashStyle.Solid
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
            Chart1.BorderlineColor = color.Bisque
    
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisY.Interval = 2
            Chart1.ChartAreas(0).AxisY.Minimum = 4
            Chart1.ChartAreas(0).AxisY.Maximum = 100
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -90
    
            Chart1.ChartAreas(0).AxisY.Title = "VALORES"
            Chart1.ChartAreas(0).AxisX.Title = "FECHA"
            Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisX.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisX.TitleAlignment = StringAlignment.Center
            Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisY.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisY.TitleAlignment = StringAlignment.Center
    
            Chart1.Titles(0).Font = New Font("Trebuchet MS", 24, FontStyle.Bold) 'FUENTE, TAMAÑO Y ESTILO DEL TÍTULO.
            Chart1.Titles(0).ForeColor = color.DarkSlateGray 'COLOR DE LA FUENTE DEL TÍTULO.
            Chart1.Titles(0).ShadowOffset = 3 'TAMAÑO DE LA SOMBRA DEL TÍTULO.
            Chart1.Titles(0).ShadowColor = color.DarkGray 'COLOR DE LA SOMBRA DEL TÍTULO.
    
            Chart1.DataSource = MiDt
    
            conexion.Close()
    
        End Sub

    jueves, 7 de abril de 2022 17:16
  • Deleted
    jueves, 7 de abril de 2022 17:28
  • Sigue sin mostrar la media sistólica y la diastólica la muestra mal.
    jueves, 7 de abril de 2022 17:56
  • Hola, ya lo he solucionado quitando los decimales de las medias, ahora lo que me gustaría es poder hacer las líneas de los poromedios más gruesas.

    No sé como hacerlo. Gracias.

    El código final a falta de ajustar el tema de las líneas es:

    Private Sub mes_lbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles mes_lbox.SelectedIndexChanged
    
            If conexion.State = ConnectionState.Closed Then
    
                conexion.Open()
                
            End If        
    
            Dim valor As Short
            Dim Mes As Short
    
            valor = mes_lbox.SelectedItem
            Mes = Now.Month
    
            'EXTRAEMOS EL NÚMERO DE MESES QUE QUEREMOS MOSTRAR EN LA GRÁFICA
    
            If valor = Now.Month Then 'SÓLO UN MES
    
                Mes = (Mes - valor) + 1
    
            Else Mes = (Mes - (valor - 1)) 'VARIOS MESES
    
            End If
    
            Dim nombre As String = UCase(MonthName(Mes))
            Dim titulo As String = ""
    
            MiDt.Clear() 'LIMPIAMOS EL DATATABLE PARA PODER CARGAR DE NUEVO VALORES
    
            Try
    
                If valor = 1 Then 'SI SELECCIONAMOS UN MES ÚNICAMENTE
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE to_char (fecha,'MM')= to_char(current_date ,'MM');", conexion)
    
                        adapter.Fill(MiDt)
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DE ESTE MES."
    
                    End Using
    
                Else 'SI SELECCIONAMOS VARIOS MESES
    
                    Using adapter As New NpgsqlDataAdapter("SELECT * FROM valores WHERE fecha BETWEEN '01/" & Mes & "/" & anio & "' AND CURRENT_DATE;", conexion)
    
                        adapter.Fill(MiDt)
    
                        Mes = 0
                        valor = 0
    
                        titulo = "VALORES DE LAS TOMAS DESDE " & nombre & " HASTA HOY."
    
                    End Using
    
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
            'CALCULAMOS LAS MEDIAS
    
            Using mediasSQL As New NpgsqlCommand("SELECT (ROUND (AVG (sistolica))), (ROUND (AVG (diastolica)))," _
            & " (ROUND (AVG (pulsaciones))), (ROUND (AVG (saturacion)))FROM valores;", conexion)
    
                Dim medSisto As Byte
                Dim medDiast As Byte
                Dim medPuls As Byte
                Dim medSat As Byte
    
                lector = mediasSQL.ExecuteReader()
                lector.Read()
    
                medSisto = lector(0)
                medDiast = lector(1)
                medPuls = lector(2)
                medSat = lector(3)
    
                'SI LAS COLUMNAS CON LAS MEDIAS EXISTEN LAS ELIMINAMOS ANTES DE EMPEZAR
    
                Dim columns As DataColumnCollection = MiDt.Columns
    
                If columns.Contains("med_Sistolica") Then
    
                    If columns.CanRemove(columns("med_Sistolica")) Then
    
                        columns.Remove("med_Sistolica")
    
                    End If
    
                End If
    
                If columns.Contains("med_Diastolica") Then
    
                    If columns.CanRemove(columns("med_Diastolica")) Then
    
                        columns.Remove("med_Diastolica")
    
                    End If
    
                End If
    
                If columns.Contains("med_Pulso") Then
    
                    If columns.CanRemove(columns("med_Pulso")) Then
    
                        columns.Remove("med_Pulso")
    
                    End If
    
                End If
    
                If columns.Contains("med_Satur.") Then
    
                    If columns.CanRemove(columns("med_Satur.")) Then
    
                        columns.Remove("med_Satur.")
    
                    End If
    
                End If
    
                MiDt.Columns.Add("med_Sistolica")
                MiDt.Columns.Add("med_Diastolica")
                MiDt.Columns.Add("med_Pulso")
                MiDt.Columns.Add("med_Satur.")
    
                For Each dr As DataRow In MiDt.AsEnumerable()
    
                    dr("med_Sistolica") = medSisto
                    dr("med_Diastolica") = medDiast
                    dr("med_Pulso") = medPuls
                    dr("med_Satur.") = medSat
    
                Next
    
                conexion.Close()
    
            End Using
    
            'AÑADIMOS DATOS Y DIBUJAMOS EL GRÁFICO
    
            Chart1.Titles.Clear()
    
            Chart1.Titles.Add(titulo)
            Chart1.Series(0).LegendText = "Valores."
    
            Chart1.Series.Clear()
    
            Chart1.Series.Add(MiDt.Columns(4).ColumnName)
            Chart1.Series.Add(MiDt.Columns(8).ColumnName)
            Chart1.Series.Add(MiDt.Columns(3).ColumnName)
            Chart1.Series.Add(MiDt.Columns(7).ColumnName)
            Chart1.Series.Add(MiDt.Columns(1).ColumnName)
            Chart1.Series.Add(MiDt.Columns(5).ColumnName)
            Chart1.Series.Add(MiDt.Columns(2).ColumnName)
            Chart1.Series.Add(MiDt.Columns(6).ColumnName)
    
            'FORMATO COLUMNA SATURACIÓN
    
            Chart1.Series(MiDt.Columns(4).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).YValueMembers = MiDt.Columns(4).ColumnName
            Chart1.Series(MiDt.Columns(4).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(4).ColumnName).Color = color.Aqua
    
            Chart1.Series(MiDt.Columns(8).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).YValueMembers = MiDt.Columns(8).ColumnName
            Chart1.Series(MiDt.Columns(8).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(8).ColumnName).Color = color.Red
    
            'FORMATO COLUMNA PULSACIONES
    
            Chart1.Series(MiDt.Columns(3).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).YValueMembers = MiDt.Columns(3).ColumnName
            Chart1.Series(MiDt.Columns(3).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(3).ColumnName).Color = color.DodgerBlue
    
            Chart1.Series(MiDt.Columns(7).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).YValueMembers = MiDt.Columns(7).ColumnName
            Chart1.Series(MiDt.Columns(7).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(7).ColumnName).Color = color.Black
    
            'FORMATO COLUMNA SISTÓLICA
    
            Chart1.Series(MiDt.Columns(1).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).YValueMembers = MiDt.Columns(1).ColumnName
            Chart1.Series(MiDt.Columns(1).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(1).ColumnName).Color = color.RoyalBlue
    
            Chart1.Series(MiDt.Columns(5).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).YValueMembers = MiDt.Columns(5).ColumnName
            Chart1.Series(MiDt.Columns(5).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(5).ColumnName).Color = color.Yellow
    
            'FORMATO COLUMNA DIASTÓLICA
    
            Chart1.Series(MiDt.Columns(2).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).YValueMembers = MiDt.Columns(2).ColumnName
            Chart1.Series(MiDt.Columns(2).ColumnName).ChartType = SeriesChartType.Area
            Chart1.Series(MiDt.Columns(2).ColumnName).Color = color.MediumBlue
    
            Chart1.Series(MiDt.Columns(6).ColumnName).XValueMember = MiDt.Columns(0).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).YValueMembers = MiDt.Columns(6).ColumnName
            Chart1.Series(MiDt.Columns(6).ColumnName).ChartType = SeriesChartType.Line
            Chart1.Series(MiDt.Columns(6).ColumnName).Color = color.Orange
    
            Chart1.BackColor = color.SlateGray
            Chart1.ChartAreas(0).BackColor = color.CadetBlue
            Chart1.BackSecondaryColor = color.Gainsboro
            Chart1.BackGradientStyle = GradientStyle.TopBottom
            Chart1.BorderlineDashStyle = ChartDashStyle.Solid
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
            Chart1.BorderlineColor = color.Bisque
    
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisY.Interval = 2
            Chart1.ChartAreas(0).AxisY.Minimum = 4
            Chart1.ChartAreas(0).AxisY.Maximum = 100
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -90
    
            Chart1.ChartAreas(0).AxisY.Title = "VALORES"
            Chart1.ChartAreas(0).AxisX.Title = "FECHA"
            Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisX.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisX.TitleAlignment = StringAlignment.Center
            Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Verdana", 14, FontStyle.Bold)
            Chart1.ChartAreas(0).AxisY.TitleForeColor = color.Red
            Chart1.ChartAreas(0).AxisY.TitleAlignment = StringAlignment.Center
    
            Chart1.Titles(0).Font = New Font("Trebuchet MS", 24, FontStyle.Bold) 'FUENTE, TAMAÑO Y ESTILO DEL TÍTULO.
            Chart1.Titles(0).ForeColor = color.DarkSlateGray 'COLOR DE LA FUENTE DEL TÍTULO.
            Chart1.Titles(0).ShadowOffset = 3 'TAMAÑO DE LA SOMBRA DEL TÍTULO.
            Chart1.Titles(0).ShadowColor = color.DarkGray 'COLOR DE LA SOMBRA DEL TÍTULO.
    
            Chart1.DataSource = MiDt
    
            conexion.Close()
    
        End Sub

    viernes, 8 de abril de 2022 8:16