Click here to Skip to main content
16,004,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for the question of chart, I've select data from my database and axis-Y value is value about Quantity of product and axis-X is value of ID_Product

but when i generate bar chart look like this picture

http://image.ohozaa.com/view/86726[^]

i want to set my chart to start from X-axis to value Y-axis like this chart i try many command but i can't fix for this problem

http://image.ohozaa.com/view/86745[^]

this is my code
C#
string sql2 = "select NAME_Product from Product where  Product.ID_Product = '" + idtoselect + "' ";
                        SqlCommand testcommand2 = new SqlCommand(sql2, conn);
                        rdr = testcommand2.ExecuteReader();

                        if (rdr.Read())
                        {
                            test = rdr["NAME_Product"].ToString();
                        }
                        rdr.Close();
 string sql = "SELECT ID_Product,QUANTITY_Product FROM Product  where  Product.NAME_Product = @ID";
                            da = new SqlDataAdapter(sql, conn);
                            da.SelectCommand.Parameters.AddWithValue("@ID", test);


                            datatb = new DataTable();

                            da.Fill(datatb);
   
                            
                            chart1.Series.Add(test);
                            for (int i = 0; i < datatb.Rows.Count; i++)
                            {
                                chart1.Series[test].Points.AddXY(datatb.Rows[i].ItemArray.GetValue(1), datatb.Rows[i].ItemArray.GetValue(0));
                                
                            }
                            chart1.Series[test].ChartArea = "ChartArea1";
                            chart1.Series[test].BorderWidth = 4;
                            chart1.Series[test].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
                            chart1.Series[test].YValueMembers = "QUANTITY_Product";
                            chart1.Series[test].XValueMember = "ID_Product";
                           

                            chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle = 45;



            chart1.DataBind();


And question about sql code. i've problem about sql code i need to choose NAME_Product from ID_Product from Otder1 Table and Product Table but i've sqlerror tell me I can't do that because i 've group by ID_Product already and can't select for name_Product

this's my sql code
<pre lang="SQL">
SELECT sum(QUANTITY_Order) AS quan1,Product.NAME_Product AS test1 
FROM Order1,Product 
where Order1.ID_Product = Product.ID_Product AND Order1.ID_Product = @ID AND DATE_Order BETWEEN @D1 AND @D2 GROUP BY Order1.ID_Product



and the last question , i've simple sql code to select quantity product and Name product from product table and when i generate haven't got error but my chart have not for any data but when i change from NAME_Product to ID_Product data will be shown

C#
string sql = "SELECT NAME_Product,QUANTITY_Product FROM Product  where  Product.NAME_Product = @ID";
                            da = new SqlDataAdapter(sql, conn);

                            da.SelectCommand.Parameters.AddWithValue("@ID", test);


                            datatb = new DataTable();

                            da.Fill(datatb);
                            da.Fill(datatb2);


                            chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
                            chart1.Series.Add(test);
                            for (int i = 0; i < datatb.Rows.Count; i++)
                            {
                                chart1.Series[test].Points.AddXY(datatb.Rows[i].ItemArray.GetValue(1), datatb.Rows[i].ItemArray.GetValue(0));
                                
                            }
                            chart1.Series[test].ChartArea = "ChartArea1";
                            chart1.Series[test].BorderWidth = 4;
                            chart1.Series[test].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
                            chart1.Series[test].YValueMembers = "QUANTITY_Product";
                            chart1.Series[test].XValueMember = "NAME_Product";
                            chart1.Series[test].;


i'm so sorry if i've type some thing wrong i'm not good for english and i newbie for c# too
Posted

Hi Friend,

make your chart type BAR to COLUMN defenitely you will achieve whatever you want:

chart1.Series[test].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column
 
Share this answer
 
Hi VijayChauhan123

thank you . i've fix for the first problem.

thank you so much and i've two problem i can't fix
 
Share this answer
 

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