# Chart (or array) error

**URL:** <https://forum.xojo.com/t/chart-or-array-error/75783>\
**Category:** Web\
**Created:** [May 16, 2023, 10:16pm UTC](https://forum.xojo.com/t/chart-or-array-error/75783 "2023-05-16T22:16:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_Vassalotti](https://forum.xojo.com/user_avatar/forum.xojo.com/gary_vassalotti/32/444_2.png) [@Gary\_Vassalotti](https://forum.xojo.com/u/Gary_Vassalotti)\
**Post date:** [May 16, 2023, 10:16pm UTC](https://forum.xojo.com/t/chart-or-array-error/75783/1 "2023-05-16T22:16:00Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Wayne\_Golding](https://forum.xojo.com/user_avatar/forum.xojo.com/wayne_golding/32/165_2.png) [@Wayne\_Golding](https://forum.xojo.com/u/Wayne_Golding)\
**Post date:** [May 17, 2023, 12:56am UTC](https://forum.xojo.com/t/chart-or-array-error/75783/2 "2023-05-17T00:56:55Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [May 17, 2023, 5:57am UTC](https://forum.xojo.com/t/chart-or-array-error/75783/3 "2023-05-17T05:57:45Z")

</div>

> [@Gary\_Vassalotti](#):
>
> but my code crashes each time I try to input those values into an array for the chart to use:

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?

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [May 17, 2023, 8:42am UTC](https://forum.xojo.com/t/chart-or-array-error/75783/4 "2023-05-17T08:42:22Z")

</div>

> [@Gary\_Vassalotti](#):
>
> but my code crashes each time I try to input those values into an array for the chart to use:

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

---

<div class="post-metadata">

**Author:** ![Gary\_Vassalotti](https://forum.xojo.com/user_avatar/forum.xojo.com/gary_vassalotti/32/444_2.png) [@Gary\_Vassalotti](https://forum.xojo.com/u/Gary_Vassalotti)\
**Post date:** [May 17, 2023, 12:53pm UTC](https://forum.xojo.com/t/chart-or-array-error/75783/5 "2023-05-17T12:53:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [May 17, 2023, 1:23pm UTC](https://forum.xojo.com/t/chart-or-array-error/75783/6 "2023-05-17T13:23:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gary\_Vassalotti](https://forum.xojo.com/user_avatar/forum.xojo.com/gary_vassalotti/32/444_2.png) [@Gary\_Vassalotti](https://forum.xojo.com/u/Gary_Vassalotti)\
**Post date:** [May 17, 2023, 2:38pm UTC](https://forum.xojo.com/t/chart-or-array-error/75783/7 "2023-05-17T14:38:06Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Gary\_Vassalotti](https://forum.xojo.com/user_avatar/forum.xojo.com/gary_vassalotti/32/444_2.png) [@Gary\_Vassalotti](https://forum.xojo.com/u/Gary_Vassalotti)\
**Post date:** [May 17, 2023, 2:48pm UTC](https://forum.xojo.com/t/chart-or-array-error/75783/8 "2023-05-17T14:48:02Z")

</div>

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