我的条形图没有显示在我的网页上。通过设置barchat.visible来帮助我了解如何使其显示...那就是错误所在。
public void BindGrid()
{
string query = "select Customer, COUNT([Total Amount]) [Total Amount] from CustomerDebts group by Customer";
DataTable dt = GetData(query);
string[] x = new string[dt.Rows.Count];
decimal[] y = new decimal[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToInt32(dt.Rows[i][1]);
}
BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = y });
BarChart1.CategoriesAxis = string.Join(",", x);
if (x.Length > 3)
{
BarChart1.ChartWidth = (x.Length * 150).ToString();
}
BarChart1.Visible;
}
private static DataTable GetData(string query)
{
DataTable dt = new DataTable();
string constr = TraceBizCommon.Configuration.ConfigSettings.ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
return dt;
}
}
答案 0 :(得分:0)
BarChart.Visible是需要分配的属性,例如;
BarChart.Visible = true;
有关Chart类的更多信息,请参见此处:https://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.chart(v=vs.110).aspx