Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
330
How to show UltraCategoryChart using SQL resultset?
posted

I am attempting to make my first UltraCategoryChart. I will describe the end result I'd like first. We are comparing quantities for the last three years. So the X axis will be months, January through December. For each month there will be 3 columns grouped together representing each year. So January will have 2018, 2019, and 2020 with those counts supplied by a SQL database query:

select year(acctdate) as year, month(acctdate) as month, FORMAT(AcctDate, 'MMMM') as MyMonthName,count(*) as count from Acct
where year(acctdate) >=2018
group by year(acctdate), month(acctdate), FORMAT(AcctDate, 'MMMM')
order by month(acctdate), year(acctdate)

Resulting in a dataset that looks like this (showing just the first two months here):

2018 1 January 1379
2019 1 January 1948
2020 1 January 1407
2018 2 February 1417
2019 2 February 1136
2020 2 February 1126

I've cobbled together code from online documentation, but I don't see anything on how to create the chart using a SQL database. I've attempted to replace the UltraCategoryChart.DataSource with a SQL DbDataReader resultset, but I get nothing displayed on the chart. There are no errors. Can anyone tell me what is missing?

Dim strSQL As String = "select year(acctdate) as Year, month(acctdate) as Month, FORMAT(AcctDate, 'MMMM') as MonthName,count(*) as Count from Acct " _
& "where year(acctdate) >=2018 " _
& "group by year(acctdate), month(acctdate), FORMAT(AcctDate, 'MMMM') " _
& "order by month(acctdate), year(acctdate)"

Dim adoRs As DbDataReader
adoRs = My.Application.GlobalAuditDB.MExecuteReader(strSQL)

Dim series As New AreaSeries()
Dim xAxis As New CategoryXAxis()
Dim yAxis As New NumericYAxis()

UltraCategoryChart1.ChartType = CategoryChartType.Column
UltraCategoryChart1.DataSource = adoRs

UltraCategoryChart1.IncludedProperties = New String() {"Year", "Month", "Count"}
UltraCategoryChart1.ExcludedProperties = New String() {"MonthName"}

UltraCategoryChart1.Visible = True
UltraCategoryChart1.BringToFront()

Parents Reply Children