locked
Exploded=true property of pie chart RRS feed

  • Question

  • Hi,
    Currently I am
    using MS pieChart for creating a graph making use of my sql database values
    I am able to show a proper pie chart
    But I am unable to make use of Exploded=
    true property

    --------------------------------------
    For example
    code:
    Chart1.Series[
    "Series1"].PostBackValue = "#INDEX";
    ..............
    protected void Chart1_Click(object
    sender, ImageMapEventArgs e)
    {
    int pointIndex = int
    .Parse(e.PostBackValue);
    .........
    ..........
    }
    .............

    here pointindex shows the currently clicked slice(portion of pie chart)

    both Series1[
    "CollectedSliceExploded"]= "true"; and
    Chart1.Series[
    "Series1"].Points[pointIndex].CustomProperties += "Exploded=true"; are not giving the expected
    Because, through code I am unable to identify total number of slices.(I think,this is the problem)
    --------------------------------------
    aspx page:

    <
    asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" onclick="Chart1_Click">
    <Series>
    <asp:Series ChartType="Pie" Name="Series1" XValueMember="Day" YValueMembers="EmpNo">
    .......

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EmployeeConnectionString1 %>"
    SelectCommand="SELECT [Day], [EmpNo] FROM [EmployeeWorkChart]">
    </asp:SqlDataSource>


    --------------------------------------
    I tried the same with hard coded values instead of taking it from database...Then it works
    (ie hard coding the values to yValues&xValues)

    double[] yValues = {.... }
    string
    [] xValues = {.......}

    Chart1.Series[
    "Series1"].PostBackValue = "#INDEX"
    ;
    series.Points.DataBindY(yValues);
    .............................
    protected void Chart1_Click(object
    sender, ImageMapEventArgs e)
        {    
            
    int pointIndex = int
    .Parse(e.PostBackValue);
            Series series = Chart1.Series[
    "My series"
    ];
                if
    (pointIndex >= 0 && pointIndex <= series.Points.Count)
                    {
                      series.Points[pointIndex].CustomProperties +=
    "Exploded=true"
    ;
                      }
        } 
    --------------------------------------

    How can I do the same without hardcoding the values

    Expecting reply
    Thanks in Advance
                   Basanth
       

    Friday, December 12, 2008 12:51 PM

Answers

  • First of all I recommend you to use this syntax when setting Custom Properties:

    Chart.Series["MySeries"]["Exploded"] = "true"

    It makes sure that you do not have duplicate custom properties set. We will make adjustments to the Pie chart sample that suggests just adding string to the CustomProperties.

    You are using data binding and my guess is that all your data points are re-created later after you changed the exploded slice. Try calling Chart.DataBind() method before setting the Exploded slice. This method will force the binding and population of the new data into the series at the moment of the call.

    Alex.
    Friday, December 12, 2008 6:28 PM