XAxis BaseUnit Months count not correct

6 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    7 posts
    Member since:
    Mar 2014

    Posted 30 May 2014 Link to this post

    I am creating a chart with a DateTime for the X axis. When I set BaseUnit to Days each days count is correct, but when I set BaseUnit to Months the count is not correct.

    I'm not sure if my code is incorrect or this is an issue with RadHtmlChart functionality.
    I assume there's nothing wrong with the code since the chart displays counts correctly when BaseUnit is set to Days.

    The month count should be 49 but it's showing up as 17. There are 8 SeriesItems being added and 17 is the value of the 4th item; not sure if that has anything to do with where it's getting 17 from.

    Any help is appreciated!
    public static RadHtmlChart ChartDeploymentsByRemoteImaging(List<DeploymentsView> results)
    {
        RadHtmlChart RadHtmlChart1 = new RadHtmlChart();
        RadHtmlChart1.ID = "RemoteImagingChart";
     
        RadHtmlChart1.Width = Unit.Pixel(680);
        RadHtmlChart1.Height = Unit.Pixel(400);
     
        RadHtmlChart1.ChartTitle.Text = "Remote Imaging";
     
        var groups = results.GroupBy(d => d.Date.Date)
            .Select(g => new
            {
                Date = g.Key,
                Count = g.Count(),
                RemoteCount = g.Where(d=>d.TaskSequence.ToUpper().Contains("OSD")).Count()
            });
     
        ColumnSeries series = new ColumnSeries();
        ColumnSeries seriesRemote = new ColumnSeries();
     
        series.Name = "Local Imaging";
        seriesRemote.Name = "Remote Imaging";
     
        series.GroupName = "Total";
        seriesRemote.GroupName = "Total";
     
        foreach (var group in groups)
        {
            CategorySeriesItem seriesItem = new CategorySeriesItem((decimal?)(group.Count - group.RemoteCount));
            series.SeriesItems.Add(seriesItem);
     
            CategorySeriesItem seriesRemoteItem = new CategorySeriesItem((decimal?)(group.RemoteCount));
            seriesRemote.SeriesItems.Add(seriesRemoteItem);
     
            RadHtmlChart1.PlotArea.XAxis.Items.Add(new AxisItem { LabelText = group.Date.ToShortDateString() });
        }
     
        series.LabelsAppearance.Visible = false;
        seriesRemote.LabelsAppearance.Visible = false;
     
        RadHtmlChart1.PlotArea.Series.Add(series);
        RadHtmlChart1.PlotArea.Series.Add(seriesRemote);
     
        RadHtmlChart1.PlotArea.XAxis.BaseUnit = Telerik.Web.UI.HtmlChart.DateTimeBaseUnit.Months;
        RadHtmlChart1.PlotArea.XAxis.Type = Telerik.Web.UI.HtmlChart.AxisType.Date;
     
        return RadHtmlChart1;
    }
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 03 Jun 2014 Link to this post

    Hello Jonathan,

    Could you please try to provide us with the values from the "groups" collection, so that I can run the example and reproduce the issue? You can for example hard code these values in the example from your post.

    Regards,
    Danail Vasilev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jonathan
    Jonathan avatar
    7 posts
    Member since:
    Mar 2014

    Posted 03 Jun 2014 in reply to Danail Vasilev Link to this post

    Here are the values being used for the charts in the previous attached screenshots.
    public class Helper
    {
        public DateTime Date { get; set; }
        public int Count { get; set; }
        public int RemoteCount { get; set; }
    }
     
    List<Helper> groups = new List<Helper>();
    groups.Add(new Helper { Date = DateTime.Parse("3/1/2014 12:00:00 AM"), Count = 3, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/2/2014 12:00:00 AM"), Count = 5, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/3/2014 12:00:00 AM"), Count = 4, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/4/2014 12:00:00 AM"), Count = 17, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/5/2014 12:00:00 AM"), Count = 16, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/6/2014 12:00:00 AM"), Count = 2, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/10/2014 12:00:00 AM"), Count = 1, RemoteCount = 0 });
    groups.Add(new Helper { Date = DateTime.Parse("3/11/2014 12:00:00 AM"), Count = 1, RemoteCount = 0 });


    When setting to BaseUnit = Months the chart should show 49 but instead shows 17.
       
    I also have another chart I just started working on where I need the ability to switch between count and cumulative sum. I am simply incrementing the value of sum on each loop.
    When I create the chart using cumulative sums it displays correctly no matter what BaseUnit value I set, but if I just use count for each series instead of cumulative sum the Months BaseUnit does the same thing as my post above.

    int sum = 0;
     
    foreach (var item in group.Dates)
    {
     
        if (Cumulative)
            sum += item.Count;
        else
            sum = 0 + item.Count;
     
        CategorySeriesItem seriesItem = new CategorySeriesItem((decimal?)sum);
        series.SeriesItems.Add(seriesItem);
     
        RadHtmlChart1.PlotArea.XAxis.Items.Add(new AxisItem { LabelText = item.Date.ToShortDateString() });
    }



    I looked at the Telerik Chart demo for Date Axis (HtmlChart - Date Axis) and noticed that it says BaseUnit will handle the aggregation for you but in the example chart when you set the BaseUnit to Months its doesn't aggregate, for January it just shows the count on 1/1/1997 instead of the total for the month.
    I am thinking eitehr the aggregation doesn't work correctly or there's something I am missing with how aggregation is implemented in relation to BaseUnit.
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 05 Jun 2014 Link to this post

    Hi Jonathan,

    Thank you for the additional clarification.

    By default the aggregation function that applies to category series with date axis is "max". You can, however, modify it through the chartObject, as illustrated in the feedback item I have created on this regard. For example:
    ASPX:
    <asp:PlaceHolder ID="Placeholder1" runat="server" />
    C#:
    public partial class Examples1_Default : System.Web.UI.Page
    {
        public RadHtmlChart ChartDeploymentsByRemoteImaging()
        {
            RadHtmlChart RadHtmlChart1 = new RadHtmlChart();
            RadHtmlChart1.ID = "RemoteImagingChart";
     
            RadHtmlChart1.Width = Unit.Pixel(680);
            RadHtmlChart1.Height = Unit.Pixel(400);
     
            RadHtmlChart1.ChartTitle.Text = "Remote Imaging";
     
            ColumnSeries series = new ColumnSeries();
            series.LabelsAppearance.Visible = false;
     
            series.DataFieldY = "Count";
            RadHtmlChart1.PlotArea.XAxis.DataLabelsField = "Date";
            RadHtmlChart1.DataSource = GetData();
            RadHtmlChart1.DataBind();
     
            RadHtmlChart1.PlotArea.Series.Add(series);
     
            RadHtmlChart1.PlotArea.XAxis.BaseUnit = Telerik.Web.UI.HtmlChart.DateTimeBaseUnit.Months;
            RadHtmlChart1.PlotArea.XAxis.Type = Telerik.Web.UI.HtmlChart.AxisType.Date;
     
            return RadHtmlChart1;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Placeholder1.Controls.Add(ChartDeploymentsByRemoteImaging());
            string script = "function f(){var chart = $find(\"" + ChartDeploymentsByRemoteImaging().ClientID + "\"); chart._chartObject.options.series[0].aggregate ='sum'; chart.repaint(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", script, true);
        }
        protected List<Helper> GetData()
        {
            List<Helper> groups = new List<Helper>();
            groups.Add(new Helper { Date = DateTime.Parse("3/1/2014 12:00:00 AM"), Count = 3, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/2/2014 12:00:00 AM"), Count = 5, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/3/2014 12:00:00 AM"), Count = 4, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/4/2014 12:00:00 AM"), Count = 17, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/5/2014 12:00:00 AM"), Count = 16, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/6/2014 12:00:00 AM"), Count = 2, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/10/2014 12:00:00 AM"), Count = 1, RemoteCount = 0 });
            groups.Add(new Helper { Date = DateTime.Parse("3/11/2014 12:00:00 AM"), Count = 1, RemoteCount = 0 });
            return groups;
        }
    }
    public class Helper
    {
        public DateTime Date { get; set; }
        public int Count { get; set; }
        public int RemoteCount { get; set; }
    }

    I have also updated your Telerik points for sharing your ideas with us.

    Regards,
    Danail Vasilev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Manuel
    Manuel avatar
    1 posts
    Member since:
    Aug 2015

    Posted 09 Dec 2015 in reply to Danail Vasilev Link to this post

    I am having the same issue but the solution doesn't work for me.
  7. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 10 Dec 2015 Link to this post

    Hi Manuel,

    I have already replied to the support ticket that was opened by you on the matter, so that we can continue our discussion there. Once we have an resolution we can post it here, for the rest of the community.

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017