B4J Question Using jchart class library to dynamically obtain pie chart data from database, what is the problem?

guandjy

Member
Using jchart to dynamically obtain pie chart data from the database, what is the problem?:
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        req.PrintTable(res)
'PIE CHART
        PieChart.Initialize("PC")
        PieChart.Title = "Pie Chart"
        PieChart.LabelLineLength = 10
        B4XPages.GetNativeParent(Me).RootPane.AddNode(PieChart,620,100,300,300)
        Dim m As Int
        Dim data1() As PieData
       
        For Each row() As Object In res.Rows
            Dim val2 As String = row(res.Columns.Get("feiyongguiji"))
            Dim val3 As Double = row(res.Columns.Get("jine"))
            For m=0 To res.Rows.Size-1
                data1(m).Initialize(val2,val3)
            Next
        Next
        PieChart.AddAllData(data1)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
 

Chris2

Active Member
Licensed User
I think people will struggle to help you with such little information.

For example:
Is the query being sent to a jRDC2 server?
What error/problem is occuring when running this code?
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
What is the query being used in cmd and what kind of results are you expecting?
 
Upvote 0

Chris2

Active Member
Licensed User
Having said that, to me this section doesn't look correct:
B4X:
        For Each row() As Object In res.Rows
            Dim val2 As String = row(res.Columns.Get("feiyongguiji"))
            Dim val3 As Double = row(res.Columns.Get("jine"))
            For m=0 To res.Rows.Size-1
                data1(m).Initialize(val2,val3)
            Next
        Next
This looks like you're itterating over the results within an itteration of the results, so (I think) you'll end up with all the items in data1() being the same (from the last result in res.Rows)

Try something like (untested, might be completely wrong!):
B4X:
Dim data1() As PieData
Dim x as int = 0
For Each row() As Object In res.Rows
       Dim val2 As String = row(res.Columns.Get("feiyongguiji"))
       Dim val3 As Double = row(res.Columns.Get("jine"))
     
       data1(x).Initialize(val2,val3)
       x=x+1
Next
PieChart.AddAllData(data1)
 
Upvote 1
Top