Back to column formats
Column formattingSharePoint Online

Like/Dislike Bar

This sample demonstrates displaying a Like/Dislike bar that visualizes the ratio of Like to Dislike users.

Like/Dislike 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",
  "style": {
    "width": "100%",
    "text-align": "center"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "height": "20px",
        "width": "90%",
        "display": "flex",
        "flex-direction": "row"
      },
      "attributes": {
        "class": "=if((length([$Like]) + length([$Dislike]) == 0 , 'ms-bgColor-sharedGray10' , '')"
      },
      "children": [
        {
          "elmType": "div",
          "style": {
            "height": "100%",
            "width": "=((length([$Like])  / (length([$Like]) + length([$Dislike]))) * 100 + '%'",
            "cursor": "pointer"
          },
          "attributes": {
            "class": "ms-bgColor-tealLight ms-bgColor-teal--hover"
          },
          "customCardProps": {
            "openOnEvent": "hover",
            "directionalHint": "topCenter",
            "isBeakVisible": true,
            "formatter": {
              "elmType": "div",
              "style": {
                "padding": "10px 20px 10px 20px"
              },
              "children": [
                {
                  "elmType": "div",
                  "style": {
                    "font-size": "25px",
                    "font-weight": "bold"
                  },
                  "attributes": {
                    "class": "ms-fontColor-tealLight"
                  },
                  "children": [
                    {
                      "elmType": "span",
                      "txtContent": "=floor(((length([$Like])/(length([$Like]) + length([$Dislike])) * 100)"
                    },
                    {
                      "elmType": "span",
                      "txtContent": "%",
                      "style": {
                        "margin-left": "5px"
                      }
                    }
                  ]
                },
                {
                  "elmType": "div",
                  "txtContent": "='(' + length([$Like])  + '/' + (length([$Like]) + length([$Dislike]) + ')'",
                  "style": {
                    "margin-left": "5px"
                  }
                }
              ]
            }
          }
        },
        {
          "elmType": "div",
          "style": {
            "height": "100%",
            "width": "=((length([$Dislike])  / (length([$Like]) + length([$Dislike]))) * 100 + '%'",
            "cursor": "pointer"
          },
          "attributes": {
            "class": "ms-bgColor-red ms-bgColor-redDark--hover"
          },
          "customCardProps": {
            "openOnEvent": "hover",
            "directionalHint": "topCenter",
            "isBeakVisible": true,
            "formatter": {
              "elmType": "div",
              "style": {
                "padding": "10px 20px 10px 20px"
              },
              "children": [
                {
                  "elmType": "div",
                  "style": {
                    "font-size": "25px",
                    "font-weight": "bold"
                  },
                  "attributes": {
                    "class": "ms-fontColor-red"
                  },
                  "children": [
                    {
                      "elmType": "span",
                      "txtContent": "=floor(((length([$Dislike])/(length([$Like]) + length([$Dislike])) * 100)"
                    },
                    {
                      "elmType": "span",
                      "txtContent": "%",
                      "style": {
                        "margin-left": "5px"
                      }
                    }
                  ]
                },
                {
                  "elmType": "div",
                  "txtContent": "='(' + length([$Dislike])  + '/' + (length([$Like]) + length([$Dislike]) + ')'",
                  "style": {
                    "margin-left": "5px"
                  }
                }
              ]
            }
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates displaying a Like/Dislike bar that visualizes the ratio of Like to Dislike users.

screenshot of the sample

You can combine this sample with the multi-person-unique-reaction sample, to incorporate Like and Dislike buttons.

screenshot of the sample

View requirements

This format can be applied to any column type but expects the following columns to be part of the view:

Type Internal Name Required
Person or Group (Multi) Like No
Person or Group (Multi) Dislike No

Sample

Solution Author(s)
generic-like-dislike-bar.json Tetsuya Kawahara

Version history

Version Date Comments
1.0 March 20, 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.