Solved

C# chart - sharepoint 2010

Posted on 2014-04-24
8
600 Views
Last Modified: 2014-05-02
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
0
Comment
Question by:ukerandi
  • 5
  • 3
8 Comments
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 40022036
The Load event is 'Chart1'.

The click event is 'Chart2'.
0
 
LVL 10

Author Comment

by:ukerandi
ID: 40022490
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
0
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 40022503
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

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 10

Author Comment

by:ukerandi
ID: 40022531
I change the code
this.chrtSalesMonthData.Click += new ImageMapEventHandler(this.chrtSalesMonthData_Click);

But still Not working
0
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 40022541
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?
0
 
LVL 10

Author Comment

by:ukerandi
ID: 40022600
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
0
 
LVL 10

Accepted Solution

by:
ukerandi earned 0 total points
ID: 40026200
i found the way to do that.
using Request.Querystring
0
 
LVL 10

Author Closing Comment

by:ukerandi
ID: 40036640
I found the solution
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question