Back to column formats
Column formattingSharePoint Online

Heart in Heart

This sample demonstrates how to change the size of a heart by using the percent value of a numeric column.

Heart in Heart formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

2 definitions

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",
      "style": {
        "display": "flex",
        "flex-direction": "row",
        "align-items": "center",
        "margin": "3px",
        "white-space": "nowrap"
      },
      "children": [
        {
          "elmType": "div",
          "style": {
            "position": "relative",
            "height": "60px",
            "width": "100px",
            "color": "#FF0000"
          },
          "children": [
            {
              "elmType": "div",
              "style": {
                "position": "absolute",
                "height": "100%",
                "width": "100%",
                "display": "flex",
                "align-items": "center",
                "justify-content": "center"
              },
              "children": [
                {
                  "elmType": "svg",
                  "style": {
                    "fill": "currentColor",
                    "fill-opacity": "10%",
                    "height": "100%"
                  },
                  "attributes": {
                    "viewBox": "0 0 100 100"
                  },
                  "children": [
                    {
                      "elmType": "path",
                      "attributes": {
                        "d": "M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z"
                      }
                    }
                  ]
                }
              ]
            },
            {
              "elmType": "div",
              "style": {
                "position": "absolute",
                "height": "100%",
                "width": "100%",
                "display": "flex",
                "align-items": "center",
                "justify-content": "center"
              },
              "children": [
                {
                  "elmType": "svg",
                  "style": {
                    "fill": "currentColor",
                    "height": "=if(@currentField > 1 , '100%', if(@currentField < 0 , '0%' , @currentField.displayValue))"
                  },
                  "attributes": {
                    "viewBox": "0 0 100 100"
                  },
                  "children": [
                    {
                      "elmType": "path",
                      "attributes": {
                        "d": "M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z"
                      }
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "elmType": "div",
          "txtContent": "@currentField.displayValue",
          "style": {
            "font-size": "18px",
            "font-weight": "bold"
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates how to change the size of a heart by using the percent value of a numeric column.

  • number-heart-in-heart.json uses the theme color of the site as the color of the heart.
  • number-heart-in-heart-custom-color.json uses the HTML color code as the the color of the heart, and in the sample, #FF0000 is set.

screenshot of the sample

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-heart-in-heart.json Tetsuya Kawahara
number-heart-in-heart-custom-color.json Tetsuya Kawahara

Version history

Version Date Comments
1.0 February 13, 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

The SVG heart in this sample is based on a sample from the following site.