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

How can I create Stacked Bar Chart from the Code behind?

2 Answers 133 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Abhishek
Top achievements
Rank 1
Abhishek asked on 23 Aug 2011, 03:12 PM
Hi,
I'm facing problem while generating a stacked chart form the code behind, its showing only the last entered 'Y Value' in the chart. I think i'm facing problem to group all the values properly. Please help me out.
public StackedBar()
        {
            InitializeComponent();
  
            SeriesMapping series = new SeriesMapping();
            series.SeriesDefinition = new StackedBarSeriesDefinition();
            series.GroupingSettings.StackGroupFieldName = "Branch1";
            series.ItemMappings.Add(new ItemMapping("MonthName", DataPointMember.XCategory));
            series.ItemMappings.Add(new ItemMapping("Meter1", DataPointMember.YValue));
            series.ItemMappings.Add(new ItemMapping("Meter2", DataPointMember.YValue));
            series.ItemMappings.Add(new ItemMapping("Meter3", DataPointMember.YValue));
            series.ItemMappings.Add(new ItemMapping("Meter4", DataPointMember.YValue));
              
            StackBarChart.ItemsSource = GetReVenue();
            StackBarChart.DataBound += new EventHandler<ChartDataBoundEventArgs>(StackBarChart_DataBound);
            StackBarChart.SeriesMappings.Add(series);
              
        }
In the above code the chart is generating for only "Meter4", but not for other Y Values!

2 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 25 Aug 2011, 11:10 AM
Hello Abhishek,

You need to create 4 SeriesMappings with StackedBarSeriesDefinition where each series mapping has 2 item mappings for XCategory and YValue, instead of your current configuration with single series mapping where you are effectively overwriting the YValue item mapping four times.

Hope this helps.


All the best,
Giuseppe
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Abhishek
Top achievements
Rank 1
answered on 27 Aug 2011, 11:28 AM

Hi Giuseppe,

Thanks for the answer, I did the same and it works for me.
Tags
Chart
Asked by
Abhishek
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Abhishek
Top achievements
Rank 1
Share this question
or