(27-01-24, 09:43 PM)annagui كتب : اساتذتي البرار اعضاء المنتدى الكرام تحية طيبة
مشكلتي كالاتي:
بالفورم 2 عندي : (2) chartpie
الاول chartpie1 للنسبة المائوية للذكور و الاناث
الثاني chartpie2 للنسبة العمورية المائوية بين (0 الى 5 سنوات) (6 الى 17 سنة) (18 الى 70 سنة) (70 الى ما فوق)
Imports System.Data.OleDb
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CenterToScreen()
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Me.WindowState = FormWindowState.Maximized
loadchart()
End Sub
Dim dt As New DataTable
Private Sub loadchart()
Dim da As New OleDbDataAdapter("select * from testchart", conn)
da.Fill(dt)
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
'عدد الذكور والاناث
Dim c = Aggregate x As DataRow In dt.Rows
Into Count(x.Item("gender") = "ذكر")
TextBox1.Text = c
Dim m = Aggregate x As DataRow In dt.Rows
Into Count(x.Item("gender") = "انثى")
TextBox2.Text = m
'المجموع
Dim en As Integer = c + m
Dim table = {
New With {.a = "نسبة الذكور", .p = (c / en * 100)},
New With {.a = "نسبة الاناث", .p = (m / en * 100)}
}
'------------------------------------------
TextBox3.Text = en
'----------------------------------------------
'النسبة المئوية
Label4.Text = table(0).p.ToString("0""%")
Label5.Text = table(1).p.ToString("0""%")
Chart1.DataSource = table
Chart1.Legends(0).Enabled = False
Chart1.Series.Clear()
Chart1.Series.Add("Serie1")
Chart1.Series(0).ChartType = SeriesChartType.Pie
Chart1.Series(0).XValueMember = "a"
Chart1.Series(0).YValueMembers = "p"
Chart1.Series(0).IsValueShownAsLabel = True
Chart1.Series(0).Label = ("#PERCENT{P0}\n\n#VALX")
Chart1.Series(0).LabelForeColor = Color.White
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'عدد الذكور والاناث
'من 0 ال 5 سنوات
Dim c1 = Aggregate x As DataRow In dt.Rows
Where CInt(x.Item("age")) <= 5
Into Count()
TextBox4.Text = c1
'من 6 ال 17 سنوات
Dim c2 = Aggregate x As DataRow In dt.Rows
Where CInt(x.Item("age")) >= 6 And CInt(x.Item("age")) <= 17
Into Count()
TextBox5.Text = c2
'من 18 ال 70 سنوات
Dim c3 = Aggregate x As DataRow In dt.Rows
Where CInt(x.Item("age")) >= 18 And CInt(x.Item("age")) <= 70
Into Count()
TextBox6.Text = c3
'من 71 الى ما فوق
Dim c4 = Aggregate x As DataRow In dt.Rows
Where CInt(x.Item("age")) >= 71
Into Count()
TextBox7.Text = c4
'المجموع
Dim en As Integer = c1 + c2 + c3 + c4
'النسبة المئوية
Dim table = {
New With {.a = "أقل من 5 سنوات", .p = (c1 / en * 100)},
New With {.a = "من 6 الى 17 سنوات", .p = (c2 / en * 100)},
New With {.a = "من 18 ال 70 سنوات", .p = (c3 / en * 100)},
New With {.a = "من 71 الى ما فوق", .p = (c4 / en * 100)}
}
Chart2.DataSource = table
Chart2.ChartAreas(0).Area3DStyle.Enable3D = True
Chart2.Legends(0).Enabled = False
Chart2.Series.Clear()
Chart2.Series.Add("Serie1")
Chart2.Series(0).ChartType = SeriesChartType.Pie
Chart2.Series(0).XValueMember = "a"
Chart2.Series(0).YValueMembers = "p"
Chart2.Series(0).IsValueShownAsLabel = True
Chart2.Series(0).Label = ("#PERCENT{P0}\n\n#VALX")
Chart2.Series(0)("PieLabelStyle") = "Outside"
End Sub
End Class