Pie Chart Item Exploded from code

8 posts, 0 answers
  1. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 08 Jul 2011 Link to this post


    HI, I have a problem trying to set an item of my pie chart, I have two pie chart that are related, if I click in one item, the other chart is refreshed automatically, but if one item was selected previously... I need to keep this selection, so I checked this sample : http://demos.telerik.com/silverlight/#Chart/Selection to see how is doing...

    this is my scenario, I have two charts, one chart has fruits and the other chart has colors, when I load the page, there are no selected items, after that I select one fruit (apple), so apple item is exploded, now I want to select a color (red) from the other chart, because my fisrt chart has one selected item, I need to keep this selection, this is my code:

    DataSeries series = this.RadChartCategoryService.DefaultView.ChartArea.DataSeries[0];
      
                    foreach (DataPoint point in series)
                    {
                        if (((DashboardChart)point.DataItem).ID == index)
                        {
                            this.RadChartCategoryService.DefaultView.ChartArea.SelectItem(point);
                            break;
                        }
                    }

    As soon as I call SelectItem, the SelectionChanged item is fired, in this case the dataPoint is always null and the problem is that my previous item was not keeped exploded. I saw in your example that is using a variable propagateSelection, is there anything else that I should do? only with SelectItem should explodes the item? why dataPoint is null in this case?

    DataPoint dataPoint = null;
    if (e.AddedItems.Count > 0)
        dataPoint = e.AddedItems[0];
    else if (e.RemovedItems.Count > 0)
        dataPoint = e.RemovedItems[0];
      
    if (dataPoint != null)
    {
        TMEGlobals.TypeOfServices currentChart =
                       ((TMEGlobals.TypeOfServices)this.CategoryTypeUC.RadChartCategoryService.Tag);
      
        Nullable<int> selectedID = ((DashboardChart)dataPoint.DataItem).ID;
      
        if (this.CategoryTypeUC.SelectedItemChart == selectedID)
        {
            this.CategoryTypeUC.SelectedItemChart = null;
      
            if (currentChart == TMEGlobals.TypeOfServices.ShowServiceType)
            {
                dashboardFilter.ServiceTypeID = null;
            }
            else
            {
                dashboardFilter.ServiceCategoryID = null;
            }
      
            this.ProviderUC.Load(dashboardFilter);
            this.MonthlyCostUC.Load(dashboardFilter, this.OrganizationUnitUC.RadGridViewOrgUnit);
      
            if (currentChart == TMEGlobals.TypeOfServices.ShowServiceCategory)
            {
                this.CategoryTypeUC.ImageSwitchService.Visibility = Visibility.Collapsed;
            }
        }
        else
        {
            this.CategoryTypeUC.SelectedItemChart = selectedID;
      
            if (currentChart == TMEGlobals.TypeOfServices.ShowServiceType)
            {
                dashboardFilter.ServiceTypeID = selectedID;
            }
            else
            {
                dashboardFilter.ServiceCategoryID = selectedID;
            }
      
            this.ProviderUC.Load(dashboardFilter);
            this.MonthlyCostUC.Load(dashboardFilter, this.OrganizationUnitUC.RadGridViewOrgUnit);
      
            if (this.CategoryTypeUC.ShowAlwaysServiceTypes == false)
            {
                this.CategoryTypeUC.ImageSwitchService.Visibility = System.Windows.Visibility.Visible;
      
                if (currentChart == TMEGlobals.TypeOfServices.ShowServiceCategory)
                {
                    this.CategoryTypeUC.ToolTipSwitchService.Content =
                        TMEGlobals.GetLanguageString("show_service_type");
                }
      
                if (currentChart == TMEGlobals.TypeOfServices.ShowServiceType)
                {
                    this.CategoryTypeUC.ToolTipSwitchService.Content =
                        TMEGlobals.GetLanguageString("show_service_category");
                }
            }
        }
    }

    is there any other example that I can see? I tried with a button and when I call SelectItem it works! the DataPoint is not null but I want it to be automatic... Any idea?
    Thank you.
  2. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 12 Jul 2011 Link to this post

    Please, I need a solution for this.
    Thank you.
  3. DevCraft banner
  4. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 13 Jul 2011 Link to this post

    Hello Chris,

    The selection will work if you use a datapoint, or a simple index. The index approach was used in the example you referenced previously. In which event are you calling the code to select the item(s)? If it is too early in the page cycle, you can try a different event, for example when the chart is databound. Give this approach a try and let me know whether it works, or if I am leaving something of the original logic out.

    Regards,
    Yavor
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  5. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 13 Jul 2011 Link to this post

    I'm calling the select items after loading my chart, so SelectionChanged is called and the dataPoint is null, the same situation works but using a button when the page was completly loaded.

    I was waiting for this functionality since last year, there is something that is not filled at that moment, if you don't understand my previous message, please let me know, I'll try to do it something simpler.

    Thank you.

  6. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 15 Jul 2011 Link to this post

    Please I need to do something with this issue.
    Do you have any solution?
    Thank you.
  7. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 18 Jul 2011 Link to this post

    Hi Chris,

    Attached to this message, is a small application, which preselects a number of pie elements, when the chart is first loaded. Take a look at it and let me know whether this is the expected behavior, or if I am leaving something out.

    Greetings,
    Yavor
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  8. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 18 Jul 2011 Link to this post

    HI,

    I posted this issue on Friday 8th, I need to finish my work, this project doesn't work,
    The elements are preselected but I can't put the item back to chart, I need to keep the same functionality with the items exploded.

    I tried to use LayoutUpdated method but... because I'm using  SelectionChanged as well is giving me an error "Layout cycle detected" between these two methods when I'm doing click in one pie chart item.

    This doesn't work for me. I need to know if this is possible or not.

    Thank you.
  9. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 19 Jul 2011 Link to this post

    Hello Chris,

    Please, keep in mind, that the forum threads are mainly aimed at providing the community with means to exchange ideas, seeks assistance and so on. While we do monitor all threads, the response time is bigger. Because of this, if you are seeking a faster response, the best option is to open a support ticket.
    Regarding the issue at hand. The sample sent earlier demonstrates the available selection api in the control. If you have a different scenario/setup, you can use the sample to replicate the problem. You can attach it to a support ticket, which will be reviewed promptly, and a workaround meeting your specific needs, provided.

    All the best,
    Yavor
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
DevCraft banner