0

I am using ASP.net Chart control to get the chart. below code which give me correct chart. I want to change my series name dynamically. Right now i hard coded it as d.VENDOR_CODE . I want my name of the series will be the d.VENDOR_CODE which I am getting from my sSQL script from database.

 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;


                }
            }
        }
    }
sony921
  • 109
  • 13

2 Answers2

0

Have you tried:

Chart1.Series[0].Points[0].AxisLabel = "New Name"
Chart1.Series[0].Legend = "New Name"
Chuck
  • 1,001
  • 1
  • 13
  • 19
0

fix this like

  string seriesname = result.Tables[0].Rows[0]["VENDOR_CODE"].ToString();
  Chart1.Series.Add(seriesname);
sony921
  • 109
  • 13