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
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
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