Solved

C# chart - sharepoint 2010

Posted on 2014-04-24
8
593 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now