Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports MySql.Data.MySqlClient
- Imports System.Windows.Forms.DataVisualization.Charting
- Public Class frmFemale
- Public Sub LoadFemalePopulationBarChart()
- Me.TopMost = True
- Me.ClientSize = New System.Drawing.Size(800, 600)
- Try
- Dim query As String = "SELECT b.barangay, COUNT(id.id) AS FemalePopulation " &
- "FROM individualdemographics id " &
- "JOIN barangay b ON id.barangay_id = b.id " &
- "WHERE id.sex = 'female' " &
- "GROUP BY b.barangay"
- Dim dt As DataTable = SQL.SQLPull(query)
- If dt.Rows.Count = 0 Then
- MessageBox.Show("No data found for the Female population chart.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Return
- End If
- barChart.Series.Clear()
- Dim series As New Series("Female")
- series.ChartType = SeriesChartType.Column
- series.IsValueShownAsLabel = True
- series.Font = New Font("Inter", 10, FontStyle.Bold)
- ' Loop through the data and add it to the series
- For Each row As DataRow In dt.Rows
- Dim barangay As String = row("barangay").ToString()
- Dim FemaleCount As Integer = Convert.ToInt32(row("FemalePopulation"))
- series.Points.AddXY(barangay, FemaleCount)
- Next
- barChart.Series.Add(series)
- series.Color = ColorTranslator.FromHtml("#ff746c")
- barChart.Titles.Clear()
- barChart.Titles.Add("Female Population per Barangay")
- barChart.Titles(0).Font = New Font("Inter", 14, FontStyle.Bold)
- barChart.ChartAreas(0).AxisX.LabelStyle.Angle = -45
- barChart.ChartAreas(0).AxisX.Interval = 1
- barChart.ChartAreas(0).AxisX.Title = "Barangay"
- barChart.ChartAreas(0).AxisX.TitleFont = New Font("Inter", 12, FontStyle.Bold)
- barChart.ChartAreas(0).AxisY.Title = "Female Count"
- barChart.ChartAreas(0).AxisY.TitleFont = New Font("Inter", 12, FontStyle.Bold)
- barChart.ChartAreas(0).InnerPlotPosition.Auto = True
- Dim gridlineColor As Color = Color.FromArgb(50, Color.Gray)
- barChart.ChartAreas(0).AxisX.MajorGrid.LineColor = gridlineColor
- barChart.ChartAreas(0).AxisY.MajorGrid.LineColor = gridlineColor
- series.ToolTip = "#VALX: #VALY Female"
- barChart.Legends(0).Font = New Font("Inter", 10, FontStyle.Regular)
- barChart.Invalidate()
- Catch ex As Exception
- MessageBox.Show($"An error occurred while loading the Female population chart: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment