DateTimeCategoricalAxis cluster on month

5 posts, 0 answers
  1. E Pons
    E Pons avatar
    16 posts
    Member since:
    Apr 2010

    Posted 19 Dec 2012 Link to this post

    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>
  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 24 Dec 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. E Pons
    E Pons avatar
    16 posts
    Member since:
    Apr 2010

    Posted 26 Dec 2012 Link to this post

    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!
  5. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 28 Dec 2012 Link to this post

    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.

  6. E Pons
    E Pons avatar
    16 posts
    Member since:
    Apr 2010

    Posted 16 Jan 2013 Link to this post

    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;
               }
           }
       }
Back to Top
UI for WPF is Visual Studio 2017 Ready