-
Sep 27th, 2022, 05:25 AM
#1
Thread Starter
Junior Member
Charts from Datagridview
Hi,
Can anyone advise in how I can achieve the following;
I have a datagridview which contains information in the following format;
Name, Sales.
Bill, 400
Fred, 200
James, 200
Jane, 150
Bill, 200
James, 600
Bill, 100
Is there a way for me to visualise this information into a bar chart ?
The names will differ from region to region so I won't know who these individuals are, these can be upto 10 individuals.
Can I somehow get VB.net to show me the information as below from the data above.
Bill, 3
Fred, 1
Jane, 1
James, 2
Any advice would be appreciated.
Many thanks.
-
Sep 28th, 2022, 02:57 AM
#2
Re: Charts from Datagridview
-
Sep 28th, 2022, 04:03 AM
#3
Re: Charts from Datagridview
Converting the data from what you have to what you want and then displaying it in a chart are two completely separate issues.
If you're targeting .NET Framework then the Chart control is in the Data section of the Toolbox, along with the DataGridView. If you're targeting .NET 6 then it's not and I don't think that it's actually been ported to .NET Core, so you would have look elsewhere or switch to .NET Framework. Assuming that you know what chart control you're going to use, you should spend some time to understand it generally, without regard for your current project. Play around with different data sets to see how the control works and do some reading about it.
Once you know how to display a data set in a chart, then you can worry about getting the data set you want in your current project and just feeding it into the control. You can do that using a LINQ query with grouping, which I will post in the near future.
-
Sep 28th, 2022, 05:56 AM
#4
Thread Starter
Junior Member
Re: Charts from Datagridview
Hi,
Yes, I will be using the Charts control within VB.net to visually display the data, the reference to my datagridview was to state that's where my source will come from.
I will have a look at different data sets and look further into how the control works.
Thank you for your guidance.
-
Sep 28th, 2022, 06:13 AM
#5
Re: Charts from Datagridview
Is you grid bound to anything, e.g. a DataTable?
-
Sep 28th, 2022, 06:27 AM
#6
Thread Starter
Junior Member
Re: Charts from Datagridview
-
Sep 28th, 2022, 06:53 AM
#7
Re: Charts from Datagridview
I was going to post a LINQ solution but I actually don't think that's a good idea. You should use a solution that you understand and you should actually apply some logic yourself to come up with a solution rather than just waiting for someone else to write it for you. Think about how you'd do this if it were a purely manual process. That will give you the logic involved and you can then write code to implement that logic. Don't try to write code before you understand what that code has to do.
If doing it manually, you'd got through the items one by one - that's a loop in programming - and for each item (Hey, doesn't VB have a For Each loop?) you would check a list to see if you have already recorded that name. If you haven't, you'd add the name with a count of 1. If you have, you'd increment the count for that name by 1. At then end of the loop, your list contains all the names and a count of the times they appear in the original list. That's the logic so you should try to write code to implement that specifically. Ideally, you'd formalise the logic into an algorithm first. If you have any issues with the code, you can always refer to the algorithm to check that the code is doing exactly what it should. If you need our help, you can point to the specific step in the algorithm that you're having trouble with.
-
Oct 4th, 2022, 05:02 AM
#8
Banned
Re: Charts from Datagridview
Originally Posted by Serial
Hi,
Can anyone advise in how I can achieve the following;
I have a datagridview which contains information in the following format;
Name, Sales.
Bill, 400
Fred, 200
James, 200
Jane, 150
Bill, 200
James, 600
Bill, 100
Is there a way for me to visualise this information into a bar chart ?
The names will differ from region to region so I won't know who these individuals are, these can be upto 10 individuals.
Can I somehow get VB.net to show me the information as below from the data above.
Bill, 3
Fred, 1
Jane, 1
James, 2
Any advice would be appreciated.
Many thanks.
I think this information will be useful for you https://stackoverflow.com/questions/...dview-to-chart
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|