cogier wrote: ↑Thursday 8th August 2024 2:27pm
I discovered that you need
DrawingArea1.Refresh if the Form is already open.
I modified the code in your last post as below:-
Hi Cogier,
I update my code and if I use your example data it works perfectly but If I try to use data from my database I just a blank chart.
below is the updated code that I use to generate the chart
Dim DataFromDatabase_Sale As Float[] = [0, GetChartDAta_1("Sale", 1), GetChartDAta_1("Sale", 2),
GetChartDAta_1("Sale", 3), GetChartDAta_1("Sale", 4), GetChartDAta_1("Sale", 5),
GetChartDAta_1("Sale", 6), GetChartDAta_1("Sale", 7), GetChartDAta_1("Sale", 8),
GetChartDAta_1("Sale", 9), GetChartDAta_1("Sale", 10), GetChartDAta_1("Sale", 11),
GetChartDAta_1("Sale", 12)]
Dim DataFromDatabase_Refund As Float[] = [0, GetChartDAta_1("Refund", 1), GetChartDAta_1("Refund", 2),
GetChartDAta_1("Refund", 3), GetChartDAta_1("Refund", 4), GetChartDAta_1("Refund", 5),
GetChartDAta_1("Refund", 6), GetChartDAta_1("Refund", 7), GetChartDAta_1("Refund", 8),
GetChartDAta_1("Refund", 9), GetChartDAta_1("Refund", 10), GetChartDAta_1("Refund", 11),
GetChartDAta_1("Refund", 12)]
Chart.CountDataSets = 2
Chart.Colors.Values = [Color.green, Color.red]
Chart.YAxe.ShowIntervalLines = False
Chart.ShowLabels = True
Chart.type = ChartType.ColumnsStacked
Chart.Legend.Title = "Legend"
Chart.Legend.Visible = True
Chart.Legend.Position = Align.Right
Chart.headers.values = ["Sales", "Refunds"]
Chart.CountDataSets = 12
Chart[0].Text = "Month"
Chart[0].values = [12, 0]
Chart.FirstColumnAsLabel = True
Chart[0].Values = [DataFromDatabase_Sale[1], DataFromDatabase_Sale[2], DataFromDatabase_Sale[3], DataFromDatabase_Sale[4], DataFromDatabase_Sale[5], DataFromDatabase_Sale[6], DataFromDatabase_Sale[7], DataFromDatabase_Sale[8], DataFromDatabase_Sale[9], DataFromDatabase_Sale[10], DataFromDatabase_Sale[11], DataFromDatabase_Sale[12]]
Chart[1].Values = [DataFromDatabase_Refund[2], DataFromDatabase_Refund[3], DataFromDatabase_Refund[4], DataFromDatabase_Refund[5], DataFromDatabase_Refund[6], DataFromDatabase_Refund[7], DataFromDatabase_Refund[8], DataFromDatabase_Refund[9], DataFromDatabase_Refund[10], DataFromDatabase_Refund[11], DataFromDatabase_Refund[12]]
DrawingArea1.Refresh ''You seem to need this if the Form is already open
I have updated the GetChartData_1 and this is below
Private Sub GetChartData_1(Mode As String, MonthNumber As Integer) As Float
Dim DataFromModule As String = Null
Dim DataToSplit As New String[1]
DataFromModule = BackOffice_Dashboard_Charts.GetMonthlyTakingsFromDatabase(MonthNumber)
DataToSplit = Split(DataFromModule, "|")
Select Mode
Case "Sale"
Return DataToSplit[0]
Case "Refund"
Return DataToSplit[1]
End Select
End
I have also updted the Sub for getting the data from the Database
Public Function GetMonthlyTakingsFromDatabase(MonthValue As Integer) As String
Dim TotalValuesSales As Integer = 0
Dim TotalValuesRefund As Integer = 0
Dim RequestedDate As String = Null
Dim RequestedEndDate As String = Null
RequestedDate = Format(Now, "yyyy") & "/" & Format(MonthValue, "00") & "/01"
RequestedEndDate = Format(Now, "yyyy") & "/" & Format(MonthValue, "00") & "/31"
Global.BackOfficeQuery = Null
Global.BackOfficeQuery &= "Select "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(cashvalue / 100),0)) as DECIMAL(18,2)) as TotalCash, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(chequevalue / 100),0)) as DECIMAL(18,2)) as TotalCheque, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(cardvalue / 100),0)) as DECIMAL(18,2)) as TotalCard, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(couponvalue / 100),0)) as DECIMAL(18,2)) as TotalCoupon, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(giftvouchervalue / 100),0)) as DECIMAL(18,2)) as TotalGiftVoucher, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(giftcardvalue / 100),0)) as DECIMAL(18,2)) as TotalGiftCard, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(accountvalue / 100),0)) as DECIMAL(18,2)) as TotalAccounts, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(safedropvalue / 100),0)) as DECIMAL(18,2)) as TotalSafeDrop, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(cashvalue_refund / 100),0)) as DECIMAL(18,2)) as TotalCashRefund, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(chequevalue_refund / 100),0)) as DECIMAL(18,2)) as TotalChequeRefund, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(cardvalue_refund / 100),0)) as DECIMAL(18,2)) as TotalCardRefund, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(couponvalue_refund / 100),0)) as DECIMAL(18,2)) as TotalCouponRefund, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(giftvouchervalue_refund / 100),0)) as DECIMAL(18,2)) as TotalGiftVoucherRefund, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(giftcardvalue_refund / 100),0)) as DECIMAL(18,2)) as TotalGiftCardRefund, "
Global.BackOfficeQuery &= "cast(abs(IFNULL(SUM(accountvalue_refund / 100),0)) as DECIMAL(18,2)) as TotalAccountsRefund "
Global.BackOfficeQuery &= "from posfigures "
Global.BackOfficeQuery &= "where datecol BETWEEN '" & RequestedDate & "' and '"
Global.BackOfficeQuery &= RequestedEndDate & "';"
BackofficeDatabase.ConnectToBackOfficeDatabase("Open")
Global.BODataResult = Global.$DBBackOfficeCon.Exec(Global.BackOfficeQuery)
If Global.BODataResult.Available = True Then
TotalValuesSales += Global.BODataResult!TotalCash
TotalValuesSales += Global.BODataResult!TotalCheque
TotalValuesSales += Global.BODataResult!TotalCard
TotalValuesSales += Global.BODataResult!TotalCoupon
TotalValuesSales += Global.BODataResult!TotalGiftVoucher
TotalValuesSales += Global.BODataResult!TotalGiftCard
TotalValuesSales += Global.BODataResult!TotalAccounts
TotalValuesRefund += Global.BODataResult!TotalCashRefund
TotalValuesRefund += Global.BODataResult!TotalChequeRefund
TotalValuesRefund += Global.BODataResult!TotalCardRefund
TotalValuesRefund += Global.BODataResult!TotalCouponRefund
TotalValuesRefund += Global.BODataResult!TotalGiftVoucherRefund
TotalValuesRefund += Global.BODataResult!TotalGiftCardRefund
TotalValuesRefund += Global.BODataResult!TotalAccountsRefund
Return TotalValuesSales & "|" & TotalValuesRefund
End If
End
I can not see where the issue is with the retrieval of the data (the data is store in the database as string but the sql request converts it into float for use on the system)