Hi Jacobus,
The following code creates StackedBar as the one you wanted in your picture.
public partial class MainPage : UserControl
{
public class Company
{
public string Name { get; set; }
public double Value1 { get; set; }
public double Value2 { get; set; }
public double Value3 { get; set; }
public Company(string name, double value1, double value2, double value3)
{
Name = name;
Value1 = value1;
Value2 = value2;
Value3 = value3;
}
}
public MainPage()
{
InitializeComponent();
List<
Company
> sampleData = new List<
Company
>();
sampleData.Add(new Company("Physical", 100, 400, 300));
sampleData.Add(new Company("Virtualized", 600, 200, 240));
SeriesMapping seriesMapping = new SeriesMapping { LegendLabel = "Series 1" };
seriesMapping.ItemMappings.Add(new ItemMapping("Value1", DataPointMember.YValue));
seriesMapping.ItemMappings.Add(new ItemMapping("Name", DataPointMember.XCategory));
seriesMapping.SeriesDefinition = new StackedBarSeriesDefinition() { ShowItemLabels = true};
SeriesMapping seriesMapping2 = new SeriesMapping { LegendLabel = "Series 2" };
seriesMapping2.ItemMappings.Add(new ItemMapping("Value2", DataPointMember.YValue));
seriesMapping2.ItemMappings.Add(new ItemMapping("Name", DataPointMember.XCategory));
seriesMapping2.SeriesDefinition = new StackedBarSeriesDefinition() {ShowItemLabels = true};
SeriesMapping seriesMapping3 = new SeriesMapping { LegendLabel = "Series 3" };
seriesMapping3.ItemMappings.Add(new ItemMapping("Value3", DataPointMember.YValue));
seriesMapping3.ItemMappings.Add(new ItemMapping("Name", DataPointMember.XCategory));
seriesMapping3.SeriesDefinition = new StackedBarSeriesDefinition() { ShowItemLabels = true };
RadChart1.ItemsSource = sampleData;
RadChart1.DefaultView.ChartArea.AxisY.AutoRange = false;
RadChart1.DefaultView.ChartArea.AxisY.AddRange(0,1200,100);
RadChart1.SeriesMappings.Add(seriesMapping);
RadChart1.SeriesMappings.Add(seriesMapping2);
RadChart1.SeriesMappings.Add(seriesMapping3);
RadChart1.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "C";
}
}
The chart is bound using a list of business objects. List has two elements (that means you'll have two stacked bars). In order to map to such kind of business objects, you have to create a new instance of
SeriesMapping. Each SeriesMapping has ItemMapping property. For each
ItemMappings the following properties are set -
DataPointMember and
FieldName which specifies from where the data should be taken.
To be able to show custom labels for Axis X tickpoints - chart uses
Categories. In above XAML each XCategory is mapped to Name property of the class Company.
Aditionally to show Currency format for YAxis I set AxisY.DefaultLabelFormat property. This is described in our help article -
http://www.telerik.com/help/silverlight/chart-custom-labels.html.
I saw in your picture that you wanted the YAxis to start from 0. RadChart calculates it's range based on it's items values. You can manually set the appropriate range for your chart. This happens when you turn off AutoRange property and set custom values for MinValue, MaxValue and Step. You can find more information about this here -
http://www.telerik.com/help/silverlight/radchart-features-axes-overview.html.
Hope this information helps.
Kind regards,
Evgenia
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