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

Best way to load data in Stacked Bar Chart

1 Answer 84 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Donald Hamm
Top achievements
Rank 1
Donald Hamm asked on 17 Jul 2009, 01:55 PM
I have a List collection of data with a cateory name  and a int array (4 elements) for the stacked bar.  What is the best way to load the stacked bar so the category name shows in the x axis and the chart can use the int array?  The examples do not show how the 'label' can be defined.  All current examples use 'doubles' array of doubles...

E.G.,  class with values to load...

public class StackedBarData
{
    _private int[] = _barDataPoints = null;
   public int[] BarDataPoints  
   {
        // loaded from database call outside of class...
        get { return this._barDataPoints ;}
        set { this._barDataPoints = value;}
   }

   _private string _categoryName = "";
   public string CategoryName
   {
        get {return this._categoryName;}
        set {this._categoryName = value;}
    }
}

the int array has 4 elements.

here is how I setup the  the series:

 

int seriesIndex = 0;

 

 

 

 

SeriesMapping sm1 = new SeriesMapping();

 

 

 

 

StackedBarSeriesDefinition d1 = new StackedBarSeriesDefinition();

 

d1.StackGroupName =

 

 

"GroupName";
sm1.SeriesDefinition = d1;

 

sm1.LegendLabel =

 

 

"Show Me the Ints 1"; // name for each item to show...

 

sm1.CollectionIndex = seriesIndex++; // index into the int array to show data points...

 

 

 

ItemMapping im1 = new ItemMapping("BarDataPoints", DataPointMember.YValue); // contains 4 data elements to show

 

sm1.ItemMappings.Add(im1);

im1 =

 

 

new ItemMapping("CategoryName", DataPointMember.XCategory); // name from class property

 

sm1.ItemMappings.Add(im1);

(etc for each of the 4 Mapping entries)

// now add to the chart...

List<StackedBarData> listOfDataPoints= new List<StackedBarData>();

int [4] data = new int[] { 55, 22, 63, 74};

StackedBarData barData = new StackedBarData();
barData.CateoryName = "My New Int 1";
barData.BarDataPoints = data;

listOfDataPoints.Add(barData)
// add rest of data points...

 

 

 

 

this.RadProgramSiteChart.SeriesMappings.Add(sm1);
(etc for the rest of mappings)

// assign to the chart...

 

 

 

 

 

this.RadProgramSiteChart.ItemsSource = listOfDataPoints;

When I use this, I get the IEnumerable error (can't find the array of ints)..
Where did I go wrong?

Thanks!
Don

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Vladimir Milev
Telerik team
answered on 21 Jul 2009, 07:23 AM
Hi Donald Hamm,

Check this help article. It explains the best way to deal with categories.

Kind regards,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Chart
Asked by
Donald Hamm
Top achievements
Rank 1
Answers by
Vladimir Milev
Telerik team
Share this question
or