Android Question xchart error Bar width = too small !!! Drawing of Bar chart skipped

Makumbi

Well-Known Member
Licensed User
Please help iam getting
B4X:
Bar width = too small !!! Drawing of Bar chart skipped

this is my code
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private chtBar, chtLine,ChartLine2,ChartLine3 As xChart
    Private btnBar, btnLine , btnLine2,BntLine2 As Button
    Private Yrs As String
    Public ChartToDisplay = "Bar" As String
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Curveperformancev2")
    B4XPages.SetTitle(Me, "Performance Analysis") 'Page title
  
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.


Sub B4XPage_Appear
    Log("main page appear")
    FillCharts
    DisplayChart(ChartToDisplay)
End Sub
'my vision on how to display the data
Private Sub FillCharts
    Private lstIDs, lstMarksEng, lstMarksScience, lstMarksSst, lstMarksMaths,lstMarksre, lstNames, lstYears, lstSemesters, lstSubjects,lstTotalagg,lstTotal As List
    Private ResultSet1 As ResultSet
    Private Query As String
    Private StudentName As String
    lstIDs.Initialize
    lstMarksEng.Initialize
    lstMarksScience.Initialize
    lstMarksSst.Initialize
    lstMarksMaths.Initialize
    lstMarksre.Initialize
    lstNames.Initialize
    lstYears.Initialize
    lstSemesters.Initialize
    lstSubjects.Initialize
    lstTotal.Initialize
    lstTotalagg.Initialize
  
    Dim term As String
    term = B4XPages.MainPage.curveextract.terms
    Dim clasrt As String
    clasrt = B4XPages.MainPage.curveextract.classk
  
    Log(term)
    Log(clasrt)
    If clasrt.Contains("P1") Or clasrt.Contains("P2") Or clasrt.Contains("P3")Then
        lstSubjects.Add("Eng")
        lstSubjects.Add("Literacy2")
        lstSubjects.Add("Literacy1")
        lstSubjects.Add("Maths")
        lstSubjects.Add("RE")
    Else
        lstSubjects.Add("Eng")
        lstSubjects.Add("Science")
        lstSubjects.Add("Sst")
        lstSubjects.Add("Maths")
        lstSubjects.Add("RE")
    End If
  
    'Name = "MAKUMBI TARIQ AZIZI"
    'Query = "SELECT Names, Total, Subject FROM Academics WHERE Names = ?"
'    Query = "SELECT ID, Names, Eng, Science, Sst, Maths, Years from students"¨
    StudentName = "Sulaiman"
  
    Query = "SELECT id, Names,Years, Expressed As Semester, engscore as Eng, sciencescore as Science, sstscore as sst, mathsscore as Maths,Totalgrade as Tagg, Totalscore as Total,ire FROM Academicspastv2 WHERE admno = ?"
  
    ResultSet1 = B4XPages.MainPage.SQL.ExecQuery2(Query, Array As String(term))
  
    'Query = "SELECT id, Years, Expressed As Semester, engscore as Eng, sciencescore as Science, sstscore as sst, mathsscore as Maths,Totalgrade as Tagg, Totalscore as Total FROM Academicspastv2  WHERE Admno = '" & term & "'"
    'ResultSet1 = Starter.SQL1.ExecQuery2(Query, Array As String(Name))

    Log(clasrt)
'    ResultSet1 = Starter.SQL1.ExecQuery(Query)
    Do While ResultSet1.NextRow
        lstIDs.Add(ResultSet1.GetLong("id"))
        StudentName=ResultSet1.GetString("Names")
        lstYears.Add(ResultSet1.GetInt("Years"))
        lstSemesters.Add(ResultSet1.Getstring("Semester"))
        'lstSemesters.Add(ResultSet1.GetInt("Semester"))
        lstMarksEng.Add(ResultSet1.GetInt("Eng"))
        lstMarksScience.Add(ResultSet1.GetInt("Science"))
        lstMarksSst.Add(ResultSet1.GetInt("sst"))
        lstMarksMaths.Add(ResultSet1.GetInt("Maths"))
        lstMarksre.Add(ResultSet1.GetInt("ire"))
        lstTotalagg.Add(ResultSet1.GetInt("Tagg"))
        lstTotal.Add(ResultSet1.GetInt("Total"))
    Loop

    'Bar chart
    chtBar.ClearData
    If clasrt.Contains("P1") Or clasrt.Contains("P2") Or clasrt.Contains("P3")Then
        chtBar.AddBar("Eng", xui.Color_Red)
        chtBar.AddBar("Literacy2", xui.Color_Blue)
        chtBar.AddBar("Literacy1", xui.Color_Green)
        chtBar.AddBar("Maths", xui.Color_Yellow)
        chtBar.AddBar("RE", xui.Color_Magenta)
    Else
        chtBar.AddBar("Eng", xui.Color_Red)
        chtBar.AddBar("Science", xui.Color_Blue)
        chtBar.AddBar("Sst", xui.Color_Green)
        chtBar.AddBar("Maths", xui.Color_Yellow)
        chtBar.AddBar("RE", xui.Color_Magenta)
    End If


    For i = 0 To lstIDs.Size - 1
        'chtBar.AddBarMultiplePoint(lstYears.Get(i) & " - " & lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)))
        chtBar.AddBarMultiplePoint(lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i), lstMarksre.Get(i)))
        Yrs=lstYears.Get(i)
  
  
    Next
    chtBar.YAxisName = "Performance of"&"-"&Yrs
    chtBar.Title = StudentName
'    chtBar.XAxisName = "total marks = " & Total
    chtBar.DrawChart
  
    'Line chart
    chtLine.ClearData
    If clasrt.Contains("P1") Or clasrt.Contains("P2") Or clasrt.Contains("P3")Then
        chtLine.AddLine2("Eng", xui.Color_Red, 2dip, "CIRCLE", False, xui.Color_Red)
        chtLine.AddLine2("Literacy2", xui.Color_Blue, 2dip, "CIRCLE", False, xui.Color_Blue)
        chtLine.AddLine2("Literacy1", xui.Color_Green, 2dip, "CIRCLE", False, xui.Color_Green)
        chtLine.AddLine2("Maths", xui.Color_Yellow, 2dip, "CIRCLE", False, xui.Color_Yellow)
        chtLine.AddLine2("RE", xui.Color_Magenta, 2dip, "CIRCLE", False, xui.Color_Magenta)
    Else
        chtLine.AddLine2("Eng", xui.Color_Red, 2dip, "CIRCLE", False, xui.Color_Red)
        chtLine.AddLine2("Science", xui.Color_Blue, 2dip, "CIRCLE", False, xui.Color_Blue)
        chtLine.AddLine2("Sst", xui.Color_Green, 2dip, "CIRCLE", False, xui.Color_Green)
        chtLine.AddLine2("Maths", xui.Color_Yellow, 2dip, "CIRCLE", False, xui.Color_Yellow)
        chtLine.AddLine2("RE", xui.Color_Magenta, 2dip, "CIRCLE", False, xui.Color_Magenta)
    End If
    For i = 0 To lstIDs.Size - 1
        'chtLine.AddLineMultiplePoints(lstYears.Get(i) & " - " & lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)), True)
        chtLine.AddLineMultiplePoints(lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i),lstMarksre.Get(i)), True)
        Yrs=lstYears.Get(i)
    Next
    chtLine.YAxisName =  "Performance of"&"-"&Yrs
    chtLine.Title = StudentName
    chtLine.DrawChart
  
    'Line chart2
    ChartLine2.ClearData
    ChartLine2.AddLine2("TotalAggregates", xui.Color_Red, 2dip, "CIRCLE", False, xui.Color_Red)
    ChartLine2.AddLine2("TotalMarks", xui.Color_Blue, 2dip, "CIRCLE", False, xui.Color_Blue)
    'chtLine.AddLine2("Sst", xui.Color_Green, 2dip, "CIRCLE", False, xui.Color_Green)
    'chtLine.AddLine2("Maths", xui.Color_Yellow, 2dip, "CIRCLE", False, xui.Color_Yellow)
    For i = 0 To lstIDs.Size - 1
        'chtLine.AddLineMultiplePoints(lstYears.Get(i) & " - " & lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)), True)
        ChartLine2.AddLineMultiplePoints(lstSemesters.Get(i), Array As Double(lstTotalagg.Get(i), lstTotal.Get(i)), True)
        Yrs=lstYears.Get(i)
    Next
    ChartLine2.YAxisName =  "Performance of"&"-"&Yrs
    ChartLine2.Title = StudentName
    ChartLine2.DrawChart
  
  
    'Line chart3
    ChartLine3.ClearData
    ChartLine3.AddLine2("TotalAggregates", xui.Color_Red, 2dip, "CIRCLE", False, xui.Color_Red)
    'ChartLine3.AddLine2("TotalMarks", xui.Color_Blue, 2dip, "CIRCLE", False, xui.Color_Blue)
    'chtLine.AddLine2("Sst", xui.Color_Green, 2dip, "CIRCLE", False, xui.Color_Green)
    'chtLine.AddLine2("Maths", xui.Color_Yellow, 2dip, "CIRCLE", False, xui.Color_Yellow)
    For i = 0 To lstIDs.Size - 1
        'chtLine.AddLineMultiplePoints(lstYears.Get(i) & " - " & lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)), True)
        ChartLine3.AddLineMultiplePoints(lstSemesters.Get(i), Array As Double(lstTotalagg.Get(i)), True)
        Yrs=lstYears.Get(i)
    Next
    ChartLine3.YAxisName =  "Performance of"&"-"&Yrs
    ChartLine3.Title = StudentName
    ChartLine3.DrawChart

End Sub

Private Sub DisplayChart(ChartType As String)
    Select ChartType
        Case "Bar"
            chtLine.Visible = False
            ChartLine2.Visible=False
            ChartLine3.Visible=False
            chtBar.Visible = True
            ChartToDisplay = "Bar"
        Case "Line"
            chtBar.Visible = False
            chtLine.Visible = True
            ChartLine2.Visible=False
            ChartLine3.Visible=False
            ChartToDisplay = "Line"
          
        Case "Line2"
            chtBar.Visible = False
            chtLine.Visible = False
            ChartLine3.Visible=False
            ChartLine2.Visible=True
            ChartToDisplay = "Line"
          
        Case "Line3"
            chtBar.Visible = False
            chtLine.Visible = False
            ChartLine2.Visible=False
            ChartLine3.Visible=True
            ChartToDisplay = "Line"
    End Select
End Sub

Private Sub btnBar_Click
    DisplayChart("Bar")
End Sub

Private Sub btnLine_Click
    DisplayChart("Line")
End Sub

Sub btnline2_Click
    DisplayChart("Line2")
End Sub

Sub BntLine2_Click
    DisplayChart("Line2")
End Sub

Sub btnline3_Click
    DisplayChart("Line3")
End Sub

Sub btnline4_Click
    DisplayChart("Line3")
End Sub

below is the data from json that is supposed to be based on to generate the barcodes
B4X:
[{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"MID TERM 1 2019","sstscore":64,"sstgrade":5,"engscore":75,"engrade":3,"mathsscore":49,"mathsgrade":8,"sciencescore":63,"sciencegrade":5,"totalscore":251,"Totalgrade":21,"Division":"2","ire":"","iregrade":"","Years":2019,"atk":1},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"END TERM 1 2019","sstscore":70,"sstgrade":3,"engscore":70,"engrade":3,"mathsscore":60,"mathsgrade":5,"sciencescore":68,"sciencegrade":4,"totalscore":268,"Totalgrade":15,"Division":"2","ire":"","iregrade":"","Years":2019,"atk":2},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"MID TERM2 2019","sstscore":75,"sstgrade":3,"engscore":55,"engrade":6,"mathsscore":71,"mathsgrade":3,"sciencescore":71,"sciencegrade":3,"totalscore":272,"Totalgrade":15,"Division":"2         ","ire":"","iregrade":"","Years":2019,"atk":3},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"END TERM 2 2019","sstscore":59,"sstgrade":6,"engscore":52,"engrade":7,"mathsscore":76,"mathsgrade":3,"sciencescore":61,"sciencegrade":5,"totalscore":248,"Totalgrade":21,"Division":"2         ","ire":"","iregrade":"","Years":2019,"atk":4},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"END TERM 2 2019","sstscore":"","sstgrade":"","engscore":"","engrade":"","mathsscore":"","mathsgrade":"","sciencescore":"","sciencegrade":"","totalscore":0,"Totalgrade":0,"Division":"2         ","ire":"","iregrade":"","Years":2019,"atk":5},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"MID TERM3 2019","sstscore":67,"sstgrade":4,"engscore":52,"engrade":7,"mathsscore":80,"mathsgrade":2,"sciencescore":56,"sciencegrade":6,"totalscore":255,"Totalgrade":19,"Division":"2         ","ire":61,"iregrade":5,"Years":2019,"atk":6},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"MID TERM3 2019","sstscore":"","sstgrade":"","engscore":"","engrade":"","mathsscore":"","mathsgrade":"","sciencescore":"","sciencegrade":"","totalscore":0,"Totalgrade":0,"Division":"2         ","ire":"","iregrade":"","Years":2019,"atk":7},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"END TERM 3 2019","sstscore":67,"sstgrade":4,"engscore":74,"engrade":3,"mathsscore":88,"mathsgrade":2,"sciencescore":60,"sciencegrade":5,"totalscore":289,"Totalgrade":14,"Division":"2         ","ire":75,"iregrade":3,"Years":2019,"atk":8},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Class":"P1","Expressed":"END TERM 3 2019","sstscore":"","sstgrade":"","engscore":"","engrade":"","mathsscore":"","mathsgrade":"","sciencescore":"","sciencegrade":"","totalscore":0,"Totalgrade":0,"Division":"2         ","ire":"","iregrade":"","Years":2019,"atk":9},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"R","Class":"P2","Expressed":"MID TERM 1 2020","sstscore":58,"sstgrade":6,"engscore":57,"engrade":6,"mathsscore":83,"mathsgrade":2,"sciencescore":61,"sciencegrade":5,"totalscore":259,"Totalgrade":19,"Division":"2         ","ire":40,"iregrade":8,"Years":2020,"atk":10},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"R","Class":"P2","Expressed":"MID TERM 1 2020","sstscore":"","sstgrade":"","engscore":"","engrade":"","mathsscore":"","mathsgrade":"","sciencescore":"","sciencegrade":"","totalscore":0,"Totalgrade":0,"Division":"2         ","ire":"","iregrade":"","Years":2020,"atk":11},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"R","Class":"P2","Expressed":"END TERM 2 2020","sstscore":76,"sstgrade":3,"engscore":81,"engrade":2,"mathsscore":95,"mathsgrade":1,"sciencescore":76,"sciencegrade":3,"totalscore":328,"Totalgrade":9,"Division":"1         ","ire":"","iregrade":"","Years":2020,"atk":12},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"R","Class":"P2","Expressed":"END TERM 2 2020","sstscore":"","sstgrade":"","engscore":"","engrade":"","mathsscore":"","mathsgrade":"","sciencescore":"","sciencegrade":"","totalscore":0,"Totalgrade":0,"Division":"1         ","ire":"","iregrade":"","Years":2020,"atk":13}]
 

Attachments

  • xchartmodule.txt
    101.7 KB · Views: 239
Last edited:

Makumbi

Well-Known Member
Licensed User
This means that, according to the number of bars, their width becomes too small. In short you have too many bars for the width of your char chart.
You can check this with the GetMaxNumberBars method.
Can I increase the number of Bars adjusting the maximum number
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
No because the width of the bars will be too small !
But, since version 7.2, you can set a zoom.
Add this line after having added the data and before drawing the chart.
BarChart.SetZoomIndexes(0, 50)
Here you can set the index of the first and last bar to display.
You can see this in the demo program.
 
Upvote 0
Top