How to add a threshold in TypeScript Charts

Use a strip line on the vertical axis to display a horizontal threshold across the Chart. Configure the strip line through primaryYAxis.stripLines and set visible to true.

Configure the threshold

Set start and end to define the threshold range. For a thin threshold line, use a small difference between the two values. For a highlighted band, use a wider range.

primaryYAxis: {
    stripLines: [{
        start: 30,
        end: 30.1,
        visible: true,
        color: '#ff512f',
        textStyle: { size: '18px', color: '#ffffff', fontWeight: '600' },
    }]
}

A strip line configured on the Y-axis is horizontal. A strip line configured on the X-axis is vertical.

Complete example

import { Chart, LineSeries, Category, Legend, Tooltip, ILoadedEventArgs, StripLine, ChartTheme } from '@syncfusion/ej2-charts';
Chart.Inject(LineSeries, Category, Legend, Tooltip, StripLine);
    let chart: Chart = new Chart({
        //Initializing Primary X Axis
        primaryXAxis: {
            valueType: 'Category',
        },
        //Initializing Primary Y Axis
        primaryYAxis:
        {
            minimum: 10, maximum: 40, interval: 5,
            lineStyle: { color: '#808080' }, labelFormat: '{value} °C', rangePadding: 'None',
            //Initializing Striplines
            stripLines: [
                {
                    start: 30, end: 30.1, color: '#ff512f', visible: true,
                    textStyle: { size: '18px', color: '#ffffff', fontWeight: '600' },
                }
            ]
        },
        //Initializing Chart Series
        series: [
            {
                dataSource: [
                    { x: 'Sun', y: 28 }, { x: 'Mon', y: 27 }, { x: 'Tue', y: 33 }, { x: 'Wed', y: 36 },
                    { x: 'Thu', y: 28 }, { x: 'Fri', y: 30 }, { x: 'Sat', y: 31 }],
                xName: 'x', width: 2, yName: 'y',  type: 'Line', name: 'Weather',
                marker: { visible: true, width: 10, height: 10, border: { width: 2, color: '#ffffff' }, fill: '#666666' },
            },
        ],
        legendSettings: { visible: false },
        //Initializing Chart Title
        title: 'Weather Report',
        height: '350px'
    });
    chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div class="col-sm-8">
            <div class="row">
                <div class="col-sm-4">  
                  <div id='container'>
                    <div id='element'  style="width:350px; height:350px;float:left">
                    </div>
                    <label id="lbl"></label>
                  </div>
                </div>
                <div class="col-sm-4" style="width:200px; height:350px;float: right">
                  <div id='Grid'>
                  </div>
                </div>
            </div>
    </div>
</body> 
</html>

Strip-line options

  • start and end define the highlighted axis range.
  • visible controls whether the strip line is rendered.
  • color and opacity control the threshold appearance.
  • text and textStyle add and format a threshold label.
  • zIndex: 'Behind' places the threshold behind the series; zIndex: 'Over' places it above the series.
  • dashArray can be used when the threshold should appear dashed.
  • Multiple objects can be added to stripLines to show several thresholds or ranges.

Troubleshooting

  • If the threshold is outside the plot area, verify that start and end fall within the axis range.
  • If the threshold is vertical instead of horizontal, move stripLines from the X-axis to the Y-axis.
  • If the threshold obscures the series, set zIndex to Behind or reduce opacity.
  • If a thin threshold is difficult to see, increase the difference between start and end or use a contrasting color.

See also