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

StackedBar wont show items

1 Answer 57 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Letoir
Top achievements
Rank 1
Letoir asked on 02 Dec 2011, 03:36 PM
I Have an asset with with a name, that contains  a value for each day (in  7 days)
List <ChartData>list = xData.GetData(DateTime.FromOADate(40839), DateTime.FromOADate(40846),  assetName);
so here i am saving for each asset the day, the name and the value it has on that day

no i want to make a stackedbar, where the value for each asset is given on day 12/1/2011, so i want all assets like
xbox, telephone, tv, .. give a value in a stackedbar for 12/1/2011 in the stackedbar chart.

How can i do this, 

this is what i tried

List<ChartTot> data = new List<ChartTot>();
 
XMLData xData = new XMLData();
XMLData xData2 = new XMLData();
 
data.Add(new ChartTot(xData.GetData(DateTime.FromOADate(40839), DateTime.FromOADate(40846), "Stereo")));
data.Add(new ChartTot(xData2.GetData(DateTime.FromOADate(40839), DateTime.FromOADate(40846), "Gas")));
 
radChart1.ItemsSource = data;
public class ChartTot
   {
       private List<ChartData> cd = new List<ChartData>();
 
       public ChartTot(List<ChartData> list)
       {
           this.cd = list;
       }
   }
public class ChartData
  {
      public String Naam { get; set; }
      public double Waarde { get; set; }
      public DateTime DezeW { get; set; }
 
 
 
      public ChartData()
      {
      }
}
 

(xData.GetData(DateTime.FromOADate(40839), DateTime.FromOADate(40846), "Stereo")
this gives me a list from ChartData class, and i put it in a List of ChartTot.

the itemsSource contains a list (ChartTot) that contains a list of ChartData

But i get no chart ???

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 07 Dec 2011, 03:11 PM
Hi Letoir,

Below I have pasted some code that you can use to get you started with stacked bar series.

<telerik:RadChart x:Name="radChartProducts" >
 <telerik:RadChart.SeriesMappings>
                 
  <telerik:SeriesMapping>
     <telerik:ItemMapping DataPointMember="XCategory" FieldName="ProductName" />
     <telerik:ItemMapping DataPointMember="YValue" FieldName="SoldUnits" />
  <telerik:SeriesMapping.SeriesDefinition>
  <telerik:StackedBarSeriesDefinition />
     </telerik:SeriesMapping.SeriesDefinition>
  </telerik:SeriesMapping>
 
  <telerik:SeriesMapping>
     <telerik:ItemMapping DataPointMember="XCategory" FieldName="ProductName" />
     <telerik:ItemMapping DataPointMember="YValue" FieldName="ReturnedUnits" />
  <telerik:SeriesMapping.SeriesDefinition>
  <telerik:StackedBarSeriesDefinition />
     </telerik:SeriesMapping.SeriesDefinition>
  </telerik:SeriesMapping>
 
 </telerik:RadChart.SeriesMappings>
</telerik:RadChart>

public partial class MainWindow : Window
{
  public MainWindow()
  {
    InitializeComponent();
 
    var products = new List<ProductInfo>()
    {
      new ProductInfo(){ProductName="keyboard", SoldUnits=200, ReturnedUnits=40},
      new ProductInfo(){ProductName="xbox", SoldUnits=150, ReturnedUnits=30},
      new ProductInfo(){ProductName="mouse", SoldUnits=120, ReturnedUnits=10},
      new ProductInfo(){ProductName="monitor", SoldUnits=220, ReturnedUnits=10},
      new ProductInfo(){ProductName="motherboard", SoldUnits=150, ReturnedUnits=20},           
    };
 
    this.radChartProducts.ItemsSource = products;
  }
}
 
public class ProductInfo
{
  public string ProductName { get; set; }
  public int SoldUnits { get; set; }
  public int ReturnedUnits { get; set; }
}


For more information and examples you can download our examples from here or if you have installed our controls you can find the example projects in your local program files directory
C:\Program Files (x86) \ Telerik \ RadControls for Wpf Q3 2011 \ Demos

Look specifically for the Stacked Bar examples. Looking from these examples you can see how classes are structured and how you need to pass data to the chart in order to use the stacked bar series.

You might also find this help topic on Grouping and Aggregation helpful.

Please read this topic on Categorical Charts too and have in mind that the data for one category will appear stacked when using stacked bar series. 


Greetings,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Letoir
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or