This is a migrated thread and some comments may be shown as answers.

Pie Chart Item Exploded from code

7 Answers 189 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chris Thierry
Top achievements
Rank 1
Chris Thierry asked on 08 Jul 2011, 05:28 PM

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.

7 Answers, 1 is accepted

Sort by
0
Chris Thierry
Top achievements
Rank 1
answered on 12 Jul 2011, 02:55 PM
Please, I need a solution for this.
Thank you.
0
Yavor
Telerik team
answered on 13 Jul 2011, 12:22 PM
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!

0
Chris Thierry
Top achievements
Rank 1
answered on 13 Jul 2011, 01:44 PM

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.

0
Chris Thierry
Top achievements
Rank 1
answered on 15 Jul 2011, 05:10 PM
Please I need to do something with this issue.
Do you have any solution?
Thank you.
0
Yavor
Telerik team
answered on 18 Jul 2011, 08:21 AM
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!

0
Chris Thierry
Top achievements
Rank 1
answered on 18 Jul 2011, 01:52 PM
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.
0
Yavor
Telerik team
answered on 19 Jul 2011, 08:52 AM
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!

Tags
Chart
Asked by
Chris Thierry
Top achievements
Rank 1
Answers by
Chris Thierry
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or