Click here to Skip to main content
15,879,348 members
Home / Discussions / C#
   

C#

 
AnswerRe: Getting a list of Key pressed Pin
Kenneth Haugland23-Dec-17 5:10
mvaKenneth Haugland23-Dec-17 5:10 
AnswerRe: Getting a list of Key pressed Pin
Gerry Schmitz23-Dec-17 5:58
mveGerry Schmitz23-Dec-17 5:58 
GeneralRe: Getting a list of Key pressed Pin
Kenneth Haugland23-Dec-17 10:14
mvaKenneth Haugland23-Dec-17 10:14 
GeneralRe: Getting a list of Key pressed Pin
Gerry Schmitz23-Dec-17 18:38
mveGerry Schmitz23-Dec-17 18:38 
SuggestionMessage Closed Pin
21-Dec-17 23:20
professionalmatthewproctor21-Dec-17 23:20 
GeneralRe: Looking for feedback for new .Net / C# error tracking and reporting tool Pin
OriginalGriff22-Dec-17 0:57
mveOriginalGriff22-Dec-17 0:57 
GeneralRe: Looking for feedback for new .Net / C# error tracking and reporting tool Pin
Eddy Vluggen22-Dec-17 4:08
professionalEddy Vluggen22-Dec-17 4:08 
QuestionPopulate graph from datagridview Pin
Member 1125947820-Dec-17 22:51
Member 1125947820-Dec-17 22:51 
Hi All

i am trying to populate a graph from a datagridview
(Not sure if this is the best practice)

i am using a sql pivot script that populates the correct data into the datagrid

It is showing the years (last 3) in column 0 and 12 months starting from column 1.


How do i show 3 series (for the years) and the 12 months on X and the value of each month on Y.



Below my code


Thank you very much





private void DoGraph(string Title)
        {

            string ConString = CString;
            string CmdString = string.Empty;
            using (SqlConnection con = new SqlConnection(ConString))
            {
                dataGridViewYears.DataSource = null;


                CmdString = " SELECT *" +
                " FROM(" +
                    " SELECT" +
                        " year(Date) as [year], left(datename(month, date), 3) as [month]," +
                        " SalesCatRoom as YearSales" +
                    " FROM tblBudgetMaster" +
                    " WHERE DATEPART(yy, date) >= 2015 AND DATEPART(yy, date) <= 2017" +
                " ) as s" +
                " PIVOT" +
                " (" +
                    " SUM(YearSales)" +
                    " FOR[month] IN(jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec)" +
                " )AS pvt";


                SqlCommand cmd = new SqlCommand(CmdString, con);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable("Years");
                
                dt.Dispose();

                sda.Fill(dt);
                dataGridViewYears.DataSource = dt.DefaultView;
                dataGridViewYears.AutoResizeColumns();
                
                
                con.Close();
                chart1.Titles.Clear();
                                            
                ChartArea chartArea1 = new ChartArea();
                chartArea1.AxisX.MajorGrid.LineColor = Color.LightGray;
                chartArea1.AxisY.MajorGrid.LineColor = Color.LightGray;
               
                chartArea1.AxisX.LabelStyle.Font = new Font("Arial", 8);
                chartArea1.AxisY.LabelStyle.Font = new Font("Arial", 8);
                chart1.ChartAreas.Add(chartArea1);



                chart1.Series.Add(new Series());



                chart1.Series[0].XValueMember = dataGridViewYears.Columns[0].DataPropertyName;
                chart1.Series[1].XValueMember = dataGridViewYears.Columns[0].DataPropertyName;
                chart1.Series[0].YValueMembers = dataGridViewYears.Columns[2].DataPropertyName;
                chart1.Series[1].YValueMembers = dataGridViewYears.Columns[3].DataPropertyName;
                chart1.DataSource = dataGridViewYears.DataSource;

               
                chart1.Series[0].Name = "Budget";
                chart1.Series[1].Name = "Actual";
                chart1.Series[0].Label ="#VALY"; //"Y = #VALY\nX = #VALX";
                chart1.Series[0].SmartLabelStyle.Enabled = true;
                chart1.Series[1].Label = "#VALY"; //"Y = #VALY\nX = #VALX";
                chart1.Series[1].SmartLabelStyle.Enabled = true;
                 chart1.Size = new Size(1000, 450);
                chart1.Titles.Add(Title);
                chartArea1.Position.Height = 80;
            }
        }
    }

GeneralRe: Populate graph from datagridview Pin
Ralf Meier21-Dec-17 2:50
mveRalf Meier21-Dec-17 2:50 
GeneralRe: Populate graph from datagridview Pin
Member 1125947821-Dec-17 2:54
Member 1125947821-Dec-17 2:54 
AnswerRe: Populate graph from datagridview Pin
Gerry Schmitz21-Dec-17 10:58
mveGerry Schmitz21-Dec-17 10:58 
QuestionHow can I make a Location-like collapsible properties? Pin
Member 1358759420-Dec-17 18:52
Member 1358759420-Dec-17 18:52 
QuestionRe: How can I make a Location-like collapsible properties? Pin
Richard MacCutchan20-Dec-17 21:36
mveRichard MacCutchan20-Dec-17 21:36 
AnswerRe: How can I make a Location-like collapsible properties? Pin
Ralf Meier21-Dec-17 2:42
mveRalf Meier21-Dec-17 2:42 
AnswerRe: How can I make a Location-like collapsible properties? Pin
Gerry Schmitz21-Dec-17 10:53
mveGerry Schmitz21-Dec-17 10:53 
QuestionAccess a combobox defined in datatemplate Pin
Hervend20-Dec-17 1:18
Hervend20-Dec-17 1:18 
AnswerRe: Access a combobox defined in datatemplate Pin
Gerry Schmitz20-Dec-17 4:15
mveGerry Schmitz20-Dec-17 4:15 
GeneralRe: Access a combobox defined in datatemplate Pin
Hervend20-Dec-17 22:45
Hervend20-Dec-17 22:45 
GeneralRe: Access a combobox defined in datatemplate Pin
Pete O'Hanlon20-Dec-17 23:15
mvePete O'Hanlon20-Dec-17 23:15 
GeneralRe: Access a combobox defined in datatemplate Pin
Hervend21-Dec-17 0:02
Hervend21-Dec-17 0:02 
QuestionLinq to Update multiple fields in the list Pin
Member 984545419-Dec-17 20:36
Member 984545419-Dec-17 20:36 
AnswerRe: Linq to Update multiple fields in the list Pin
Richard Deeming20-Dec-17 2:29
mveRichard Deeming20-Dec-17 2:29 
QuestionRe: Linq to Update multiple fields in the list Pin
Gerry Schmitz20-Dec-17 4:37
mveGerry Schmitz20-Dec-17 4:37 
Questionc sharp windows form application in visual studio Pin
Member 1358596919-Dec-17 20:30
Member 1358596919-Dec-17 20:30 
AnswerRe: c sharp windows form application in visual studio Pin
OriginalGriff19-Dec-17 21:38
mveOriginalGriff19-Dec-17 21:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.