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

RadCartesianBarChart show series when click on legend

11 Answers 269 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Arun
Top achievements
Rank 1
Arun asked on 03 Dec 2015, 08:26 PM

Hi,

I am using radcartesianbarchart to show multiple bar series. For example if i have category1, category2, and total these are the series collection.

If i click on legent of category1, need to show the category1 series. same for category2. If i click on total it should show all series. How we can achieve this.

Using hover property we can show fadeout of other series. But i need to draw when click on the legend only. Also please advise how to do animation for the chart series.

Thanks,

Arun

11 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 04 Dec 2015, 04:39 PM
Hello Arun,

You can take a look at the Live Data demo. Note that the example is in Silverlight but it share its code with the WPF version.

Is this going to suit your needs?

Regards,
Ivan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 05 Jan 2016, 08:22 AM

Hi,

 Can you specify the example project name, so that i can identify it.

0
Ivan
Telerik team
answered on 06 Jan 2016, 09:13 AM
Hi Arun,

Excuse me for the mistake, the name of the demo is Large Data. You can find it in the Performance section of the ChartView control demos inside the UI for WPF examples. This location applies for both demo applications - WPF and SL.

If you have further questions about this let us know.

Regards,
Ivan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 18 Jan 2016, 12:49 PM

Hi,

 The mentioned example is not relevant to me. 

 The requirement is have to show the chart dataitems when we click on corresponding legend. Please find the attached screenshot and below details.

In the attached screenshot we can able to see 4 items(Q1, Q2, Q3, and Q4) with the series of values. Now the chart showing all 4 items in chart area. Our requirement is we need to show Q1 data items when i click on Q1 legend. Corresponding for all other legend items also.

 

How we can implement this, I hope we can write a template for legend to click and how to get the corresponding chart items and how to disable/collapse other items. 

 Please attach a example.

 

0
Accepted
Ivan
Telerik team
answered on 19 Jan 2016, 12:51 PM
Hello Arun,

We are not sure that we completely understand your case. However, we prepared a sample project for you. Can you take a look at it and let us know if this is what you are looking for?

The series are initially hidden. When you click on some of the legend items, the series bound to the legend item is being shown.

Let me know if this works for you.

Regards,
Ivan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 19 Jan 2016, 01:57 PM

Yes. This is the expected one. Thanks lot. 

 

Also i need to hide the other legend items and show the corresponding legend item alone when we click.

0
Arun
Top achievements
Rank 1
answered on 19 Jan 2016, 03:19 PM
Like highlight the current legend and disable the other legends
0
Ivan
Telerik team
answered on 21 Jan 2016, 12:14 PM
Hello Arun,

Can you please clarify further what do you mean by setting the other legend items hidden or disabled? This way the user will be able to select a legend item and it's corresponding series only one time.

Is this the behavior that you are looking for?

If this is the case, in the project we've sent you, you can pass the legend control itself as a command parameter. Then, inside the static command handler you can extract  all the buttons from the legend template and set their Visibility property to Collapsed. Finally, you can set the Visibility property to Visible only on the button that has been clicked .

Regards,
Ivan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 27 Jan 2016, 10:50 AM

"you can pass the legend control itself as a command parameter. Then, inside the static command handler you can extract  all the buttons from the legend template and set their Visibility property to Collapsed. Finally, you can set the Visibility property to Visible only on the button that has been clicked ."

 

Can you please provide the code snippet for this. 

0
Accepted
Ivan
Telerik team
answered on 01 Feb 2016, 10:00 AM
Hi Arun,

In xaml you can pass the legend as a CommandParameter in the following way:
<telerik:RadLegend x:Name="legend">
<
telerik:RadLegend.ItemTemplate>
  <DataTemplate>
      <telerik:RadButton Content="{Binding Title}"
            Command="{x:Static local:MyCommands.HideShowCommand}"
            CommandParameter="{Binding ElementName=legend}"
            Background="{Binding MarkerFill}"
            Tag="LegendItemButton"/>
    </DataTemplate>
</telerik:RadLegend.ItemTemplate>
</telerik:RadLegend>

In the CommandExecuteHandler handler in the code behind you can introduce these changes:
private static void CommandExecuteHandler(object sender, ExecutedRoutedEventArgs e)
{
var legend = e.Parameter as RadLegend;
 var buttons = legend.ChildrenOfType<RadButton>().Where(x => x.Tag.ToString() == "LegendItemButton");
 
 RadButton button = (RadButton)sender;
 LegendItem item = button.DataContext as LegendItem;
 BarSeries series = item.Presenter as BarSeries;
 RadCartesianChart chart = series.Chart as RadCartesianChart;
 var items = chart.LegendItems;
 
 foreach (BarSeries s in chart.Series)
 {
   s.Visibility = Visibility.Collapsed;
 }
 foreach (var btn in buttons)
 {
  btn.Opacity= 0.5;
 }
 
 series.Visibility = Visibility.Visible;
 button.Opacity = 1;
}
This way when the user clicks on a legend button, the relevant series item will be highlighted and all the other legend buttons will fade.

Regards,
Ivan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 01 Feb 2016, 12:45 PM
Thanks lot
Tags
Chart
Asked by
Arun
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Arun
Top achievements
Rank 1
Share this question
or