lmaoeksdi

frmFemale

Dec 16th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.88 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Imports System.Windows.Forms.DataVisualization.Charting
  3.  
  4. Public Class frmFemale
  5.  
  6.     Public Sub LoadFemalePopulationBarChart()
  7.         Me.TopMost = True
  8.         Me.ClientSize = New System.Drawing.Size(800, 600)
  9.         Try
  10.  
  11.             Dim query As String = "SELECT b.barangay, COUNT(id.id) AS FemalePopulation " &
  12.                                   "FROM individualdemographics id " &
  13.                                   "JOIN barangay b ON id.barangay_id = b.id " &
  14.                                   "WHERE id.sex = 'female' " &
  15.                                   "GROUP BY b.barangay"
  16.  
  17.  
  18.             Dim dt As DataTable = SQL.SQLPull(query)
  19.  
  20.             If dt.Rows.Count = 0 Then
  21.                 MessageBox.Show("No data found for the Female population chart.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
  22.                 Return
  23.             End If
  24.  
  25.  
  26.             barChart.Series.Clear()
  27.  
  28.             Dim series As New Series("Female")
  29.             series.ChartType = SeriesChartType.Column
  30.             series.IsValueShownAsLabel = True
  31.             series.Font = New Font("Inter", 10, FontStyle.Bold)
  32.  
  33.             ' Loop through the data and add it to the series
  34.             For Each row As DataRow In dt.Rows
  35.                 Dim barangay As String = row("barangay").ToString()
  36.                 Dim FemaleCount As Integer = Convert.ToInt32(row("FemalePopulation"))
  37.                 series.Points.AddXY(barangay, FemaleCount)
  38.             Next
  39.  
  40.             barChart.Series.Add(series)
  41.             series.Color = ColorTranslator.FromHtml("#ff746c")
  42.             barChart.Titles.Clear()
  43.             barChart.Titles.Add("Female Population per Barangay")
  44.             barChart.Titles(0).Font = New Font("Inter", 14, FontStyle.Bold)
  45.             barChart.ChartAreas(0).AxisX.LabelStyle.Angle = -45
  46.             barChart.ChartAreas(0).AxisX.Interval = 1
  47.             barChart.ChartAreas(0).AxisX.Title = "Barangay"
  48.             barChart.ChartAreas(0).AxisX.TitleFont = New Font("Inter", 12, FontStyle.Bold)
  49.             barChart.ChartAreas(0).AxisY.Title = "Female Count"
  50.             barChart.ChartAreas(0).AxisY.TitleFont = New Font("Inter", 12, FontStyle.Bold)
  51.  
  52.             barChart.ChartAreas(0).InnerPlotPosition.Auto = True
  53.             Dim gridlineColor As Color = Color.FromArgb(50, Color.Gray)
  54.             barChart.ChartAreas(0).AxisX.MajorGrid.LineColor = gridlineColor
  55.             barChart.ChartAreas(0).AxisY.MajorGrid.LineColor = gridlineColor
  56.  
  57.             series.ToolTip = "#VALX: #VALY Female"
  58.             barChart.Legends(0).Font = New Font("Inter", 10, FontStyle.Regular)
  59.             barChart.Invalidate()
  60.  
  61.         Catch ex As Exception
  62.             MessageBox.Show($"An error occurred while loading the Female population chart: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  63.         End Try
  64.     End Sub
  65. End Class
  66.  
Advertisement
Add Comment
Please, Sign In to add comment