Add multiple horizontal floating bars in the same lane

Applies to: Nevron Chart for .NET

How to add multiple horizontal floating bars in the same lane?

The following example demonstrates how to add several floating bars in the same lane:



[C#]
using System;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.GraphicsCore;
...
private void Form1_Load(object sender, EventArgs e)
{
    NChart chart = nChartControl1.Charts[0];
    chart.DisplayOnLegend.Visible = false;
    chart.Width = 100;
    chart.Dock = DockStyle.Fill;
    chart.DockMargins = new NMarginsL(5, 5, 5, 5);
      
    NAxis axisX = chart.Axis(StandardAxis.PrimaryX);
    axisX.View = new NRangeAxisView(new NRange1DD(CategoryValues.Min - 0.5, CategoryValues.Max + 0.5), true, true);
    NOrdinalScaleConfigurator scaleX = (NOrdinalScaleConfigurator)axisX.ScaleConfigurator;
    scaleX.MajorTickMode = MajorTickMode.CustomStep;
    scaleX.CustomStep = 1;
  
    NFloatBarSeries floatBar = new NFloatBarSeries();
    chart.Series.Add(floatBar);
    floatBar.UseXValues = true;
    floatBar.DataLabelStyle.Visible = false;
    floatBar.BarWidth = new NLength(10, NRelativeUnit.ParentPercentage);
  
    AddItem(floatBar, 10, 15, CategoryValues.Ignition);
    AddItem(floatBar, 27.5, 34.2, CategoryValues.Ignition);
    AddItem(floatBar, 21, 55, CategoryValues.Moving);
    AddItem(floatBar, 67, 69, CategoryValues.Moving);
    AddItem(floatBar, 30, 45, CategoryValues.Rightlnd);
    AddItem(floatBar, 60, 70, CategoryValues.Rightlnd);
    AddItem(floatBar, 80, 95, CategoryValues.Rightlnd);
}
  
void AddItem(NFloatBarSeries floatBar, double from, double to, double x)
{
    floatBar.BeginValues.Add(from);
    floatBar.EndValues.Add(to);
    floatBar.XValues.Add(x);
}
  
class CategoryValues
{
    internal const double Ignition = 0;
    internal const double EngineRunning = 1;
    internal const double Moving = 2;
    internal const double Idling = 3;
    internal const double Brakes = 4;
    internal const double Rightlnd = 5;
    internal const double Leftlnd = 6;
  
    internal const double Min = Ignition;
    internal const double Max = Leftlnd;
}

[VB.NET]
Imports System
Imports System.Windows.Forms
Imports Nevron.Chart
Imports Nevron.GraphicsCore
...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim chart As NChart = nChartControl1.Charts(0)
    chart.DisplayOnLegend.Visible = False
    chart.Width = 100
    chart.Dock = DockStyle.Fill
    chart.DockMargins = New NMarginsL(5, 5, 5, 5)
  
    Dim axisX As NAxis = chart.Axis(StandardAxis.PrimaryX)
    axisX.View = New NRangeAxisView(New NRange1DD(CategoryValues.Min - 0.5, CategoryValues.Max + 0.5), True, True)
    Dim scaleX As NOrdinalScaleConfigurator = DirectCast(axisX.ScaleConfigurator, NOrdinalScaleConfigurator)
    scaleX.MajorTickMode = MajorTickMode.CustomStep
    scaleX.CustomStep = 1
  
    Dim floatBar As New NFloatBarSeries()
    chart.Series.Add(floatBar)
    floatBar.UseXValues = True
    floatBar.DataLabelStyle.Visible = False
    floatBar.BarWidth = New NLength(10, NRelativeUnit.ParentPercentage)
  
    AddItem(floatBar, 10, 15, CategoryValues.Ignition)
    AddItem(floatBar, 27.5, 34.2, CategoryValues.Ignition)
    AddItem(floatBar, 21, 55, CategoryValues.Moving)
    AddItem(floatBar, 67, 69, CategoryValues.Moving)
    AddItem(floatBar, 30, 45, CategoryValues.Rightlnd)
    AddItem(floatBar, 60, 70, CategoryValues.Rightlnd)
    AddItem(floatBar, 80, 95, CategoryValues.Rightlnd)
End Sub
  
Private Sub AddItem(ByVal floatBar As NFloatBarSeries, ByVal from As Double, ByVal [to] As Double, ByVal x As Double)
    floatBar.BeginValues.Add(from)
    floatBar.EndValues.Add([to])
    floatBar.XValues.Add(x)
End Sub
  
Class CategoryValues
    Friend Const Ignition As Double = 0
    Friend Const EngineRunning As Double = 1
    Friend Const Moving As Double = 2
    Friend Const Idling As Double = 3
    Friend Const Brakes As Double = 4
    Friend Const Rightlnd As Double = 5
    Friend Const Leftlnd As Double = 6
  
    Friend Const Min As Double = Ignition
    Friend Const Max As Double = Leftlnd
End Class

In order to set different colors for the bars you can choose one of the following options:
1. Use multiple series – one for each lane.
2. Use only one series and set individual colors for each bar.

Article ID: 117, Created On: 11/8/2010, Modified: 12/1/2010