Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# chart - sharepoint 2010

Posted on 2014-04-24
8
Medium Priority
?
616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 32

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 32

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
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
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 32

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 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