Click here to Skip to main content
14,927,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Table which will be loaded in a DataGridView From SQL-Server and it will have columns Like Days, Month , and Year. I want to plot Year and Month in X axis and The Day Count in Y axis. Am new to .Net .Is there any way to do this ??

1 solution

Drop a Chart control on your form, and DataBind it to the same source as the DataGridView.
Set the Series.XValueMember to the name of the property in your class you want along the X axis, and the Series.YValueMembers to the Y axis property.

If you need to plot from two columns as one axis value then that's a pain - and normally indicates that your data source is badly designed: you should be using a DateTime value instead of holding separate Year, Month, and Day values as it's far, far to easy to get invalid dates with separates.
But...just create a new class that holds a DateTime and a Count properties, and create a List of them, which each instance holding a DateTime created from Year and Month, with the Day set to the first. Use that list as the datasource for the Chart, and set the x and y members appropriately.
Member 11858080 29-Nov-15 6:10am
Thank you for your kind reply, I have added the Chart control and binded the datasource, and now the chart is ready, now I am able to plot it but I dont know how to code for count of days any Idea ??

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