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

StackedBar Chart binding data but not displaying data

4 Answers 80 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 29 Dec 2011, 10:04 PM
Hi everyone,

I'm having some issues with displaying a StackedBar chart. I can confirm that data is being bound (because the DataBound event is firing). However, the data is not being displayed (see attached). I'm simply getting a "No Data Series". I modeled this chart after another regular bar series chart that works fine.
 

using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Controls.Charting;
using RadHelpdeskDashboard.HelpdeskServiceReference;
using RadHelpdeskDashboard.Helpers;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Windows.Media;
 
namespace RadHelpdeskDashboard
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            TotalElapsedOpenTicketsChart.Loaded +=new RoutedEventHandler(TotalElapsedOpenTicketsChart_Loaded);
            Loaded +=new RoutedEventHandler(MainPage_Loaded);
        }
 
        public void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadTotalElapsedOpenTicketsChart();
        }
 
 
        protected void LoadTotalElapsedOpenTicketsChart()
        {
            TotalElapsedOpenTicketsChartBusy.IsBusy = true;
            HelpdeskDataServiceClient obj = new HelpdeskDataServiceClient();
            obj.GetTotalElapsedOpenTicketsCompleted += (sender, e) =>
                {
                    List<PeopleTotalOpenElapsedTicket> _people = new List<PeopleTotalOpenElapsedTicket>();
                    foreach (TotalElapsedOpenTickets_GetResult tickresult in e.Result)
                    {
                        PeopleTotalOpenElapsedTicket temp = new PeopleTotalOpenElapsedTicket(tickresult.Name,
                                                                                             (tickresult.Total.HasValue) ? tickresult.Total.Value : 0,
                                                                                             tickresult.LT10, tickresult._10to30, tickresult.GT30);
                        _people.Add(temp);
                    }
 
                    TotalElapsedOpenTicketsChart.ItemsSource = _people;
                    TotalElapsedOpenTicketsChartBusy.IsBusy = false;
                };
            obj.GetTotalElapsedOpenTicketsAsync();
        }
 
        public void TotalElapsedOpenTicketsChart_Loaded(object sender, RoutedEventArgs e)
        {
            StackedBar3DSeriesDefinition bar = new StackedBar3DSeriesDefinition("Name") { ShowItemLabels = true };
            bar.Appearance.Fill = new SolidColorBrush(Colors.Blue);
            SeriesMapping smLT10 = new SeriesMapping() { LegendLabel = "Less than 10 days", CollectionIndex = 0 };
            smLT10.ItemMappings.Add(new ItemMapping() { FieldName = "Name", DataPointMember = DataPointMember.XCategory });
            smLT10.ItemMappings.Add(new ItemMapping() { FieldName = "TicketsLessThanTenDays", DataPointMember = DataPointMember.YValue });
            smLT10.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("Name"));
            smLT10.SeriesDefinition = bar;
 
            StackedBar3DSeriesDefinition bar1 = new StackedBar3DSeriesDefinition("Name") { ShowItemLabels = true };
            bar1.Appearance.Fill = new SolidColorBrush(Colors.Red);
            SeriesMapping sm10to30 = new SeriesMapping() { LegendLabel = "10 to 30 days", CollectionIndex = 1 };
            sm10to30.ItemMappings.Add(new ItemMapping() { FieldName = "Name", DataPointMember = DataPointMember.XCategory });
            sm10to30.ItemMappings.Add(new ItemMapping() { FieldName = "TicketsTenToThirtyDays", DataPointMember = DataPointMember.YValue });
            sm10to30.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("Name"));
            sm10to30.SeriesDefinition = bar1;
 
            StackedBar3DSeriesDefinition bar2 = new StackedBar3DSeriesDefinition("Name") { ShowItemLabels = true };
            bar2.Appearance.Fill = new SolidColorBrush(Colors.Green);
            SeriesMapping smGT30 = new SeriesMapping() { LegendLabel = "Greater than 30 days", CollectionIndex = 2 };
            smGT30.ItemMappings.Add(new ItemMapping() { FieldName = "Name", DataPointMember = DataPointMember.XCategory });
            smGT30.ItemMappings.Add(new ItemMapping() { FieldName = "TicketsMoreThanThirtyDays", DataPointMember = DataPointMember.YValue });
            smGT30.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("Name"));
            smGT30.SeriesDefinition = bar2;
 
            TotalElapsedOpenTicketsChart.SeriesMappings.Add(smLT10);
            TotalElapsedOpenTicketsChart.SeriesMappings.Add(sm10to30);
            TotalElapsedOpenTicketsChart.SeriesMappings.Add(smGT30);
 
            TotalElapsedOpenTicketsChart.DefaultView.ChartArea.AxisX.Title = "Employee";
            TotalElapsedOpenTicketsChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45.0;
            TotalElapsedOpenTicketsChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside;
            TotalElapsedOpenTicketsChart.DefaultView.ChartArea.AxisY.AutoRange = true;
            TotalElapsedOpenTicketsChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "0";
            TotalElapsedOpenTicketsChart.DefaultView.ChartArea.AxisY.Title = "Tickets";
            TotalElapsedOpenTicketsChart.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
            TotalElapsedOpenTicketsChart.DefaultView.ChartTitle.Content = "Total Elapsed Open Tickets";
            TotalElapsedOpenTicketsChart.DefaultView.ChartTitle.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
        }
    }
}


Any ideas? Thanks!

-Sam

4 Answers, 1 is accepted

Sort by
0
Accepted
Rahul
Top achievements
Rank 2
answered on 30 Dec 2011, 04:00 PM
Hi Sam,
I analyzed one problem in your code.
If i remove CollectionIndex from SeriesMapping then your chart is working fine.
If i add CollectionIndex then its not working.

I pasting your modified code. Hope it will help you.

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            radChart1.Loaded += new RoutedEventHandler(radChart1_Loaded);
            Loaded += new RoutedEventHandler(MainPage_Loaded);
             
        }
 
        void radChart1_Loaded(object sender, RoutedEventArgs e)
        {
            StackedBar3DSeriesDefinition bar = new StackedBar3DSeriesDefinition("Name") { ShowItemLabels = true };
            bar.Appearance.Fill = new SolidColorBrush(Colors.Blue);
            SeriesMapping smLT10 = new SeriesMapping() { LegendLabel = "Less than 10 days" };
            smLT10.ItemMappings.Add(new ItemMapping() { FieldName = "FirstName", DataPointMember = DataPointMember.XCategory });
            smLT10.ItemMappings.Add(new ItemMapping() { FieldName = "LastName", DataPointMember = DataPointMember.YValue });
            smLT10.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("FirstName"));
            smLT10.SeriesDefinition = bar;
  
            StackedBar3DSeriesDefinition bar1 = new StackedBar3DSeriesDefinition("Name") { ShowItemLabels = true };
            bar1.Appearance.Fill = new SolidColorBrush(Colors.Red);
            SeriesMapping sm10to30 = new SeriesMapping() { LegendLabel = "10 to 30 days"};
            sm10to30.ItemMappings.Add(new ItemMapping() { FieldName = "FirstName", DataPointMember = DataPointMember.XCategory });
            sm10to30.ItemMappings.Add(new ItemMapping() { FieldName = "LastName", DataPointMember = DataPointMember.YValue });
            sm10to30.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("FirstName"));
            sm10to30.SeriesDefinition = bar1;
  
            StackedBar3DSeriesDefinition bar2 = new StackedBar3DSeriesDefinition("Name") { ShowItemLabels = true };
            bar2.Appearance.Fill = new SolidColorBrush(Colors.Green);
            SeriesMapping smGT30 = new SeriesMapping() { LegendLabel = "Greater than 30 days" };
            smGT30.ItemMappings.Add(new ItemMapping() { FieldName = "FirstName", DataPointMember = DataPointMember.XCategory });
            smGT30.ItemMappings.Add(new ItemMapping() { FieldName = "LastName", DataPointMember = DataPointMember.YValue });
            smGT30.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("FirstName"));
            smGT30.SeriesDefinition = bar2;
  
            radChart1.SeriesMappings.Add(smLT10);
            radChart1.SeriesMappings.Add(sm10to30);
            radChart1.SeriesMappings.Add(smGT30);
  
            radChart1.DefaultView.ChartArea.AxisX.Title = "Employee";
            radChart1.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45.0;
            radChart1.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside;
            radChart1.DefaultView.ChartArea.AxisY.AutoRange = true;
            radChart1.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "0";
            radChart1.DefaultView.ChartArea.AxisY.Title = "Tickets";
            radChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
            radChart1.DefaultView.ChartTitle.Content = "Total Elapsed Open Tickets";
            radChart1.DefaultView.ChartTitle.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
         
        }
 
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadChartData();
        }
 
        private void LoadChartData()
        {
            List<PersonName> lst = new List<PersonName>();
            lst.Add(new PersonName { FirstName = "Rahul", LastName = 3 });
            lst.Add(new PersonName { FirstName = "Rahul", LastName = 3 });
            lst.Add(new PersonName { FirstName = "Rahul", LastName = 3 });
            lst.Add(new PersonName { FirstName = "Rahul", LastName = 3 });
            lst.Add(new PersonName { FirstName = "Rahul", LastName = 3 });
 
            radChart1.ItemsSource = lst;
        }
    }
    public class PersonName
    {
        private string firstName;
        private int lastName;
 
      
 
        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }
 
        public int LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }
    }
}

Regards
Rahul
0
Sam
Top achievements
Rank 1
answered on 03 Jan 2012, 04:26 PM
Hi Rahul,

Thanks very much, that seemed to work! I'm guessing that is a bug in the control because I believe that CollectionIndex should work.

Interestingly now in the legend, there are way too many entries (see attached). The reason I used CollectionIndex was to order the 3 "groupings".


Sam
0
Evgenia
Telerik team
answered on 06 Jan 2012, 02:18 PM
Hi Sam,

The source code provided by Rahul seems correct to me. Have you by any reason set the LegendDisplayMode property of the Chart to DataPointLabel. This will cause the Chart to display an item for each DataPoint in your series. If this is not the case I suggest that you take a look at the attached sample that demonstrates how to create a Grouped StackedBars.

As for the CollectionIndex property - this property allows the chart to be data bound to a collection/array nested inside another collection/array. The index used is the index of the internal collection inside the ItemsSource. Since you don't have nested collections in your scenario - this won't help you in your scenario.

All the best,
Evgenia
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Sam
Top achievements
Rank 1
answered on 06 Jan 2012, 09:35 PM
Hi Evgenia,

Interestingly once I got rid of SeriesMapping.GroupSettings.Add(new ChartGroupDescriptor("Name"));

it worked
Tags
Chart
Asked by
Sam
Top achievements
Rank 1
Answers by
Rahul
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or