Back to view formats
View formattingSharePoint Online

Weather forecast

This sample transforms list items into cards formatted with weather forecast layouts.

Weather forecast 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.

View formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/view-formatting.schema.json",
  "hideSelection": true,
  "hideColumnHeader": true,
  "rowFormatter": {
    "elmType": "div",
    "style": {
      "font-family": "Arial, sans-serif",
      "padding": "20px",
      "background-color": "#f0f0f0",
      "border-radius": "10px",
      "box-shadow": "0 2px 5px rgba(0,0,0,0.1)",
      "max-width": "400px",
      "margin": "0 auto"
    },
    "children": [
      {
        "elmType": "div",
        "style": {
          "background-color": "white",
          "border-radius": "10px",
          "width": "800px",
          "padding": "20px",
          "box-shadow": "0 2px 5px rgba(0,0,0,0.1)",
          "display": "flex",
          "flex-direction": "column"
        },
        "children": [
          {
            "elmType": "div",
            "style": {
              "display": "flex",
              "flex-direction": "column",
              "align-items": "center",
              "justify-content": "space-between",
              "margin-bottom": "10px"
            },
            "children": [
              {
                "elmType": "div",
                "style": {
                  "margin-bottom": "10px",
                  "font-size": "18px",
                  "font-weight": "normal"
                },
                "txtContent": "[$Title]"
              },
              {
                "elmType": "div",
                "style": {
                  "margin-bottom": "10px",
                  "font-size": "24px",
                  "font-weight": "bold"
                },
                "txtContent": "[$Location]"
              }
            ]
          },
          {
            "elmType": "div",
            "style": {
              "display": "flex",
              "align-items": "center",
              "justify-content": "space-between",
              "margin-bottom": "10px"
            },
            "children": [
              {
                "elmType": "div",
                "style": {
                  "font-size": "48px",
                  "font-weight": "bold"
                },
                "txtContent": "=[$Temperature] + '°'"
              },
              {
                "elmType": "div",
                "style": {
                  "font-size": "36px"
                },
                "attributes": {
                  "iconName": "=if([$Weather] == 'Sunny', 'Sunny', if([$Weather] == 'Cloudy', 'PartlyCloudyDay', if([$Weather] == 'Rainy', 'Rain', if([$Weather] == 'Snowy', 'Snowflake', ''))))"
                }
              },
              {
                "elmType": "div",
                "style": {
                  "text-align": "right",
                  "font-size": "14px"
                },
                "children": [
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "margin-bottom": "5px",
                      "display": "flex",
                      "flex-direction": "row"
                    },
                    "children": [
                      {
                        "elmType": "span",
                        "style": {
                          "font-size": "14px",
                          "font-weight": "bold"
                        },
                        "attributes": {
                          "iconName": "Rain"
                        }
                      },
                      {
                        "elmType": "span",
                        "style": {
                          "font-size": "14px",
                          "padding-left": "5px"
                        },
                        "txtContent": "=[$Rain] + '%'"
                      }
                    ]
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "margin-bottom": "5px",
                      "display": "flex",
                      "flex-direction": "row"
                    },
                    "children": [
                      {
                        "elmType": "span",
                        "style": {
                          "font-size": "14px",
                          "font-weight": "bold"
                        },
                        "attributes": {
                          "iconName": "ArrowUpRight8"
                        }
                      },
                      {
                        "elmType": "span",
                        "style": {
                          "font-size": "14px",
                          "padding-left": "5px"
                        },
                        "txtContent": "[$Wind]"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "elmType": "div",
            "style": {
              "font-size": "14px",
              "margin-bottom": "20px"
            },
            "txtContent": "[$Description]"
          },
          {
            "elmType": "div",
            "style": {
              "display": "grid",
              "grid-template-columns": "1fr 1fr",
              "gap": "10px",
              "border-top": "1px solid #e0e0e0",
              "padding-top": "10px"
            },
            "children": [
              {
                "elmType": "div",
                "style": {
                  "display": "flex",
                  "align-items": "center",
                  "padding": "10px"
                },
                "children": [
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "20px",
                      "margin-right": "10px"
                    },
                    "attributes": {
                      "iconName": "Drop"
                    }
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "color": "#666",
                      "flex-grow": "1"
                    },
                    "txtContent": "Humidity"
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "font-weight": "bold"
                    },
                    "txtContent": "=[$Humidity] + '%'"
                  }
                ]
              },
              {
                "elmType": "div",
                "style": {
                  "display": "flex",
                  "align-items": "center",
                  "padding": "10px"
                },
                "children": [
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "20px",
                      "margin-right": "10px"
                    },
                    "attributes": {
                      "iconName": "Sunny"
                    }
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "color": "#666",
                      "flex-grow": "1"
                    },
                    "txtContent": "UV Index"
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "font-weight": "bold"
                    },
                    "txtContent": "[$UVIndex]"
                  }
                ]
              },
              {
                "elmType": "div",
                "style": {
                  "display": "flex",
                  "align-items": "center",
                  "padding": "10px"
                },
                "children": [
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "20px",
                      "margin-right": "10px"
                    },
                    "attributes": {
                      "iconName": "12PointStar"
                    }
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "color": "#666",
                      "flex-grow": "1"
                    },
                    "txtContent": "Sunrise"
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "font-weight": "bold"
                    },
                    "txtContent": "[$Sunrise]"
                  }
                ]
              },
              {
                "elmType": "div",
                "style": {
                  "display": "flex",
                  "align-items": "center",
                  "padding": "10px"
                },
                "children": [
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "20px",
                      "margin-right": "10px"
                    },
                    "attributes": {
                      "iconName": "ClearNight"
                    }
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "color": "#666",
                      "flex-grow": "1"
                    },
                    "txtContent": "Sunset"
                  },
                  {
                    "elmType": "div",
                    "style": {
                      "font-size": "14px",
                      "font-weight": "bold"
                    },
                    "txtContent": "[$Sunset]"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

From the contributor

How to use this sample

Summary

This sample transforms list items into cards formatted with weather forecast layouts. To ensure the view functions correctly, make sure all specified columns are included. The icons are referenced from Fluent UI Icons.

screenshot of the sample

View requirements

Column Name Type
Title Single line of text
Location Single line of text
Temperature Number
Weather Choice (Sunny,Cloudy,Rainy,Snowy)
Wind Single line of text
Humidity Number
UVIndex Single line of text
Sunrise Single line of text
Sunset Single line of text
Rain Number

Sample

Solution Author(s)
weather-forecast.json Sudeep Ghatak

Version history

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

None