Profile Picture

X-axis dates with inconsistent time-intervals

Posted By Vahid Mesri 7 Years Ago
Author
Message
Vahid Mesri
Problem Posted 7 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 11, Visits: 67
Hi,

In my smooth-line plot, the x-values are dates and the y-values are percentages.
The issue is that I have monthly values at the beginning section of my plot, however, after two years, the dates are updated on yearly basis, therefore the dates do not have consistent intervals.

Please find attached the plot I've created using the Microsoft chart control. I would like to use Nevron to reproduce this plot but unfortunately it treats the dates as categories and not datetime variables.

Thanks a lot for your help Smile

 https://www.nevron.com/forum/uploads/images/d3035e64-c2a9-4868-96e6-197d.png



Nevron Support
This post has been flagged as an answer
Posted 7 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746
Hello Vahid,
This is caused by the default axis scaling. You can use the following custom C# code:
using System;
using System.Drawing;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;

namespace MyNamespace
{
      /// <summary>
      /// Sample class
      /// </summary>
      public class MyClass
      {
           /// <summary>
           /// Main entry point
           /// </summary>
           /// <param name="context"></param>
           public static void RSMain(NRSChartCodeContext context)
           {
                NChart chart = context.document.Charts[0];
                NDateTimeScaleConfigurator dateTimeScale = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NDateTimeScaleConfigurator;

                if (dateTimeScale != null)
                {
                      bool hasMin = false;
                      DateTime minValue = new DateTime();
                      foreach (NSeriesBase series in chart.Series)
                      {
                           NXYScatterSeries xyScatter = series as NXYScatterSeries;

                           if (xyScatter != null && xyScatter.XValues.Count > 0)
                           {
                                DateTime curXValue = DateTime.FromOADate((double)xyScatter.XValues[0]);
                                if (hasMin)
                                {
                                      minValue = minValue < curXValue ? minValue : curXValue;
                                }
                                else
                                {
                                      hasMin = true;
                                      minValue = curXValue;
                                }
                           }
                      }

                      if (hasMin)
                      {
                           dateTimeScale.UseOrigin = true;

                           dateTimeScale.Origin = new DateTime(minValue.Year, minValue.Month, 1, 0, 0, 0);
                      }
                }
           }
      }
}



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic