I'm a beginner on Visual Basic and Basic4Android.
I would like to type a program which is listing from XML but having some problem which is about from XML to Charting.
I add my code below. If there is any ability, would some one please check for mistake?
Many thanks.
Here I couldn't solve problem for charting.
I would like to type a program which is listing from XML but having some problem which is about from XML to Charting.
I add my code below. If there is any ability, would some one please check for mistake?
Many thanks.
B4X:
Sub Process_Globals
Dim Sube1GrafikParser As SaxParser
Dim Sube2GrafikParser As SaxParser
Dim Sube1GrafikHc As HttpClient
Dim Sube2GrafikHc As HttpClient
Dim Sube1GrafikReq As HttpRequest
Dim Sube2GrafikReq As HttpRequest
Dim KarParser As SaxParser
Dim Karhc As HttpClient
Dim Karreq As HttpRequest
Dim Sube1Tutar,Sube1Musteri,Sube2Tutar,Sube2Musteri As Float
Dim Sube1Subesi,Sube1Tarih,Sube1Ay,Sube2Subesi,Sube2Tarih,Sube2Ay As String
End Sub
Sub Globals
Dim KarAy,KarSatisTutari,KarSatisMaliyeti,KarKarlilik,KarOran,KarMusteriSayisi As String
Dim KarTable As Table
Dim pnlBars As Panel
Dim TabHost1 As TabHost
Dim Graphp As Panel
Dim BD As BarData
Dim G As Graph
Dim SubeTarih,Sube1Tutarlar,Sube2Tutarlar As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("genelgorunum")
SubeTarih.Initialize
Sube1Tutarlar.Initialize
Sube2Tutarlar.Initialize
TabHost1.Initialize("TabHost1")
Graphp.Initialize("")
pnlBars.Initialize("pnlBars")
BD.Initialize
G.Initialize
KarParser.Initialize
Karhc.Initialize("Karhc")
Karreq.InitializeGet("http://www.villafurniture.sd/xml/ags.xml")
Karhc.Execute(Karreq, 1)
KarTable.Initialize(Me, "Karlilik", 6)
KarTable.AddToActivity(Activity, 5, 40, 50.5%x, 100%y)
KarTable.SetHeader(Array As String("AY", "SATIŞ TUTARI", "SATIŞ MALİYETİ", "KARLILIK", "ORAN", "MÜŞTERİ SAYISI"))
KarTable.SetColumnsWidths(Array As Int(50dip, 120dip,140dip,100dip,100dip,140dip))
Sube1GrafikParser.Initialize
Sube1GrafikHc.Initialize("Sube1GrafikHc")
Sube1GrafikReq.InitializeGet("http://www.villafurniture.sd/xml/sube1_cirolar.xml")
' Sube1GrafikReq.InitializeGet("http://www.villafurniture.sd/xml/subeler_cirolar.xml")
Sube1GrafikHc.Execute(Sube1GrafikReq, 2)
Sube2GrafikParser.Initialize
Sube2GrafikHc.Initialize("Sube2GrafikHc")
Sube2GrafikReq.InitializeGet("http://www.villafurniture.sd/xml/sube2_cirolar.xml")
Sube2GrafikHc.Execute(Sube2GrafikReq, 2)
Dim pnlIcerik As Panel
pnlIcerik.Initialize("pnlIcerik")
Activity.AddView(pnlIcerik,5,300,1270,353)
pnlIcerik.Color=Colors.White
Activity.AddView(TabHost1, 645, -75, 640, 380)
TabHost1.AddTab2("Günlük Cirolar",Graphp)
Graphp.AddView(pnlBars, 0, 0, 630, 300)
End Sub
#Region Karlilik
Sub Karhc_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Response.GetAsynchronously("KarRSS", File.OpenOutput(File.DirDefaultExternal, "ags.xml", False), True, TaskId)
End Sub
Sub Karhc_ResponseError(Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If Response <> Null Then
Msgbox("Hata: " & Response.GetString("UTF8"), "Bağlantı Hatası")
Response.Release
End If
End Sub
Sub KarRSS_StreamFinish(Success As Boolean, TaskId As Int)
If Success = False Then
Msgbox(LastException.Message, "Hata Oluştu")
Return
End If
Dim In As InputStream
In = File.OpenInput(File.DirDefaultExternal, "ags.xml")
KarParser.Parse(In, "KarParser")
In.Close
End Sub
Sub KarParser_EndElement(Uri As String, Name As String, Text As StringBuilder)
Karlilik(Name,Text)
End Sub
Sub Karlilik(Name As String, Text As StringBuilder)
If KarParser.Parents.IndexOf("Table") > -1 Then
If Name = "AY" Then
KarAy = Text.ToString
Else If Name = "SATIS_TUTARI" Then
KarSatisTutari = Text.ToString
Else If Name = "SATIS_MALIYETI" Then
KarSatisMaliyeti = Text.ToString
Else If Name = "KARLILIK" Then
KarKarlilik = Text.ToString
Else If Name = "ORAN" Then
KarOran = Text.ToString
Else If Name = "MUSTERI_SAYISI" Then
KarMusteriSayisi = Text.ToString
End If
End If
If Name="Table" Then
KarTable.AddRow(Array As String(KarAy, KarSatisTutari,KarSatisMaliyeti,KarKarlilik,KarOran,KarMusteriSayisi))
End If
End Sub
#End Region
#Region Grafik
#Region Sube1
Sub Sube1GrafikHc_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Response.GetAsynchronously("Sube1GrafikRSS", File.OpenOutput(File.DirDefaultExternal, "sube1_cirolar.xml", False), True, TaskId)
End Sub
Sub Sube1GrafikHc_ResponseError(Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If Response <> Null Then
Msgbox("Hata: " & Response.GetString("UTF8"), "Bağlantı Hatası")
Response.Release
End If
End Sub
Sub Sube1GrafikRSS_StreamFinish(Success As Boolean, TaskId As Int)
If Success = False Then
Msgbox(LastException.Message, "Hata Oluştu")
Return
End If
Dim In As InputStream
In = File.OpenInput(File.DirDefaultExternal, "sube1_cirolar.xml")
Sube1GrafikParser.Parse(In, "Sube1GrafikParser")
In.Close
End Sub
Sub Sube1GrafikParser_EndElement(Uri As String, Name As String, Text As StringBuilder)
If Sube1GrafikParser.Parents.IndexOf("Table") > -1 Then
If Name="TARIH" Then
Sube1Tarih = Text.ToString
Sube1Tarih = Sube1Tarih.SubString2(8,10)
SubeTarih.Add(Sube1Tarih)
Else If Name="TUTAR" Then
Sube1Tutar=Text.ToString
Sube1Tutarlar.Add(Sube1Tutar)
End If
End If
End Sub
#End Region
#Region Sube2
Sub Sube2GrafikHc_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Response.GetAsynchronously("Sube2GrafikRSS", File.OpenOutput(File.DirDefaultExternal, "sube2_cirolar.xml", False), True, TaskId)
End Sub
Sub Sube2GrafikHc_ResponseError(Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If Response <> Null Then
Msgbox("Hata: " & Response.GetString("UTF8"), "Bağlantı Hatası")
Response.Release
End If
End Sub
Sub Sube2GrafikRSS_StreamFinish(Success As Boolean, TaskId As Int)
If Success = False Then
Msgbox(LastException.Message, "Hata Oluştu")
Return
End If
Dim In As InputStream
In = File.OpenInput(File.DirDefaultExternal, "sube2_cirolar.xml")
Sube2GrafikParser.Parse(In, "Sube2GrafikParser")
In.Close
End Sub
Sub Sube2GrafikParser_EndElement(Uri As String, Name As String, Text As StringBuilder)
If Sube2GrafikParser.Parents.IndexOf("Table") > -1 Then
If Name="TUTAR" Then
Sube2Tutar=Text.ToString
Sube2Tutarlar.Add(Sube2Tutar)
End If
End If
If Name="Table" Then
BD.Target = pnlBars
BD.BarsWidth = 15dip
BD.Stacked = False
Charts.AddBarColor(BD, MakeTransparent(Colors.Magenta, 230))
Charts.AddBarColor(BD, MakeTransparent(Colors.Red, 230))
For i = 1 To 31
Dim Sube1 As Int
Dim Sube2 As Int
Sube1=Sube1Tutarlar.Get(1)
Sube2=Sube2Tutarlar.Get(1)
Charts.AddBarPoint(BD, i , Array As Float(Sube1,Sube2))
Next
G.Title = "Günlük Cirolar"
G.XAxis = "Günler"
G.YAxis = "Cirolar"
G.YStart = 0
G.YEnd = 200000
G.YInterval = 20000
G.AxisColor = Colors.Black
Charts.DrawBarsChart(G, BD, Colors.White)
End If
End Sub
#End Region
#End Region
Sub MakeTransparent(Color As Int, Alpha As Int) As Int
Return Bit.And(Color, Bit.Or(0x00FFFFFF, Bit.ShiftLeft(Alpha, 24)))
End Sub
Here I couldn't solve problem for charting.
B4X:
If Name="Table" Then
BD.Target = pnlBars
BD.BarsWidth = 15dip
BD.Stacked = False
Charts.AddBarColor(BD, MakeTransparent(Colors.Magenta, 230))
Charts.AddBarColor(BD, MakeTransparent(Colors.Red, 230))
For i = 1 To 31
Dim Sube1 As Int
Dim Sube2 As Int
Sube1=Sube1Tutarlar.Get(1)
Sube2=Sube2Tutarlar.Get(1)
Charts.AddBarPoint(BD, i , Array As Float(Sube1,Sube2))
Next
G.Title = "G�nl�k Cirolar"
G.XAxis = "G�nler"
G.YAxis = "Cirolar"
G.YStart = 0
G.YEnd = 200000
G.YInterval = 20000
G.AxisColor = Colors.Black
Charts.DrawBarsChart(G, BD, Colors.White)
End If
Last edited: