Back to column formats
Column formattingSharePoint 2019SharePoint Online

Multi-Colored Databars

This column formatting sample demonstrates how to show the number column as data bars with multiple colors.

Multi-Colored Databars 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": "span",
      "txtContent": "=(100 * @currentField) + '%'",
      "style": {
        "padding-left": "8px",
        "white-space": "nowrap"
      }
    }
  ],
  "attributes": {
    "role": "progressbar",
    "aria-valuenow": "@currentField",
    "aria-valuemin": "0",
    "aria-valuemax": "1"
  },
  "style": {
    "padding": "0",
    "color": "black",
    "background-color": "=if(@currentField <= 0.25, '#c86c70', if(@currentField <= 0.5, '#ffc83d', '#85b44c'))",
    "border-top": "='2px solid' + if(@currentField <= 0.25, '#a4262c', if(@currentField <= 0.5, '#997825', '#498205'))",
    "width": "=if(@currentField > 1, '100%', if(@currentField < 0, '0', (100 * @currentField) + '%'))",
    "box-sizing": "border-box"
  }
}

From the contributor

How to use this sample

Summary

This column formatting sample demonstrates how to show the number column as data bars with multiple colors. Background color changes depending on the value:

Value Color
0% - 25% Red
26% - 50% Yellow
51% - 100% Green

screenshot of the sample

This sample is derived from number-data-bar.

View requirements

This format can be applied to a Number column. It is expected that the values will be from 0 to 1 (percent).

Sample

Solution Author(s)
number-data-bar-multi-color.json Ganesh Sanap

Version history

Version Date Comments
1.0 December 29, 2021 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.