StackedBar chart, with mutliple dataseries

8 posts, 1 answers
  1. Kristjan Einarsson
    Kristjan Einarsson avatar
    95 posts
    Member since:
    Jan 2010

    Posted 21 Jun 2011 Link to this post

    Hi, I'm not sure if this is possible but here is my scenario:

    I'm using the StackedBar series and they work fine, but sometimes I will need to compare similar data and would need two series per datapoint on the X axis for this, and I have to do this in codebehind. In other words like a normal chart with multiple dataseries but with stacked bar chart.

    Are there any examples for this ?

    Best regards
    Kristján.

  2. Nikolay
    Admin
    Nikolay avatar
    386 posts

    Posted 23 Jun 2011 Link to this post

    Hello Kristjan Einarsson,

    Would a chart similar to our demo 2D Stacked Bar be suitable for your scenario? It makes use of 2 stack groups, so that each X axis point has 2 stacks of bars, which could easily be compared. in code behind you can set 2 or more stack groups by setting the series definition in the following manner :
    stackedBarSeries1.Definition = new StackedBarSeriesDefinition("stack 1");

    Each Stacked Bar series that is assigned to "stack 1" would form the first stack, and each that is assigned to "stack 2" would form the second stack, as in the demo example.

    Hope this helps.

    Regards,
    Nikolay
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kristjan Einarsson
    Kristjan Einarsson avatar
    95 posts
    Member since:
    Jan 2010

    Posted 29 Jun 2011 Link to this post

    Hi, for some reason I'm not getting this to work. All the data is shown but the stacks do not "stack" together it makes a continuous chart
    here is my code:

    for (int i = 0; i < model.Count; i++)
    {
        SeriesMapping seriesMapping = new SeriesMapping();
        StackedBarSeriesDefinition definition = new StackedBarSeriesDefinition("Stack1");
        SeriesMapping compareSeriesMapping = new SeriesMapping();
     
        //When hover over series it will blur everything and only show the correct series and Legend item.
        definition.InteractivitySettings.HoverScope = InteractivityScope.Series;
        definition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
     
        definition.ShowItemToolTips = true;
        definition.ShowItemLabels = false;
        seriesMapping.SeriesDefinition = definition;
        seriesMapping.CollectionIndex = i;
     
        ItemMapping im1 = new ItemMapping();
        im1.DataPointMember = DataPointMember.YValue;
        seriesMapping.ItemMappings.Add(im1);
        chart.SeriesMappings.Add(seriesMapping);
    }
     
    int collectionCounter = model.Count - 1;
    for (int i = 0; i < model.Captions.Count; i++)
    {
        SeriesMapping seriesMapping = new SeriesMapping();
        StackedBarSeriesDefinition definition = new StackedBarSeriesDefinition("Stack2");
        SeriesMapping compareSeriesMapping = new SeriesMapping();
     
        //When hover over series it will blur everything and only show the correct series and Legend item.
        definition.InteractivitySettings.HoverScope = InteractivityScope.Series;
        definition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
     
        definition.ShowItemToolTips = true;
        definition.ShowItemLabels = false;
        seriesMapping.SeriesDefinition = definition;
        seriesMapping.CollectionIndex = collectionCounter;
        ItemMapping im1 = new ItemMapping();
        im1.DataPointMember = DataPointMember.YValue;
        seriesMapping.ItemMappings.Add(im1);
        chart.SeriesMappings.Add(seriesMapping);
        collectionCounter++;
    }

    the itemssource is List<double[]>
    can you spot what I'm doing wrong or do you have an dynamic stack example  ?

    Best regards
    Kristján
  5. Answer
    Nikolay
    Admin
    Nikolay avatar
    386 posts

    Posted 01 Jul 2011 Link to this post

    Hi Kristjan Einarsson,

    Please, find attached a sample StackedBar application in code behind, which seems to fit your scenario. Perhaps reviewing it would help you.

    Regards,
    Nikolay
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  6. Kristjan Einarsson
    Kristjan Einarsson avatar
    95 posts
    Member since:
    Jan 2010

    Posted 06 Jul 2011 Link to this post

    Hi, I took a look to your example, although it did not entirely fit my requirements it gave me an idea on how to accomplish this.
    I changed the mappings as follows:
    for (int i = 0; i < 3; i++)
    {
        SeriesMapping seriesMapping = new SeriesMapping();
        seriesMapping.SeriesDefinition = new StackedBarSeriesDefinition("stack 1");
        seriesMapping.SeriesDefinition.ShowItemToolTips = true;
        seriesMapping.SeriesDefinition.ShowItemLabels = false;
        seriesMapping.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
        seriesMapping.SeriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
        //seriesMapping.ItemMappings.Add(new ItemMapping("XValue", DataPointMember.XValue));
        seriesMapping.ItemMappings.Add(new ItemMapping("[" + i + "].Value1", DataPointMember.YValue));
        chart.SeriesMappings.Add(seriesMapping);
    }
      
    and the population:
    public static List<List<DataObject>> GetData()
    {
        List<List<DataObject>> list = new List<List<DataObject>>();
     
        for (int i = 0; i < 12; i++)
        {
            List<DataObject> listToAdd = new List<DataObject>();
            DataObject num1 = new DataObject(0, rand.Next(10, 100), 10);
            DataObject num2 = new DataObject(0, rand.Next(10, 100), 10);
            DataObject num3 = new DataObject(0, rand.Next(10, 100), 10);
     
            listToAdd.Add(num1);
            listToAdd.Add(num2);
            listToAdd.Add(num3);
            list.Add(listToAdd);
        }
        return list;
    }

    Best regards
    Kristján
  7. Manu
    Manu avatar
    24 posts
    Member since:
    Aug 2015

    Posted 03 Sep 2015 in reply to Nikolay Link to this post

    hi Nikolay,

    Greetings!

    i am having some problem. plz see the below attachments u will cm to know my problem.

    i am getting the values for chart from dataset.. 

    if x-axis values are same i should get stacked bar..

    plz help me out from this prob.

     

     

  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 07 Sep 2015 Link to this post

    Hello Manu,

    This thread is about the old RadChart. This is the old charting control in our suite and due to its limitations, we suggest that you do not use it for new development. You can not use the much faster RadCharView. The RadChartView is actually a set of controls - RadCartesianChart, RadPieChart, RadPolarChart, ChartDataSource. It is generally pretty fast, easy to set up, and very flexible.  Here are some links:
    qsf examples
    sdk samples
    online documentation

    In the online documentation and qsf examples you will see how to use a BarSeries with CategoryBinding, ValueBinding and CombineMode Stack so that you get a stacked chart.

    Regards,
    Petar Marchev
    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
  9. Manu
    Manu avatar
    24 posts
    Member since:
    Aug 2015

    Posted 07 Sep 2015 in reply to Petar Marchev Link to this post

    thanks for the reply petar..

    i am building my charts using radhtmlchart..

    i solved my problem thanks :)

Back to Top
UI for WPF is Visual Studio 2017 Ready