Nevron .NET Vision Documentation
State Indicators

State indicators are used to represent a value as a visual state. For example the most common use for state indicators is found in car dashboards where usually a red led indicator is lit when the car will soon run out of fuel.

Each state indicator has a value (controlled through the Value property) and a variable number of states. Each state indicator state has a range and style settings. When the value of the state indicator changes it will go trough the available states and display the active ones. A state is considered active when its range contains the state indicator value.

Creating a State Indicator

You create a state indicator by creating an instance of the NStateIndicatorPanel class. For example:

C#
Copy Code

NStateIndicatorPanel stateIndicator = new NStateIndicatorPanel();
nChartControl1.Panels.Add(stateIndicator);

Visual Basic
Copy Code

Dim stateIndicator As New NStateIndicatorPanel
NChartControl1.Panels.Add(stateIndicator)

Now the state indicator is added to the panels collection of the control. By default each state indicator has a default state. This state is visualized when there is no selected active state from the States collection of the indicator. To set the value of the of the state indicator (that controls how active states are selected) you must touch the Value property:

C#
Copy Code
stateIndicator.Value = 10;
Visual Basic
Copy Code
stateIndicator.Value = 10
Adding States

In order to add more states to the indicator (except the default one) you need to add one or more objects of type NIndicatorState to the states collection of the indicator:

C#
Copy Code

NStateIndicatorPanel stateIndicator = new NStateIndicatorPanel();
nChartControl1.Panels.Add(stateIndicator);

NRangeIndicatorState orangeState = new NRangeIndicatorState();
stateIndicator.States.Add(orangeState);
orangeState.Range =
new NRange1DD(20, 40);
orangeState.Shape.FillStyle =
new NColorFillStyle(Color.Orange);

NRangeIndicatorState redState = new NRangeIndicatorState();
stateIndicator.States.Add(redState);
redState.Range =
new NRange1DD(40, 60);
redState.Shape.FillStyle =
new NColorFillStyle(Color.Red);

Visual Basic
Copy Code

Dim stateIndicator As New NStateIndicatorPanel
NChartControl1.Panels.Add(stateIndicator)

Dim orangeState As New NRangeIndicatorState
stateIndicator.States.Add(orangeState)
orangeState.Range =
New NRange1DD(20, 40)
orangeState.Shape.FillStyle =
New NColorFillStyle(Color.Orange)

Dim redState As New NRangeIndicatorState
stateIndicator.States.Add(redState)
redState.Range =
New NRange1DD(40, 60)
redState.Shape.FillStyle =
New NColorFillStyle(Color.Red)

Now you have a state indicator with three states (the default one) and the two more states - orange that will be active when the value of the state indicator indicator is between 20 and 40 and red when the value is between 40 and 60. The above code also shows how to change the indicator shape color.

Active State(s)

When there is one or more state, that has a range containing the state indicator value it becomes active. How the state indicator visualizes the active states is controlled by the ActiveStateMode property accepting values from the ActiveStateIndicatorMode enum:

Active State Indicator Mode Description
AllActive All active states are added to the indicator
LastActive Only the last active state is added
FirstActive Only the first active state is added

The order in which you add states to the state indicator will reflect how they are visualized as well as whether they will become active (in the case when the active state mode is set to LastActive or FirstActive).

When you have more that one active state the state indicator will regard the value of the orientation property:

 

C#
Copy Code

NStateIndicatorPanel stateIndicator = new NStateIndicatorPanel();
nChartControl1.Panels.Add(stateIndicator);

stateIndicator.ActiveStateMode = ActiveStateIndicatorMode.AllActive;
stateIndicator.Orientation =
StateIndicatorOrientation.Vertical;

// create a smart shape factory

N2DSmartShapeFactory factory = new N2DSmartShapeFactory(new NColorFillStyle(Color.White),new NStrokeStyle(),new NShadowStyle());

// crate the orange range indicator state
NRangeIndicatorState orangeState = new NRangeIndicatorState();
orangeState.Text =
"Orange";
orangeState.ShapeSizeMode =
StateIndicatorShapeSizeMode.SameAsText;
orangeState.TextStyle.FillStyle =
new NColorFillStyle(Color.White);
stateIndicator.States.Add(orangeState);
orangeState.Range =
new NRange1DD(20, 50);
orangeState.Shape = factory.CreateShape(
SmartShape2D.RoundedRectShape);
orangeState.Shape.FillStyle =
new NColorFillStyle(Color.Orange);
orangeState.Shape.StrokeStyle.Color =
Color.DarkOrange;

// crate the red range indicator state
NRangeIndicatorState redState = new NRangeIndicatorState();
redState.Text =
"Red";
redState.TextStyle.FillStyle =
new NColorFillStyle(Color.White);
redState.ShapeSizeMode =
StateIndicatorShapeSizeMode.SameAsText;
stateIndicator.States.Add(redState);
redState.Range =
new NRange1DD(40, 60);
redState.Shape = factory.CreateShape(
SmartShape2D.RoundedRectShape);
redState.Shape.FillStyle =
new NColorFillStyle(Color.Red);
redState.Shape.StrokeStyle.Color =
Color.DarkRed;

stateIndicator.Value = 45;

Visual Basic
Copy Code

Dim stateIndicator As New NStateIndicatorPanel
NChartControl1.Panels.Add(stateIndicator)
stateIndicator.ActiveStateMode = ActiveStateIndicatorMode.AllActive
stateIndicator.Orientation = StateIndicatorOrientation.Vertical

' create a smart shape factory
Dim factory As New N2DSmartShapeFactory(New NColorFillStyle(Color.White), New NStrokeStyle(), New NShadowStyle())

' crate the orange range indicator state
Dim orangeState As New NRangeIndicatorState
orangeState.Text =
"Orange"
orangeState.ShapeSizeMode = StateIndicatorShapeSizeMode.SameAsText
orangeState.TextStyle.FillStyle =
New NColorFillStyle(Color.White)
stateIndicator.States.Add(orangeState)
orangeState.Range =
New NRange1DD(20, 50)
orangeState.Shape = factory.CreateShape(SmartShape2D.RoundedRectShape)
orangeState.Shape.FillStyle =
New NColorFillStyle(Color.Orange)
orangeState.Shape.StrokeStyle.Color = Color.DarkOrange

' crate the red range indicator state
Dim redState As New NRangeIndicatorState
redState.Text =
"Red"
redState.TextStyle.FillStyle = New NColorFillStyle(Color.White)
redState.ShapeSizeMode = StateIndicatorShapeSizeMode.SameAsText
stateIndicator.States.Add(redState)
redState.Range =
New NRange1DD(40, 60)
redState.Shape = factory.CreateShape(SmartShape2D.RoundedRectShape)
redState.Shape.FillStyle =
New NColorFillStyle(Color.Red)
redState.Shape.StrokeStyle.Color = Color.DarkRed

stateIndicator.Value = 45

Related Examples

Gauge Gallery \ Gauges \ Indicators \ State Indicators

 

See Also

 

 


©2017. Nevron Software LLC.

Send Feedback