Unanswered exploded pie

  • Sunday, May 13, 2012 10:15 AM
     
      Has Code

    Hi,

    I have created a pie chart which explodes whenever I click a slice.

    The thing is, whenever the user clicks the exploded slice again, I want it to change the Exploded property to false.

    How can I check the slice's custom property?  I use postback and I think the property is reset to false whenever I click a slice.

    This is my c# code:

    protected void Chart1_Click(object sender, ImageMapEventArgs e)
            {
                int pointIndex = int.Parse(e.PostBackValue);
                Chart chartCtl = (Chart)Panel1.FindControl("Chart1");
                Series series = chartCtl.Series["Series1"];
                chartCtl.DataBind();
                if (pointIndex >= 0 && pointIndex < series.Points.Count)
                {
                    series.Points[pointIndex].CustomProperties += "Exploded=true";
                }
            }

    and this is what I wrote for the Onload function:

                Chart chartCtl = (Chart)Panel1.FindControl("Chart1");
                Series series = chartCtl.Series["Series1"];
    
                series.PostBackValue = "#INDEX";

All Replies

  • Thursday, May 24, 2012 4:46 AM
     
     

    Hi qsoft_developer,

    you can use mouse down event as follows

    Private Sub chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chart1.MouseDown

    Dim result As HitTestResult = chart1.HitTest(e.X, e.Y)
                Dim exploded As Boolean

                If result.PointIndex = -1 Then Exit Sub

                If chart1.Series(0).Points(result.PointIndex).CustomProperties = "Exploded=true" Then
                    exploded = True
                Else
                    exploded = False
                End If

                Dim point As DataPoint
                For Each point In chart1.Series(0).Points
                    point.CustomProperties = ""
                Next point

                If exploded Then
                    Return
                End If

                If result.ChartElementType = ChartElementType.DataPoint Then
                    point = chart1.Series(0).Points(result.PointIndex)
                    point.CustomProperties = "Exploded = true"
                End If

                If result.ChartElementType = ChartElementType.LegendItem Then
                    point = chart1.Series(0).Points(result.PointIndex)
                    point.CustomProperties = "Exploded = true"
                End If

    End Sub


    Sandeep J. Sharma (eZee Technosys)


  • Thursday, May 24, 2012 7:04 AM
     
     

    Thank you very much for your response.

    I now have another issue i need to solve with the exploded pie.

    In my dashboard, I have the pie chart which the user can click on and make it explode, but I also have other charts (column, line charts etc.).

    I would like to change the color of the other charts according to the pie slice I clicked on.

    The problem is I am using 'BrightPastel' palette in my aspx code, and I can't seem to retrieve the color element of the selected slice from the codebehind (c#).

    Does anyone have a solution for this?

     

  • Tuesday, May 29, 2012 4:42 AM
     
     

    Hi

    You can try this 

    Dim result As HitTestResult = chart1.HitTest(e.X, e.Y)

    chart2.series(0).color = result.Series().Color


    Sandeep J. Sharma (eZee Technosys)

  • Tuesday, May 29, 2012 9:23 AM
     
     

    Thanks for your reply, but I tried converting to code to c# and I received the following error message:

    Error 5 'System.Web.UI.WebControls.ImageMapEventArgs' does not contain a definition for 'X' and no extension method 'X' accepting a first argument of type 'System.Web.UI.WebControls.ImageMapEventArgs' could be found (are you missing a using directive or an assembly reference?)


    This is my c# code:

    HitTestResult result = chart1Ctl.HitTest(e.X, e.Y);

    and of course, I am using the following namespace:

    using System.Web.UI.DataVisualization.Charting;
    After a quick google search I found this: http://msdn.microsoft.com/en-us/library/dd467422.aspx

    I am developing in asp.ne 3.5 framework, and as I understand from this article, HitTestResult is only supported in .net 4.0 framework.

    Is there maybe a different solution for me? Am I missing something?