Log in to like this post! Introducing the XamFunnelChart Damyan Petev / Tuesday, November 8, 2011 The XamFunnelChart™ is a new control in 11.2 and as with other newly introduced controls following our Unified XAML strategy – they are Cross-platform and this one is no exception. It will be available in NetAdvantage® for Silverlight and WPF both Line Of Business and Data Visualization packages as well as NetAdvantage for Windows Phone. The XamFunnelChart can display a single series of data as progressively decreasing proportions in the form of a funnel. The funnel can have any number of sections ( or also referred as slices ) each of which representing a percentage of the whole. A classical example of a funnel chart is orders fulfilment starting with the total of initiated orders on top or even the awareness of the customers or how many have clicked an advertisement and finishing with the actual deliveries to satisfied customers. What the goal of such chart would be is to make easy spotting a major ‘fallout’ at some stage of a process that starts at 100% and ends at lower or illustrate where the biggest bottlenecks are in that process. Here’s a visual example showing the expenses for each phase: Displaying in the default top-down style, using outside labels and with bottom edge set at half the size of the top one. The chart is inverted, the outside labels have been replaced with a legend and the bottom edge (now on top) has been reduced in size to make the chart a bit more narrow. Now that you have an idea what the XamFunnelChart can do let’s see how to use it. Getting Started As always it starts with adding the required references which include the base assembly for the platform (e.g InfragisticsSL4.DataVisualization.v11.2.dll or just InfragisticsSL4.v11.2.dll in NetAdvantage for Silverlight) and the one for the chart (e.g. InfragisticsWP7.Controls.Charts.XamDataChart.v11.2.dll ) and of cource the infragistics namespace: xmlns:ig="http://schemas.infragistics.com/xaml" Once that is done you might consider the data to be visualized. The chart is easy enough to use with data models of you choosing but it does have requirements that need to be met otherwise an error will be generated: First and foremost the very minimum is that the data model must contain one numeric column – these are the values for each slice. The data model may contain an optional string column for legend and labels. The funnel chart doesn’t use axes so there are not in the list of requirements. And if there are more than one series just the first one will be rendered. There’s also no need to include percentages in the model as the XamFunnelChart will take the sum of all values and calculate the each row’s part for you. The strings for inner or outer labels are also shared as legend labels. Here’s an example data using a simple value-label pairs: public class ExampleItem { public string Label { get; set; } public double Value { get; set; } } public class TestData : ObservableCollection<ExampleItem> { public TestData() { ExampleItem slice1 = new ExampleItem(); slice1.Label = "Marketing"; slice1.Value = 45000; Add(slice1); ExampleItem slice2 = new ExampleItem(); slice2.Label = "Retail"; slice2.Value = 22000; Add(slice2); ExampleItem slice3 = new ExampleItem(); slice3.Label = "Manufacturing"; slice3.Value = 76000; Add(slice3); ExampleItem slice4 = new ExampleItem(); slice4.Label = "Shipping"; slice4.Value = 33500; Add(slice4); ExampleItem slice5 = new ExampleItem(); slice5.Label = "Research & Design"; slice5.Value = 88000; Add(slice5); } } And adding that to the resources in XAML: <UserControl ... xmlns:local="clr-namespace:FunnelChartDemo" ...> <UserControl.Resources> <local:TestData x:Key="data"></local:TestData> </ResourceDictionary> </UserControl.Resources> ... Adding the control next and it includes a few required properties to set: The ItemSource , which will be bound to an instance of the data collection in this example ValueMemberPath property holds the path to the data series with numeric values The other basic properties include OuterLabelMemberPath and InnerLabelMemberPath which obviously hold the path to the labels in the collection and the Boolean UseOuterLabelsForLegend that based on it’s value will alternate between outer and inner labels for the legend. FunnelSliceDisplay in an option if the chart should use ‘Uniform’ style to display slices which is basically each slice row having the same height as the others, or using ‘Weighted’ style to calculate each row’s height based on its part in the total: <ig:XamFunnelChart ItemsSource="{StaticResource data}" x:Name="funnelChart" ValueMemberPath="Value" InnerLabelMemberPath="Value" FunnelSliceDisplay="Weighted" OuterLabelMemberPath="Label" OuterLabelVisibility="Visible" Legend="{Binding ElementName=Legend}"/> <!--Adding the legend --> <ig:ItemLegend x:Name="Legend" /> And the result of that would be something like this: As it can be seen the chart can use both outside labels and legend also after a quick comparison with the ones above – this one is using the default styles and they are styled with our IG Theme. Of course you can define your own set of colours using the Brushes property. Interaction The XamFunnelChart can really come to life with it’s dependency properties – they will allow for truly engaging user interaction with the chart in runtime. To start with it allows selection with setting the AllowSliceSelection to true. The control also fires a SliceClicked event and argument that provides an easy way to get information about the clicked slice. Let’s assume you would like to let the user pick slices to see their combined values, this can be done like so: private void funnelChart_SliceClicked(object sender, Infragistics.Controls.Charts.FunnelSliceClickedEventArgs args) { //the sender object is the chart XamFunnelChart chart = (XamFunnelChart)sender; //and args supplies the Index and the Item itself ExampleItem clickedSlice = (ExampleItem)args.Item; /*if the clicked slice is in the selected collection it means it has just been added and vise versa.*/ if (chart.SelectedItems.Contains(clickedSlice)) { // using a TextBox named showValue to hold the sum if (showValue.Text == string.Empty) { showValue.Text = clickedSlice.Value.ToString(); } else { showValue.Text = (int.Parse(showValue.Text) + clickedSlice.Value).ToString(); } } else { showValue.Text = (int.Parse(showValue.Text) - clickedSlice.Value).ToString(); } } The IsInverted property can be bound and changed in runtime to produce a rather dramatic animation. Speaking of animations the chart also has and entry animation and an TransitionDuration property that can be set to seconds or parts of a second, just keep in mind it’s a TimeSpan so use the format “00:00:01.00” if you don’t want to end up with one hour transition animation and keep in mind it also affects the entry – probably for normal use 3 seconds is the maximum. Curves Besides smooth animations the XamFunnelChart can also do smooth curves – for that it uses Bezier curves. A Bezier curve is a parametric curve that can scale indefinitely and is used to create very fluid and graceful curves. You can enable that feature on the chart and you can also provide two points as parameters for the curve referred as upper and lower: <ig:XamFunnelChart ItemsSource="{StaticResource data}" UseBezierCurve="True" UpperBezierControlPoint="0.1, 0.25" LowerBezierControlPoint="0.55, 0.5" ValueMemberPath="Value"/> Using that you can create stunningly looking charts simply let users set the points and observe the chart animate the transition between different settings. Here’s an example of what the chart can look like using Bezier curves: Conclusion The XamFunnelChart will display data in style, sort it and calculate percentages to scale each piece. You can manipulate its shape – start with a funnel , flip it, make it a pyramid or apply smooth curves to its sides and make it truly unique. Allow users to interact with the funnel chart and make changes to various setting in runtime while enjoying fluid animations and still being able effortlessly make conclusions based on the presented data. A demo project demonstrating some of the main features can be found here. Keep in mind assemblies from the 11.2 Release (can be trial) are required.