Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
asodie
Helper I
Helper I

Deneb Vega-lite: Add label to reference line for today's date

I have a timeline bubble chart (shown with dummy data) with a reference line for the current date. 
 
asodie_3-1692211533616.png

 

I want to add a label for the reference line that just says "today's date". When I try to add one it adds a label with today's date to every bubble. I would like a label for the reference line on top where it would be readable.

Here is my code:

 

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"name": "dataset"},
  "width": 950,
  "height": 400,
  "transform": [
    {
      "calculate": "now()",
      "as": "today"
    }
  ],
  "encoding": {
    "x": {
      "field": "Date",
      "type": "temporal",
      "axis": {
        "grid": false,
        "format": "Q%q %Y"
      }
    },
    "y": {
      "field": "Prob",
      "type": "quantitative"
    }
  },
  "layer": [
    {
      "mark": {
        "type": "circle",
        "opacity": 0.8,
        "stroke": "black",
        "strokeWidth": 1
      },
      "encoding": {
        "size": {
          "field": "Amount",
          "type": "quantitative"
        },
        "color": {
          "field": "Group",
          "type": "nominal"
        }
      }
    },
    {
      "mark": {
        "type": "circle",
        "opacity": 0.8,
        "stroke": "black",
        "strokeWidth": 1
      },
      "encoding": {
        "size": {
          "field": "Amount",
          "type": "quantitative",
          "scale": {"rangeMax": 1000}
        },
        "color": {
          "field": "Group",
          "type": "nominal"
        }
      }
    },
    {
      "mark": {
        "type": "rule",
        "opacity": 0.6
      },
      "encoding": {
        "x": {
          "field": "today",
          "type": "temporal"
        },
        "size": {"value": 1},
        "color": {"value": "grey"}
      }
    }
  ]
}

 

1 REPLY 1
asodie
Helper I
Helper I

Answering my own question:

 

I created another layer inside the original layers that contained just the reference line and text mark for todays date. This is my code for the text mark:

 

{
          "mark": {
            "type": "text",
            "align": "left",
            "baseline": "bottom",
            "dx":-15
          },
          "encoding": {
            "text": {"value": "Today"},
            "x": {
              "field": "today",
              "type": "temporal"
            },
            "y": {"value": 0}
          }
        }

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.