Hi everyone, I am new in Charts in vb.net, i have this code and and these connection to get data from SQL Server, Here is the code in vb.net
Private Sub LoadDataGrocery()
Chart1.DataSource = GetData_Grocery()
Chart1.DataSource = GetData_Vacation()
Chart1.DataSource = GetData_Electronics()
Chart1.DataSource = GetData_FixCosts()
Chart1.DataSource = GetData_Clothes()
Chart1.DataSource = GetData_Other()
'Grocery
Chart1.Series("Grocery").Points.Clear()
Chart1.Series("Grocery").Color = Color.FromArgb(172, 126, 241)
Chart1.Series("Grocery").XValueMember = "Year"
Chart1.Series("Grocery").YValueMembers = "Total"
'Vacation
Chart1.Series("Vacation").Points.Clear()
Chart1.Series("Vacation").Color = Color.FromArgb(100, 200, 255)
Chart1.Series("Vacation").XValueMember = "Year"
Chart1.Series("Vacation").YValueMembers = "Total"
'Electronics
Chart1.Series("Electronics").Points.Clear()
Chart1.Series("Electronics").Color = Color.FromArgb(249, 118, 176)
Chart1.Series("Electronics").XValueMember = "Year"
Chart1.Series("Electronics").YValueMembers = "Total"
'Clothes
Chart1.Series("Clothes").Points.Clear()
Chart1.Series("Clothes").Color = Color.FromArgb(253, 138, 114)
Chart1.Series("Clothes").XValueMember = "Year"
Chart1.Series("Clothes").YValueMembers = "Total"
'FixCost
Chart1.Series("Fix Costs").Points.Clear()
Chart1.Series("Fix Costs").Color = Color.FromArgb(220, 20, 60)
Chart1.Series("Fix Costs").XValueMember = "Year"
Chart1.Series("Fix Costs").YValueMembers = "Total"
'Other
Chart1.Series("Other").Points.Clear()
Chart1.Series("Other").Color = Color.FromArgb(24, 161, 251)
Chart1.Series("Other").XValueMember = "Year"
Chart1.Series("Other").YValueMembers = "Total"
End Sub
and this is the function that i get data :
Private Function GetData_Grocery() As DataTable
Dim dtChartData As New DataTable()
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("db").ConnectionString)
Using cmd As New SqlCommand("Chart_Grocery", conn) ' Total working hours in the month -- step3
cmd.CommandType = CommandType.StoredProcedure
conn.Open()
cmd.Parameters.AddWithValue("@FromYear2", DateTimePickerfrom.Text) '--step3
cmd.Parameters.AddWithValue("@toYear2", DateTimePickerto.Text) '--step3
Dim reader As SqlDataReader = cmd.ExecuteReader()
dtChartData.Load(reader)
End Using
End Using
Return dtChartData
End Function
And exactly like this, I have for each Chart in my database
Chart_Grocery
Chart_Clothes
Chart_Electronics
Chart_Vacation
Chart_Other
Chart_FixCost
What I have tried:
And in my SQL script this is what I have used to get the data :
ALTER Procedure [dbo].[Chart_Clothes]
(
@FromYear2 NVARCHAR(50)
,@toYear2 NVARCHAR(50)
)
AS
Begin
Select SUM(Price) AS 'Total'
,CONVERT(char(7), date, 120) as 'year'
--Department = 'Grocery'
From [dbo].[Expenses]
Where Department = 'Clothes'
Group BY CONVERT(char(7), date, 120)
Having CONVERT(char(7), date, 120) >= @FromYear2 And CONVERT(char(7), date, 120) <= @toYear2
End
For each chart, this function is used except the chart_name above and Department,
I don't know where is the issue why it shows me data only in one line.
There is no error just no information.
Thank you