Split DateTime label line


https://www.nevron.com/Forum/Topic12191.aspx
Print Topic | Close Window

By rich dudley - 7 Years Ago
https://www.nevron.com/forum/uploads/images/341904d0-247e-4dd5-8187-e2e2.jpg
How do I split the label row so its Q3 on the first row and 16 below it? If I need to just define a string for each label with a <br/> in it, how do I link it to the data?
By Nevron Support - 7 Years Ago
Hi Rich,
Please provide more information on how you configure the chart - whether this is a categorical or date time scale, code used to configure the control etc. In the case of a categorical scale you can switch the labels to XML formatted text and insert <br/> like you mentioned:

   NChart chart = nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();
   bar.DataLabelStyle.Visible = false;

   bar.Values.Add(10);
   bar.Values.Add(20);

   chart.Series.Add(bar);

   NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;

   ordinalScale.LabelStyle.TextStyle.TextFormat = TextFormat.XML;
   ordinalScale.AutoLabels = false;

   ordinalScale.Labels.Add("Q3<br/>2017");
   ordinalScale.Labels.Add("Q4<br/>2017");

For date time axes the code is similar:

   NChart chart = nChartControl1.Charts[0];

   NLineSeries line = new NLineSeries();
   line.DataLabelStyle.Visible = false;
   line.UseXValues = true;

   Random rand = new Random();
   DateTime dt = DateTime.Now;

   for (int i = 0; i < 10; i++)
   {
    line.Values.Add(10);
    line.XValues.Add(dt.ToOADate());
    dt = dt.AddMonths(3);
   }

   chart.Series.Add(line);

   NDateTimeScaleConfigurator dateTimeScale = new NDateTimeScaleConfigurator();
   dateTimeScale.LabelStyle.TextStyle.TextFormat = TextFormat.XML;
   dateTimeScale.LabelValueFormatter = new NDateTimeValueFormatter("#Q<br/>yy");
   chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = dateTimeScale;

   dateTimeScale.MajorTickMode = MajorTickMode.CustomStep;
   dateTimeScale.EnableUnitSensitiveFormatting = false;
   dateTimeScale.CustomStep = new NDateTimeSpan(3, NDateTimeUnit.Month);


Hope this helps - let us know if you meet any problems or have any questions.
By rich dudley - 7 Years Ago
I am using a DateTimeScale. adding the br to the value formatter is exactly what I needed. Is there a way to use a datetimescale without resetting the scale configurator with new NDateTimeScaleConfigurator() to keep any already defined settings?

List<NDateTimeUnit> dateTimeUnits = new List<NDateTimeUnit>();
dateTimeUnits.Add(NDateTimeUnit.Quarter);
dateTimeUnits.Add(NDateTimeUnit.Year);

chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NDateTimeScaleConfigurator();
NDateTimeScaleConfigurator scale = (NDateTimeScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
scale.LabelStyle.ContentAlignment = ContentAlignment.MiddleLeft;
scale.EnableUnitSensitiveFormatting = false;
scale.LabelValueFormatter = new NDateTimeValueFormatter("#Q yy");
scale.AutoDateTimeUnits = dateTimeUnits.ToArray();

line.UseXValues = true;

try
{
  foreach (DataRow row in RLChartData.Rows)
  {
   DateTime date = Convert.ToDateTime(row[valueColumnName[1]].ToString());
   double value = Convert.ToDouble(row[valueColumnName[0]]);
   line.XValues.Add(date);
   line.Values.Add(value);
  }
}
catch (System.Exception e) { }
By Nevron Support - 7 Years Ago

Hi Rich,
Yes you just need to add the following:

scale.LabelStyle.TextStyle.TextFormat = TextFormat.XML;
scale.LabelValueFormatter = new NDateTimeValueFormatter("#Q<br/>yy");

and it should be working.