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… ?
6 Answers, 1 is accepted
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, Xval1 = MonthYear, Xval2 = MonthYear but what would the binding code look like ?
You can populate your chart with DateTime values by using SeriesMapping or DataPoints. Here you can find a helpful article about populating DateTime values:
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:
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:
Let me know if you need additional assistance.
the Telerik team
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.
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.
the Telerik team
Thank you Polina
That has worked perfectly. I really appreciate it.