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

DateTimeCategoricalAxis cluster on month

4 Answers 95 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
E Pons
Top achievements
Rank 1
E Pons asked on 20 Dec 2012, 03:33 AM
Hello,

Prior to updating with Q2 and Q3 2012 (at once), we had a RadCartesianChart BarSeries that functioned exactly as desired.  The graph displayed grouped bars from two series by month, regardless of year.  Now, the cluster functionality is no longer working.  It seems that the year is not disregarded as it was before, so each month is listed twice.

Can you please help with how to restore the clustered display by month?

For reference, here's the relevant XAML:
<telerik:RadCartesianChart.HorizontalAxis>
    <telerik:DateTimeCategoricalAxis DateTimeComponent="Month" LabelFormat="MMM" />
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:BarSeries x:Name="ProductionLastYearBarSeries" CombineMode="Cluster"
        CategoryBinding="MonthCategory" ValueBinding="Total" HorizontalContentAlignment="Left">
    <telerik:BarSeries.PointTemplate>
        <DataTemplate>
            <Border BorderBrush="#80B1EE" BorderThickness="1" MaxWidth="20" CornerRadius="1" >
                <Rectangle Fill="#80B1EE" MaxWidth="20"/>
            </Border>
        </DataTemplate>
    </telerik:BarSeries.PointTemplate>
</telerik:BarSeries>
 
<telerik:BarSeries x:Name="ProductionThisYearBarSeries" CombineMode="Cluster"
    CategoryBinding="MonthCategory" ValueBinding="Total" HorizontalContentAlignment="Left">
    <telerik:BarSeries.PointTemplate>
        <DataTemplate>
            <Border BorderBrush="#1A62B9" BorderThickness="1" MaxWidth="20" CornerRadius="1" >
                <Rectangle Fill="#1A62B9" MaxWidth="20"/>
            </Border>
        </DataTemplate>
    </telerik:BarSeries.PointTemplate>
</telerik:BarSeries>

4 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 24 Dec 2012, 09:54 AM
Hi,

 I prepared a sample based on your code snippet and info but was unable to reproduce the unwanted behaviour. Could you please send us a runnable project where this issue occurs or can you reproduce it in the attached one?

Kind regards,
Evgenia
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
E Pons
Top achievements
Rank 1
answered on 26 Dec 2012, 07:01 PM
Hi Evgenia,

Thanks for looking into this.  Unfortunately I'm not able to open the solution you attached.  The first error I see is:

Unable to read the project file 'ChartView_LineSeriesTooltip.csproj'

Is this a WPF project?

Thanks much!
0
Evgenia
Telerik team
answered on 28 Dec 2012, 09:59 AM
Hi,

 Indeed the project was made under Silverlight but you should be able to run it in WPF too. Simply copy-paste the .xaml and .cs in a new WPF project. 

Kind regards,
Evgenia
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
E Pons
Top achievements
Rank 1
answered on 16 Jan 2013, 07:08 PM
An informational note regarding the resolution of this issue:

I created a sample project that reproduced the issue and sent it to Telerik support.  (The previous project posted here by Telerik did not accurately represent the scenario.)

Here is the reply from support:
The behavior that you have observed prior the update was actually incorrect. The DateTimeCategoricalAxis was looking at the Category values as strings (after the formatting) and not as DateTime values as is was supposed to. In order to achieve the same result as before, you should use CategoricalAxis instead. The other required change is to give the date as string. I have attached a modified version of your project to demonstrate this. Lastly you will need to sort the data.


The described solution did solve the problem.  Here's the relevant .cs sample code:
public partial class MainWindow : Window
   {
       public MainWindow()
       {
           this.DataContext = new ViewModel();
           InitializeComponent();
       }
 
       public class ViewModel : ViewModelBase
       {
           private int count = 10;
           private DateTime lastDate = DateTime.Now;
 
           public ViewModel()
           {
               var data = new ObservableCollection<ChartData>();
               for (int i = 1; i < count; i++)
               {
                   this.lastDate = this.lastDate.AddMonths(-1);
                   data.Add(new ChartData() { XDatа = lastDate, YData = i * 1.5 });
               }
 
               this.DataThisYear = data;
 
               data = new ObservableCollection<ChartData>();
               lastDate = DateTime.Now.AddYears(-1);
               for (int i = 1; i < count; i++)
               {
                   this.lastDate = this.lastDate.AddMonths(-1);
                   data.Add(new ChartData() { XDatа = lastDate, YData = i * 3 });
               }
               this.DataLastYear = data;
 
               Sort(this.DataLastYear);
               Sort(this.DataThisYear);
           }
 
           private void Sort(ObservableCollection<ChartData> observableCollection)
           {
               var list = observableCollection.ToList();
 
               list.Sort((a, b) => a.XDatа.CompareTo(b.XDatа));
 
               observableCollection.Clear();
               list.ForEach(item => observableCollection.Add(item));
           }
 
           public ObservableCollection<ChartData> DataThisYear { get; set; }
           public ObservableCollection<ChartData> DataLastYear { get; set; }
       }
 
       public class ChartData
       {
           public string XDatе
           {
               get { return this.XDatа.ToString("MMM"); }
           }
 
           public DateTime XDatа
           {
               get;
               set;
           }
 
           public double YData
           {
               get;
               set;
           }
       }
   }
Tags
ChartView
Asked by
E Pons
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
E Pons
Top achievements
Rank 1
Share this question
or