Click here to Skip to main content
15,565,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
So I want a week of data, with the cell 0 in my datagridview being the date column (to be displayed as the X-axis for my chart) and the cell 1 in my datagridview being the data column (to be displayed as the Y-axis for my chart).

Then once if you could hopefully help me out with that, I need to somehow get the chart to display the next week set of data, using a button or something.

So, in the end, I want the chart to display the data in either weekly (7 days) or (if another tab is select) monthly (31 days) with the data in the datagridview being sorted.

The problem is: With the code that I have given, it does the loop, but doesn't display the data on the chart. I tried googling but I couldn't find something that would relate to mine and got a bit lost with what to do and search, so please don't hammer me on that...

Hope that makes sense!!

What I have tried:

Private Sub tmrMonitor_Tick(sender As Object, e As EventArgs) Handles tmrMonitor.Tick
        Dim Y As Integer
        Dim X As Date

        Dim StartDate As DateTime = "18/07/2020"
        Dim EndDate As DateTime = "17/08/2020"

        Select Case tbctrlDisplay.SelectedIndex
            Case 0
                While counter < dgvUserData.RowCount
                    Do Until counter = 7
                        Date.TryParse(dgvUserData.Rows(counter).Cells(0).Value, X)
                        lblTimeMonitored.Text = X.ToString
                        Integer.TryParse(dgvUserData.Rows(counter).Cells(1).Value, Y)
                        lblPulseValue.Text = Y.ToString()

                        If StartDate <= X And EndDate >= X Then

                            counter = counter + 1
                            chrtWeekly.Series("Beats Per Minute").Points.AddXY(X.ToString, Y.ToString)
                        End If
                    Loop
                End While

                
        End Select
Posted
Updated 20-Aug-20 18:35pm
v2

1 solution

Ignore this - I misread your question What I would do, is attach a Binding/DataSource to the DataGridView, then set the filter to (whatever) .. for example,
bs.Filter = string.Format("Date Between #{0:yyyy/MM/dd}# And #{1:yyyy/MM/dd}#", startDate, endDate);

Ok, you don't say how your datagridview is populated .. I generally find that using a BindingSource gives a lot of flexibility (which is why I went off tangent in my first thought) .. so, I would suggest looking at using a datatable and bindingsource for your chart .. this gives a a bit of flexibility, including
1) I think you could fill the chart datatable using linq from the datagridview datatable, ie a query between your two data ranges
2) you could manually fill the chart datatable either from your datagridview directly or from the datagridview datatable
3) you could conceivably use the same bindingsource filter on both datagridview and chart

I haven't done it for eons, but I think a change to the datatable or bindingsource forces a refresh, which is how your chart would 'redisplay' when you change data/filter - or Im pretty sure it's easy enough to 'tell the chart to refresh' - that covers this 'wish'
Quote:
So, in the end, I want the chart to display the data in either weekly (7 days) or (if another tab is select) monthly (31 days) with the data in the datagridview being sorted.
[Edit] Worth having a look at, can the chart binding source select the columns from the datagridview datatable ? if so, then your job is even easier - this might help Binding Data to Series (Chart Controls) | Microsoft Docs[^] [/Edit]
 
Share this answer
 
v3
Comments
Merscy 21-Aug-20 1:44am    
Yeah sorry, I forgot to tell. It does have a binding with access.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900