Sample: Circle in a circle

After seeing this tweet from Ruth Pozuelo, I was triggered to see if we can do something similar with column format.
As it turned out it wasn’t even that hard although I must admit that this was my first try of drawing anything in SVG. So I spend way too much time on the understanding of drawing a circle 😂.

And here is the code, it can be used on any number column displaying percentages.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
    "style": {
    "display": "flex",
    "padding": "4px",
    "align-items": "center"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "inline-block",
        "border-radius": "100%",
        "fill": "currentColor",
        "width": "100px",
        "height": "100px"
      },
      "attributes": {
        "class": "ms-bgColor-themeLight ms-fontColor-themePrimary"
      },
      "children": [
        {
          "elmType": "svg",
          "children": [
            {
              "elmType": "path",
              "attributes": {
                "d": "='M 0,50' + 'a '+ pow(50*@currentField,0.5) + ','+pow(50*@currentField,0.5) + ' 0 1,1 ' + 100*pow(@currentField,0.5) +',0' + 'a '+ pow(50*@currentField,0.5) + ','+pow(50*@currentField,0.5) + ' 0 1,1 ' + -100*pow(@currentField,0.5) +',0' "
              }
            }
          ]
        }
      ]
    },
    {
      "elmType": "div",
      "txtContent" : "@currentField.displayValue",
      "style": {
        "position" : "absolute",
        "z-index" : "10",
        "left" : "45px",
        "width" :"40px",
        "text-align" : "center",
        "white-space" :"nowrap",
        "border-radius" : "0.2em"

      },
      "attributes": {
        "class" :"ms-bgColor-white ms-fontColor-themeDarker"
      }

    }
  ]
}

Leave a Reply

Your email address will not be published. Required fields are marked *