我想创建一个c#图形(多行),我已经将它与sql server数据库连接起来以填充该系列,并且它适用于一行,而另一行却不起作用第一行未显示在图表中,但第二行显示,我不得不将枚举为0和1的序列“仅(意甲1)工作)如果可以提供帮助,请有人检查代码
// dashboard
ArrayList joursvisites = new ArrayList();
ArrayList nombrevisites = new ArrayList();
ArrayList nombreventes = new ArrayList();
ArrayList chffreAffaire = new ArrayList();
#region dashboard
private void ventes_visites()
{
string connstr = ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
using(SqlConnection con = new SqlConnection(connstr))
{
string query = "SELECT cast(d.Jours AS INT) as jours, count(d.ID_Visiteur) as nombre_visite, " +
"cast(count(dl.ProduitChoisit) AS INT) as nombre_ventes, " +
"cast(sum(dl.PrixPayé) AS INT) as chiffre_affaire " +
"FROM dbo.Deal as dl JOIN dbo.DateVisite as d " +
"ON dl.ID_Date = d.ID_Date " +
"GROUP BY d.Jours " +
"ORDER By Jours ASC";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
joursvisites.Add(reader.GetInt32(0));
nombrevisites.Add(reader.GetInt32(1));
nombreventes.Add(reader.GetInt32(2));
chffreAffaire.Add(reader.GetInt32(3));
}
chart1.Series[0].Points.DataBindXY(joursvisites, nombrevisites);
chart1.Series[1].Points.DataBindXY(joursvisites, nombreventes);
chart2.Series[0].Points.DataBindXY(joursvisites, chffreAffaire);
reader.Close();
con.Close();
}
}
#endregion
public void LoadMultiLineChart(){
string query = "SELECT ShipCountry, DATEPART(Year, OrderDate) [Year],
COUNT(OrderId)[总计]“;
query += " FROM Orders WHERE ShipCountry IN ('France', 'Germany', 'Brazil')";
query += " GROUP BY ShipCountry, DATEPART(Year, OrderDate)";
DataTable dt = GetData(query);
List<string> countries = (from p in dt.AsEnumerable()
select p.Field<string("ShipCountry")).Distinct().ToList();
if (Chart1.Series.Count() == 1)
{
Chart1.Series.Remove(Chart1.Series[0]);
}
foreach (string country in countries)
{
int[] x = (from p in dt.AsEnumerable()
where p.Field<string>("ShipCountry") == country
orderby p.Field<int>("Year") ascending
select p.Field<int>("Year")).ToArray();
int[] y = (from p in dt.AsEnumerable()
where p.Field<string>("ShipCountry") == country
orderby p.Field<int>("Year") ascending
select p.Field<int>("Total")).ToArray();
Chart1.Series.Add(new Series(country));
Chart1.Series[country].IsValueShownAsLabel = true;
Chart1.Series[country].BorderWidth = 3;
Chart1.Series[country].ChartType = SeriesChartType.Line;
Chart1.Series[country].Points.DataBindXY(x, y);
}
Chart1.Legends[0].Enabled = true;
}
私有静态数据表GetData(字符串查询){字符串constr = @“数据源=。\ SQL2005;初始目录= Northwind;用户ID = sa;密码= pass @ 123”;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlDataAdapter sda = new SqlDataAdapter(query, con))
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}