Show a custom label or name on the chart sections

Applies to: Nevron Chart for .NET

How to show a custom label or name on the chart sections?

This effect can be achieved by using an invisible point series with custom data labels. The following code snippet shows how to achieve background labels:

[C#]
NChart chart = nChartControl1.Charts[0];
nChartControl1.Legends.Clear();
  
NPointSeries labels = new NPointSeries();
  
// hide everything except the labels
labels.UseXValues = true;
labels.MarkerStyle.Visible = false;
labels.DataLabelStyle.Format = "<label>";
labels.BorderStyle.Width = new NLength(0);
labels.FillStyle.SetTransparencyPercent(100);
  
labels.DataLabelStyle.TextStyle.BackplaneStyle.Visible = false;
labels.DataLabelStyle.TextStyle.Orientation = 90;
labels.DataLabelStyle.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Left;
labels.DataLabelStyle.TextStyle.StringFormatStyle.VertAlign = Nevron.VertAlign.Top;
labels.DataLabelStyle.ArrowLength = new NLength(0);
  
labels.Values.Add(0);
labels.XValues.Add(0);
labels.Values.Add(0);
labels.XValues.Add(3);
labels.Values.Add(0);
labels.XValues.Add(6);
  
labels.Labels.Add("Some Label at 0");
labels.Labels.Add("Some Label at 3");
labels.Labels.Add("Some Label at 6");
  
chart.Series.Add(labels);
  
NLineSeries line = new NLineSeries();
line.DataLabelStyle.Visible = false;
line.MarkerStyle.Visible = true;
  
Random rand = new Random();
  
for (int i = 0; i < 10; i++)
{
    line.Values.Add(rand.Next(100));
}
  
chart.Series.Add(line);
  
NOrdinalScaleConfigurator scaleX = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator;
  
NNumericRangeSamplerProvider provider = new NNumericRangeSamplerProvider();
provider.SamplingMode = SamplingMode.CustomStep;
provider.UseOrigin = true;
provider.Origin = 3;
provider.CustomStep = 3;
  
NScaleStripStyle strip = new NScaleStripStyle();
strip.RangeSamplerProvider = provider;
strip.Interval = 1;
strip.Length = 1;
strip.Begin = 1;
strip.SetShowAtWall(ChartWallType.Back, true);
strip.FillStyle = new NColorFillStyle(Color.LightGray);
scaleX.StripStyles.Add(strip);

[VB.NET]
Dim chart As NChart = NChartControl1.Charts(0)
NChartControl1.Legends.Clear()
  
Dim labels As New NPointSeries()
  
' hide everything except the labels
labels.UseXValues = True
labels.MarkerStyle.Visible = False
labels.DataLabelStyle.Format = "<label>"
labels.BorderStyle.Width = New NLength(0)
labels.FillStyle.SetTransparencyPercent(100)
  
labels.DataLabelStyle.TextStyle.BackplaneStyle.Visible = False
labels.DataLabelStyle.TextStyle.Orientation = 90
labels.DataLabelStyle.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Left
labels.DataLabelStyle.TextStyle.StringFormatStyle.VertAlign = Nevron.VertAlign.Top
labels.DataLabelStyle.ArrowLength = New NLength(0)
  
labels.Values.Add(0)
labels.XValues.Add(0)
labels.Values.Add(0)
labels.XValues.Add(3)
labels.Values.Add(0)
labels.XValues.Add(6)
  
labels.Labels.Add("Some Label at 0")
labels.Labels.Add("Some Label at 3")
labels.Labels.Add("Some Label at 6")
  
chart.Series.Add(labels)
  
Dim line As New NLineSeries()
line.DataLabelStyle.Visible = False
line.MarkerStyle.Visible = True
  
Dim rand As New Random()
  
For i As Integer = 0 To 9
    line.Values.Add(rand.[Next](100))
Next
  
chart.Series.Add(line)
  
Dim scaleX As NOrdinalScaleConfigurator = TryCast(chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator, NOrdinalScaleConfigurator)
  
Dim provider As New NNumericRangeSamplerProvider()
provider.SamplingMode = SamplingMode.CustomStep
provider.UseOrigin = True
provider.Origin = 3
provider.CustomStep = 3
  
Dim strip As New NScaleStripStyle()
strip.RangeSamplerProvider = provider
strip.Interval = 1
strip.Length = 1
strip.Begin = 1
strip.SetShowAtWall(ChartWallType.Back, True)
strip.FillStyle = New NColorFillStyle(Color.LightGray)
scaleX.StripStyles.Add(strip)

Article ID: 98, Created On: 10/19/2010, Modified: 12/1/2010