This is a migrated thread and some comments may be shown as answers.
Stacked Bar Chart, X-Axis as Date
6 Answers 76 Views
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 01 Feb 2011, 07:26 PM

Hi,

I have a Stacked Bar Chart, that is working perfectly. I have the data points and the legend correct; however the X-Axis is number and I need it to be a date.

My source object has  a

List<List<int>> ProcessTotals  for the data
List<string> Process that I used for the legend
List<date> MonthYear for the X-Axis

How would I do this , also how would I format the date to be Jan 10,  Feb 10 etc… ?

Thanks,
Richard

6 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 02 Feb 2011, 04:38 PM

I apologise for the bump but this issue has stopped me in my tracks and I suspect it’s simple fix. Each x-axis point maps directly to my list of dates. As in  Xval0 = MonthYear[0], Xval1 = MonthYear[1], Xval2 = MonthYear[2]  but what would the binding code look like ?


Richard
0
Missing User
answered on 04 Feb 2011, 10:25 AM
Hello Richard,

You can populate your chart with DateTime values by using SeriesMapping or DataPoints. Here you can find a helpful article about populating DateTime values:
http://www.telerik.com/help/silverlight/radchart-features-datetime-support.html

Another thing that needs to be done is to set the IsDateTime to True. This property indicates that the values for the X-axis are considered as dates. Here are described the X-Axis properties:
http://www.telerik.com/help/silverlight/radchart-features-axes-x-axis.html

My suggestion about formatting the date time values is using DefaultLabelFormat and Format Expression. You can try with DefaultLabelFormat="MMM dd". More about Format Expressions can be found here:
http://www.telerik.com/help/silverlight/radchart-features-format-expressions.html

Let me know if you need additional assistance.

Regards,
Polina
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richard
Top achievements
Rank 1
answered on 04 Feb 2011, 02:38 PM

public class ProcessMonthMileStone
{
 public List<string> ProcessNames = new List<string>();
 public List<DateTime> Months = new List<DateTime>();
 public List<List<int>> ProcessMileStones = new List<List<int>>();
}
  
  
int colIndex = 0; 
foreach (string processName in milestone.ProcessNames) 
    SeriesMapping sm = new SeriesMapping() { LegendLabel = processName, CollectionIndex = colIndex }; 
    sm.SeriesDefinition = new StackedBarSeriesDefinition("Stack1"); 
    sm.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.YValue }); 
    //sm.ItemMappings.Add(new ItemMapping("Months", DataPointMember.XValue)); 
    
    radChartMileStones.SeriesMappings.Add(sm); 
    colIndex++; 
//radChartMileStones.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM"; 
radChartMileStones.DefaultView.ChartArea.AxisX.IsDateTime = true
radChartMileStones.DefaultView.ChartArea.AxisX.LabelRotationAngle = -45;


Hi

I’m afraid that didn’t really work for me. It looks like the Stacked Bar chart might behave differently ?

In the code snippet you can see the object that is used as the itemsource for the chart.

Without the DataPointMember.XValue, the chart displays correctly in 6 stacks of 12 items.
However when I add in the DataPointMember.XValue, the stacks break and 12 items are displayed on the x-axis and it does not display the correct date.

I have attached 2 pictures to demonstrate this.

Would it be possible for you to do a small sample project that uses a stacked bar chart with dates on the x-axis, I can’t find any in your online samples.

Thanks,
Richard

0
Richard
Top achievements
Rank 1
answered on 08 Feb 2011, 01:11 PM
I am still struggling with this , if anyone can help it would be really really appreciated.
0
Accepted
Missing User
answered on 10 Feb 2011, 08:38 AM
Hello Richard,

My suggestion is to use a Categorical Chart. By using this kind of chart, the enabled X axis can be used to plot not only values (e.g. number of sales, etc.), but also categories (e.g. months of the year, units, people, etc.). With Category axis the chart treats the data as a sequence of non-numerical text labels. The marker is placed according to the position of the category in the sequence and data is provided per category.

So you can try with : DataPointMember.XCategory instead of DataPointMember.XValue

I have attached a sample project with dates on the x-axis.

Hope this will help.

Best wishes,
Polina
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richard
Top achievements
Rank 1
answered on 10 Feb 2011, 11:42 AM

Thank you Polina

That has worked perfectly. I really appreciate it.

Richard

Tags
Chart
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Missing User
Share this question
or