Solved

C# chart - sharepoint 2010

Posted on 2014-04-24
8
611 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

623 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