Back to column formats
Column formattingSharePoint Online

Number Level Bar

This sample demonstrates displaying a percentage across a bar. End users are able to edit the values by increasing/decreasing in 25% increments using arrow buttons.

Number Level Bar formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",
      "attributes": {
        "iconName": "ChromeBack",
        "class": "=if(@currentField>0,'ms-fontColor-neutralPrimary ms-fontColor-themePrimary--hover', 'ms-fontColor-neutralLight')"
      },
      "style": {
        "cursor": "pointer",
        "padding-right": "4px"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "ThreatLevel": "=if(@currentField>= .25,@currentField-.25,0)*100"
        }
      }
    },
    {
      "elmType": "div",
      "style": {
        "position": "relative",
        "width": "100%",
        "height": "40px",
        "display": "flex",
        "align-items": "center"
      },
      "children": [
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-greenLight"
          },
          "style": {
            "margin-left": "3px",
            "width": "25%",
            "height": "60%"
          }
        },
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-yellow"
          },
          "style": {
            "width": "25%",
            "height": "60%"
          }
        },
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-orangeLight"
          },
          "style": {
            "width": "25%",
            "height": "60%"
          }
        },
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-redDark"
          },
          "style": {
            "width": "25%",
            "height": "60%"
          }
        },
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-black"
          },
          "style": {
            "position": "absolute",
            "left": "=([$ThreatLevel]*100) + '%'",
            "width": "6px",
            "height": "80%",
            "border-radius": "3px"
          }
        }
      ]
    },
    {
      "elmType": "div",
      "attributes": {
        "iconName": "ChromeBackMirrored",
        "class": "=if(@currentField<1,'ms-fontColor-neutralPrimary ms-fontColor-themePrimary--hover', 'ms-fontColor-neutralLight')"
      },
      "style": {
        "cursor": "pointer",
        "padding-left": "7px"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "ThreatLevel": "=if(@currentField < 1,@currentField+.25,1)*100"
        }
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates displaying a percentage across a bar. End users are able to edit the values by increasing/decreasing in 25% increments using arrow buttons.

screenshot of the sample

View requirements

This format can be applied to any number column. It expects the values to be percents (0-1) but the format could be adjusted for custom ranges by changing the expressions.

Sample

Solution Author(s)
number-level-bar.json Chris Kent

Version history

Version Date Comments
1.0 May 12, 2022 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes