Link to home
Start Free TrialLog in
Avatar of ukerandi
ukerandiFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# chart - sharepoint 2010

Hi see below my code. iam developeing visual webpart using sharepoint 2010.
if user click on the chart point area i need to get the point value in to the label button.

please check my code and show me where iam doing mistake
void ViewMonthlySalesChart(string EnterSalesPersonName)
        {
            this.chrtSalesMonthData.Load  += new EventHandler(this.Chart1_Load);
            this.chrtSalesMonthData.Click += new ImageMapEventHandler(this.Chart2_Click);
            //this.chrtSalesMonthData.
            //this.chrtSalesMonthData.Click += new EventHandler(this.Chart2_Click);
            
           
            string[] salesPersonID = EnterSalesPersonName.Split('-');
            SqlConnection ChartSalesMonth = new SqlConnection(SqlConnectLive);
            ChartSalesMonth.Open();
            SqlCommand cmdSalesMonth = ChartSalesMonth.CreateCommand();
            string SqlMonthSales = "select SalesAmount,SalesDate from abc_V where slsman='" + salesPersonID[0] + "' order by SalesDate ASC";
            cmdSalesMonth.CommandText = SqlMonthSales; 



            

            chrtSalesMonthData.ImageStorageMode = ImageStorageMode.UseImageLocation;

            chrtSalesMonthData.Legends.Add("Legend");
            chrtSalesMonthData.Width = 800;
            chrtSalesMonthData.Height = 400;
            chrtSalesMonthData.RenderType = RenderType.ImageTag;
            string imagePath = "~/_layouts/ChartImages/";
            chrtSalesMonthData.ImageLocation = imagePath + "SalesMonth_#SEQ(200,30)";
            chrtSalesMonthData.Palette = ChartColorPalette.Berry;

            Title chartTitle = new Title("Sales this Month", Docking.Top, new Font("Calibri", 12, FontStyle.Bold), Color.FromArgb(26, 59, 105));
            chrtSalesMonthData.Titles.Add(chartTitle);
            chrtSalesMonthData.ChartAreas.Add("SalesMonth");

            chrtSalesMonthData.Series.Add("SalesMonth");

            //chrtSalesMonthData.Series["SalesMonth"].LabelToolTip = "test";
            SqlDataReader rdr = cmdSalesMonth.ExecuteReader();

           
            //chartSeries3.Appearance.PointMark.Visible = true;
            int  i=0;
            while (rdr.Read())
            {
                //i=Convert.ToInt32( rdr["SalesDate"].ToString());
                chrtSalesMonthData.Series["SalesMonth"].Points.AddXY(Convert.ToDouble(rdr["SalesDate"].ToString()), Convert.ToDouble(rdr["SalesAmount"].ToString()));
              
                //chrtSalesMonthData.Series["SalesMonth"].AxisLabel = rdr["SalesDate"].ToString();
                //chrtSalesMonthData.Series["SalesMonth"].Points[i].LabelUrl = "http://test/SitePages/test.aspx?id=" + rdr["SalesDate"].ToString();
                chrtSalesMonthData.Series["SalesMonth"].Points[i].LegendMapAreaAttributes = "#VALY";
                chrtSalesMonthData.Series["SalesMonth"].Points[i].PostBackValue = "#VALY";

                //
                i++;
            }
            
          
            rdr.Close();
            cmdSalesMonth.Connection.Close();
            chrtSalesMonthData.Series["SalesMonth"].IsValueShownAsLabel = true;
            chrtSalesMonthData.ChartAreas["SalesMonth"].AxisX.Interval = 1;
            chrtSalesMonthData.ChartAreas["SalesMonth"].AxisX.LabelStyle.Angle = -90;
            //chrtSalesMonthData.Series["SalesMonth"].IsVisibleInLegend = true;
            chrtSalesMonthData.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
            chrtSalesMonthData.BorderColor = Color.FromArgb(26, 59, 105);
            chrtSalesMonthData.BorderlineDashStyle = ChartDashStyle.Solid;
      
            chrtSalesMonthData.Series["SalesMonth"].LabelAngle = -90;

            chrtSalesMonthData.Series["SalesMonth"].Font = new Font("Arial", 8, FontStyle.Bold);
            chrtSalesMonthData.Series["SalesMonth"].CustomProperties = "BarLabelStyle = Bottom";

            

           
           
            chrtSalesMonthData.BorderWidth = 1;
            
            SalesManthChart.Controls.Add(chrtSalesMonthData);
            ChartSalesMonth.Close();

            Series series = chrtSalesMonthData.Series["SalesMonth"];
            //series.IsValueShownAsLabel = true;
            series.PostBackValue = "#VALX";


        }
        //MouseEventArgs
        protected void Chart2_Click(object sender,System.Web.UI.WebControls.ImageMapEventArgs  e)
        {
            //HttpContext.Current.Session["VAL"] = e.PostBackValue;



            Label1.Text ="abc"+ e.PostBackValue.ToString();

           
        }


        protected void Chart1_Load(object sender, EventArgs e)
        {
            Label1.Text = "test";
        }

Open in new window


this part is working fine
 protected void Chart1_Load(object sender, EventArgs e)
        {
            Label1.Text = "test";
        }
But Click event not working
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

The Load event is 'Chart1'.

The click event is 'Chart2'.
Avatar of ukerandi

ASKER

This is code again.
As I said earlier Load event is working fine but click event Not Working
void ViewMonthlySalesChart(string EnterSalesPersonName)
        {
            this.chrtSalesMonthData.Load  += new EventHandler(this.chrtSalesMonthData_Load);
            this.chrtSalesMonthData.Click += new ImageMapEventHandler(this.CchrtSalesMonthData_Click);
            //this.chrtSalesMonthData.
            //this.chrtSalesMonthData.Click += new EventHandler(this.Chart2_Click);
            
           
            string[] salesPersonID = EnterSalesPersonName.Split('-');
            SqlConnection ChartSalesMonth = new SqlConnection(SqlConnectLive);
            ChartSalesMonth.Open();
            SqlCommand cmdSalesMonth = ChartSalesMonth.CreateCommand();
            string SqlMonthSales = "select SalesAmount,SalesDate from abc_V where slsman='" + salesPersonID[0] + "' order by SalesDate ASC";
            cmdSalesMonth.CommandText = SqlMonthSales; 



            

            chrtSalesMonthData.ImageStorageMode = ImageStorageMode.UseImageLocation;

            chrtSalesMonthData.Legends.Add("Legend");
            chrtSalesMonthData.Width = 800;
            chrtSalesMonthData.Height = 400;
            chrtSalesMonthData.RenderType = RenderType.ImageTag;
            string imagePath = "~/_layouts/ChartImages/";
            chrtSalesMonthData.ImageLocation = imagePath + "SalesMonth_#SEQ(200,30)";
            chrtSalesMonthData.Palette = ChartColorPalette.Berry;

            Title chartTitle = new Title("Sales this Month", Docking.Top, new Font("Calibri", 12, FontStyle.Bold), Color.FromArgb(26, 59, 105));
            chrtSalesMonthData.Titles.Add(chartTitle);
            chrtSalesMonthData.ChartAreas.Add("SalesMonth");

            chrtSalesMonthData.Series.Add("SalesMonth");

            //chrtSalesMonthData.Series["SalesMonth"].LabelToolTip = "test";
            SqlDataReader rdr = cmdSalesMonth.ExecuteReader();

           
            //chartSeries3.Appearance.PointMark.Visible = true;
            int  i=0;
            while (rdr.Read())
            {
                //i=Convert.ToInt32( rdr["SalesDate"].ToString());
                chrtSalesMonthData.Series["SalesMonth"].Points.AddXY(Convert.ToDouble(rdr["SalesDate"].ToString()), Convert.ToDouble(rdr["SalesAmount"].ToString()));
              
                //chrtSalesMonthData.Series["SalesMonth"].AxisLabel = rdr["SalesDate"].ToString();
                //chrtSalesMonthData.Series["SalesMonth"].Points[i].LabelUrl = "http://test/SitePages/test.aspx?id=" + rdr["SalesDate"].ToString();
                chrtSalesMonthData.Series["SalesMonth"].Points[i].LegendMapAreaAttributes = "#VALY";
                chrtSalesMonthData.Series["SalesMonth"].Points[i].PostBackValue = "#VALY";

                //
                i++;
            }
            
          
            rdr.Close();
            cmdSalesMonth.Connection.Close();
            chrtSalesMonthData.Series["SalesMonth"].IsValueShownAsLabel = true;
            chrtSalesMonthData.ChartAreas["SalesMonth"].AxisX.Interval = 1;
            chrtSalesMonthData.ChartAreas["SalesMonth"].AxisX.LabelStyle.Angle = -90;
            //chrtSalesMonthData.Series["SalesMonth"].IsVisibleInLegend = true;
            chrtSalesMonthData.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
            chrtSalesMonthData.BorderColor = Color.FromArgb(26, 59, 105);
            chrtSalesMonthData.BorderlineDashStyle = ChartDashStyle.Solid;
      
            chrtSalesMonthData.Series["SalesMonth"].LabelAngle = -90;

            chrtSalesMonthData.Series["SalesMonth"].Font = new Font("Arial", 8, FontStyle.Bold);
            chrtSalesMonthData.Series["SalesMonth"].CustomProperties = "BarLabelStyle = Bottom";

            

           
           
            chrtSalesMonthData.BorderWidth = 1;
            
            SalesManthChart.Controls.Add(chrtSalesMonthData);
            ChartSalesMonth.Close();

            Series series = chrtSalesMonthData.Series["SalesMonth"];
            //series.IsValueShownAsLabel = true;
            series.PostBackValue = "#VALX";


        }
        //MouseEventArgs
        protected void chrtSalesMonthData_Click(object sender,System.Web.UI.WebControls.ImageMapEventArgs  e)
        {
            //HttpContext.Current.Session["VAL"] = e.PostBackValue;



            Label1.Text ="abc"+ e.PostBackValue.ToString();

           
        }


        protected void chrtSalesMonthData_Load(object sender, EventArgs e)
        {
            Label1.Text = "test";
        }

Open in new window


Can some one kindly show me where iam doing mistake
In the line below what is CchrtSalesMonthData_Click? Shouldn't it be chrtSalesMonthData_Click ??

this.chrtSalesMonthData.Click += new ImageMapEventHandler(this.CchrtSalesMonthData_Click);

Open in new window

I change the code
this.chrtSalesMonthData.Click += new ImageMapEventHandler(this.chrtSalesMonthData_Click);

But still Not working
1. Can the control support a normal click event, that could be tried?
2. Could you set some label text without the postbackvalue string to see if the click event does get entered?
1. Can the control support a normal click event, that could be tried?
2. Could you set some label text without the postbackvalue string to see if the click event does get entered?

01. No becuase iam using Chart=new Chart();
    some problem with our server with web.config file, thats the why iam using that. so this is the only option

 so i have to create Event Handler for Click event, Chart Load is working fine
 (chrtSalesMonthData_Load)

But Chart click event its not working. I need to get Chart point value if you know any example or any suggesion greatly apprciate




02. Yes i did.

 using
Lable1.Text="Test"+e.toString();

its not working.

thanks
ASKER CERTIFIED SOLUTION
Avatar of ukerandi
ukerandi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found the solution