Chart (or array) error

I am don’t know what I have that is wrong… I am trying to create a chart from a recordset. The recordset does have data:
MariaDB [va_1]> select date, sum(credit) as tTot, GL_Account from transactions where gl_account LIKE ‘4%’ group by extract(year from date) desc;
±-----------±------------±-----------+
| date | tTot | GL_Account |
±-----------±------------±-----------+
| 2023-01-11 | 38463.6600 | 410000 |
| 2022-01-06 | 155758.4998 | 410000 |
| 2021-10-07 | 88311.5598 | 410000 |
| 2020-11-30 | 86476.4804 | 430000 |
| 2019-12-01 | 68791.2707 | 430000 |
±-----------±------------±-----------+
5 rows in set (0.010 sec)

but my code crashes each time I try to input those values into an array for the chart to use:

if Session.SelCompany.Connect then
  var rsttCompany as recordset = Session.SelCompany.SQLSelect("Select * from company")
    Session.fyend=rsttCompany.Field("fy_month").Value
    VAR tYearEnd as integer = Session.fyend
   Dim rstSales as Recordset = session.SelCompany.SqlSelect("select date, sum(credit) as tTot, GL_Account from transactions where gl_account LIKE '4%' group by extract(year from date) desc;")
  Var tARYear, tINVYear as Date
  
  While not rstSales.EOF
    Var x as Single  = 0
    For x=0 to 4
      tARYear=rstSales.Field("date").DateValue
      arYear(x)=tARYear.Year
      ARTot(x)=rstSales.Field("tTot").Value
      rstSales.MoveNext
    Next x
    Exit While
  Wend
   
   Var ds1 as new WebChartLinearDataset("AR Amount",color.Red, true, ARTot)
  Var ds2 as new WebChartLinearDataset("Year",color.Red, true, arYear)
  ds1.ChartType = WebChartLinearDataset.ChartTypes.Bar
  ds2.ChartType = WebChartLinearDataset.ChartTypes.Bar
  Chart1.AddDatasets(ds1,ds2)
End If

First of all I think you want to use the year as the label. ARTot() needs to be defined as a double.

This code may work better:

if Session.SelCompany.Connect then
  var rsttCompany as recordset = Session.SelCompany.SQLSelect("Select * from company")
  Session.fyend=rsttCompany.Field("fy_month").Value
  VAR tYearEnd as integer = Session.fyend
  Dim rstSales as Recordset = session.SelCompany.SqlSelect("select date, sum(credit) as tTot, GL_Account from transactions where gl_account LIKE '4%' group by extract(year from date) desc;")
  Var tARYear, tINVYear as Date
  Dim ARTot() As Double
  
  Chart1.RemoveAllLabels
  Chart1.RemoveAllDatasets
  
  For Each Row As DatabaseRow In rstSales
    tARYear=rstSales.Field("date").DateValue
    Chart1.AddLabel(tARYear.Year.ToString)
    ARTot.Add(rstSales.Field("tTot").DoubleValue)
  Next
  
  Var ds1 as new WebChartLinearDataset("AR Amount",color.Red, true, ARTot)
  ds1.ChartType = WebChartLinearDataset.ChartTypes.Bar
  Chart1.AddDatasets(ds1)
End If

What do you mean with crash? Do you get a exception? If yes, which one? If you really get a crash do you have information about the crash?

If you don’t give detail then you won’t get any help.

It gives no error message, just exits the subroutine. So, I don’t have more information than that…

So it doesn’t crash. Have you stepped through the code with the debugger to see what it’s doing?

Yes, after the lines that put data into the array (I have tried changing their order) it exits the subroutine… I am going to try Waynes code here in a bit to see if that fixes my issue…

Thanks Wayne… I was able to use your example to make my code work!