我正在使用ASP.net图表控件来获取图表。下面的代码给我正确的图表。我想动态更改我的系列名称。现在我把它硬编码为d.VENDOR_CODE
。我希望我的系列名称是d.VENDOR_CODE,我从我的sSQL脚本中获取数据库。
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["eFoxNetConnectionString"].ConnectionString);
String sSQL = "SELECT d.VENDOR_CODE, RTRIM(LTRIM(cast(datename(month, d.Dates) as char(15))))+',' + RTRIM(LTRIM(cast(year(d.Dates) as char(20)))) as [CLOSED_DATE], ISNULL(c.No_of_Case,'0')as No_of_Case FROM (SELECT DISTINCT a.VENDOR_CODE, b.dates AS Dates FROM dbo.FTX_FA_CASE a JOIN ( SELECT dates FROM dbo.FTX_FA_Calender WITH (NOLOCK) WHERE Dates > '2015-06-01'AND Dates < GETDATE() ) b ON 1=1) d LEFT JOIN (select t.vendor_code, [CLOSED_DATE] as [CLOSED_DATE],count(t.vendor_code) as [No_of_Case] from dbo.FTX_FA_CASE t WITH (NOLOCK) where [CLOSED_DATE] is not null group by t.vendor_code, CLOSED_DATE) c ON c.vendor_code=d.vendor_code AND DATEADD(m, DATEDIFF(m, 0, d.dates), 0) = DATEADD(m, DATEDIFF(m, 0, c.CLOSED_DATE), 0) where d.vendor_code='ACEA' ORDER BY d.VENDOR_CODE, d.Dates";
SqlCommand cmd = new SqlCommand(sSQL, con);
con.Open();
cmd.Connection = con;
using (SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
{
using (DataSet result = new DataSet())
{
DataTable Table1 = new DataTable();
result.Tables.Add(Table1);
result.Load(dr, LoadOption.OverwriteChanges, Table1);
if (result.Tables[0].Rows.Count > 0)
{
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart1.BorderlineColor = System.Drawing.Color.FromArgb(26, 59, 105);
Chart1.BorderlineWidth = 3;
//Chart1.BackColor = Color.RoyalBlue;
Chart1.ChartAreas.Add("chtArea");
Chart1.ChartAreas[0].AxisX.Title = "CLOSED_DATE";
Chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Verdana", 11, System.Drawing.FontStyle.Bold);
Chart1.ChartAreas[0].AxisY.Title = "No_of_Case";
Chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Verdana", 11, System.Drawing.FontStyle.Bold);
Chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
Chart1.ChartAreas[0].BorderWidth = 2;
Chart1.Legends.Add("No_of_Case");
Chart1.Series.Add(d.VENDOR_CODE);
Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
Chart1.Series[0].Points.DataBindXY(result.Tables[0].DefaultView, "CLOSED_DATE", result.Tables[0].DefaultView, "No_of_Case");
Chart1.Series[0].IsVisibleInLegend = true;
Chart1.Series[0].IsValueShownAsLabel = true;
Chart1.Series[0].BorderWidth = 3;
//// Chart1.Series[0].Color = Color.Red;
}
}
}
}
答案 0 :(得分:0)
你试过了吗?
Chart1.Series[0].Points[0].AxisLabel = "New Name"
Chart1.Series[0].Legend = "New Name"
答案 1 :(得分:0)
修复此问题
string seriesname = result.Tables[0].Rows[0]["VENDOR_CODE"].ToString();
Chart1.Series.Add(seriesname);