MR.B4A 252 ارسال شده در دیروز در 06:53 اشتراک گذاری ارسال شده در دیروز در 06:53 اگر با Basic4Android (B4A) برنامهنویسی میکنی، این سورس دقیقاً همون چیزیه که دنبالش بودی! 🔥 سورس طراحی نمودار با مقداردهی کامل که بهت امکان میده تنها با چند خط کد، نمودارهای جذاب و حرفهای بسازی. ✅ نمودار خطی (Line Chart) ✅ نمودار ستونی یا میلهای (Bar Chart) ✅ نمودار دایرهای (Pie Chart) 💡 مناسب برای: ✔️ نمایش آمار و گزارش ✔️ داشبوردهای مدیریتی ✔️ اپلیکیشنهای فروشگاهی، مالی، آموزشی و هر پروژهای که نیاز به نمایش دادهها داره. ✨ کدنویسی تمیز، قابل شخصیسازی و آماده استفاده در پروژههای واقعی. 🎯 اگر میخوای ظاهر اپلیکیشنهات حرفهایتر بشه و دادهها رو به زیباترین شکل نمایش بدی، این سورس رو از دست نده. سورس: Sub Globals Private Panel1 As Panel Private Panel2 As Panel Private Panel3 As Panel End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Layout") Dim Data() As Int = Array As Int(12,25,18,40,35,55,48,60) Dim Data2() As Int = Array As Int(12,25,18,40,35,55,48,60) Dim Data3() As Int = Array As Int(12,25,18,40,35,55,48,60) DrawChartline(Data,Colors.Yellow,Colors.Black) DrawBarChart(Data2,Colors.Red,Colors.Black,Colors.Blue,Colors.Cyan,Colors.DarkGray,Colors.Magenta) DrawPieChart(Data3) End Sub Sub Activity_Resume End Sub Sub Activity_Pause (UserClosed As Boolean) End Sub 'نمودار دخطی Sub DrawChartline(Values() As Int, pointcolor As Int, linecolor As Int) If Values.Length < 2 Then Return Dim cvs As Canvas cvs.Initialize(Panel1) cvs.DrawColor(Colors.White) Dim Margin As Float = 30dip Dim MaxValue As Int = 0 'بزرگترین مقدار For Each n As Int In Values If n > MaxValue Then MaxValue = n Next If MaxValue = 0 Then Return Dim StepX As Float = (Panel1.Width - (2 * Margin)) / (Values.Length - 1) Dim i As Int For i = 0 To Values.Length - 2 Dim x1 As Float = Margin + (i * StepX) Dim x2 As Float = Margin + ((i + 1) * StepX) Dim Ratio1 As Float = Values(i) / MaxValue Dim Ratio2 As Float = Values(i + 1) / MaxValue Dim y1 As Float = Panel1.Height - Margin - (Ratio1 * (Panel1.Height - (2 * Margin))) Dim y2 As Float = Panel1.Height - Margin - (Ratio2 * (Panel1.Height - (2 * Margin))) cvs.DrawLine(x1, y1, x2, y2, linecolor, 3dip) cvs.DrawCircle(x1, y1, 5dip, pointcolor, True, 1dip) Next 'رسم آخرین نقطه Dim LastX As Float = Margin + ((Values.Length - 1) * StepX) Dim LastY As Float = Panel1.Height - Margin - ((Values(Values.Length - 1) / MaxValue) * _ (Panel1.Height - (2 * Margin))) cvs.DrawCircle(LastX, LastY, 5dip, pointcolor, True, 1dip) Panel1.Invalidate End Sub 'نمودار خطی 'نمودار ستونی Sub DrawBarChart(Values() As Int,color1 As Int, color2 As Int, color3 As Int, color4 As Int,color5 As Int, _ color6 As Int) Dim cvs As Canvas cvs.Initialize(Panel2) cvs.DrawColor(Colors.White) Dim Margin As Float = 30dip Dim MaxValue As Int = 0 'پیدا کردن بیشترین مقدار For Each n As Int In Values If n > MaxValue Then MaxValue = n Next If MaxValue = 0 Then Return Dim BarCount As Int = Values.Length Dim BarWidth As Float = (Panel2.Width - (2 * Margin)) / BarCount 'آرایه رنگها Dim ColorsArray() As Int = Array As Int( _ color1, _ color2, _ color3, _ color4, _ color5, _ color6 _ ) Dim i As Int For i = 0 To BarCount - 1 Dim BarHeight As Float = (Values(i) / MaxValue) * (Panel2.Height - (2 * Margin)) Dim Left As Float = Margin + (i * BarWidth) Dim Top As Float = Panel2.Height - Margin - BarHeight Dim Right As Float = Left + BarWidth * 0.7 Dim Bottom As Float = Panel2.Height - Margin Dim Rect1 As Rect Rect1.Initialize(Left, Top, Right, Bottom) 'انتخاب رنگ متفاوت برای هر ستون Dim c As Int c = ColorsArray(i Mod ColorsArray.Length) cvs.DrawRect(Rect1, c, True, 0) Next Panel2.Invalidate End Sub 'نمودار ستونی 'نمودار دایره ای Sub DrawPieChart(Values() As Int) Dim cvs As Canvas cvs.Initialize(Panel3) cvs.DrawColor(Colors.White) 'محاسبه مجموع Dim Total As Int = 0 For Each n As Int In Values Total = Total + n Next If Total = 0 Then Return 'رنگ بخش ها Dim ColorsArray() As Int = Array As Int( _ Colors.Red, _ Colors.Blue, _ Colors.Green, _ Colors.Yellow, _ Colors.Magenta, _ Colors.Cyan _ ) Dim Radius As Float = Min(Panel3.Width, Panel3.Height) / 3 Dim CenterX As Float = Panel3.Width / 2 Dim CenterY As Float = Panel3.Height / 2 Dim StartAngle As Float = -90 Dim i As Int For i = 0 To Values.Length - 1 Dim SweepAngle As Float = (Values(i) / Total) * 360 'ساخت یک تکه از دایره Dim Path1 As Path Dim StartX As Float = CenterX + CosD(StartAngle) * Radius Dim StartY As Float = CenterY + SinD(StartAngle) * Radius Path1.Initialize(CenterX, CenterY) Path1.LineTo(StartX, StartY) Dim a As Float For a = StartAngle To StartAngle + SweepAngle Step 5 Dim x As Float = CenterX + CosD(a) * Radius Dim y As Float = CenterY + SinD(a) * Radius Path1.LineTo(x, y) Next Path1.LineTo(CenterX, CenterY) cvs.DrawPath(Path1, ColorsArray(i Mod ColorsArray.Length), True, 0) StartAngle = StartAngle + SweepAngle Next Panel3.Invalidate End Sub 'نمودار دایره ای فقط کافیه این کدهارو داخل برنامت کپی کنی. تهیه و تنظیم مرتضی صباغی MR.B4A کانال ایتا https://eitaa.com/basic4androidlan کانال تلگرام https://t.me/programmingwithb4a 1 نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر تنظیمات بیشتر اشتراک گذاری ...
ارسالهای توصیه شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .
توجه: strong> مطلب ارسالی شما پس از تایید مدیریت برای همه قابل رویت خواهد بود.