locked
Use expression in winform chart y Series RRS feed

  • Question

  • In my winform app ,

    1. i want to use chart from toolbox (instead of making on using RDLC report).
    2. Using two columns of my access database source (Size_in_mg , And count of "ID column")
    3. But in Y axis i want to use expression like =Count((Fields!Number.Value)) but the chart won't allow me to as it simply takes names of he column.
    4. i have tried searching in web but didn't find convincing result. So please share any link or share your knowledge so that i can learn

    • Moved by CoolDadTx Thursday, August 6, 2020 2:15 PM Winforms related
    Thursday, August 6, 2020 3:40 AM

All replies

  • Hi Ravi Kumar12233,

    Thank you for posting here.

    You can modify your SQL statement like this:

    SELECT COUNT(Id) count, Size_in_mg FROM Table1 GROUP BY Size_in_mg; 

                string connString = @"";
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    conn.Open();
                    using (SqlCommand command = new SqlCommand("SELECT COUNT(Id) count, Size_in_mg FROM Table1 GROUP BY Size_in_mg; ",conn))
                    {
                        SqlDataReader sqlDataReader = command.ExecuteReader();
                        chart1.Series[0].XValueMember = "Size_in_mg";
                        chart1.Series[0].YValueMembers = "count";
                        chart1.DataSource = sqlDataReader;
                        chart1.DataBind();
                    }
                }

    Result:

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 6, 2020 7:29 AM