Vega Lite
What Property Types Does Vega-Lite Accept?

Hey there! 👋 Are you curious about the various property types you can use in Vega-Lite to create stunning data visualizations? Well, you're in the right place! Let’s break it down so you can master these property types with ease.

Primitive Types

What is the "Any" type?

The "Any" type is super flexible—it can accept any literal value you throw at it! Whether it's a string, number, boolean, or even null, this type has got you covered.

How to Use Arrays in Vega-Lite?

Arrays allow you to group multiple values together. For instance:

  • An empty array: []
  • An array of numbers: [1, 2, 3]
  • An array of strings: ["foo", "bar"]

Sometimes, items in arrays need to follow a specific type, like Number[] or String[]. You can also include signal references as items: [{"signal": "width"}, {"signal": "height"}].

What Can I Do with Booleans?

Booleans are straightforward. They can only be true or false. Simple!

How to Define Colors?

You can use any valid CSS color string (opens in a new tab) to define colors. For example:

  • Hex color: #f304d3
  • Short hex: #ccc
  • RGB color: rgb(253, 12, 134)
  • Basic color name: steelblue

What is an Expression Reference (ExprRef)?

This involves setting an object with an expr property that defines a Vega Expression. For instance, you can set mark color to {expr: "lab(50,10,30)"}.

How to Write Expressions?

Vega-Lite supports custom calculations through Vega's expression language. You can refer to each datum object using the variable datum. More details are available in the Vega documentation for expressions (opens in a new tab).

How to Use Numbers?

Numbers are pretty intuitive. You can use integers, floats, or scientific notation:

  • Integer: 1
  • Float: 3.14
  • Scientific notation: 1e5

How to Work with Objects?

Objects accept general object literals. An example would be:

{"left":5, "right":30, "top":5, "bottom":50}

Check the individual property descriptions for what each key and value should be.

How to Use Strings?

Strings can be any sequence of characters. Here are some examples:

  • "bold"
  • "step-before"
  • "" (an empty string)

Any Tips for Text?

Text accepts both single strings and arrays of strings for multi-line text. Need multi-line text? Just use an array!

How to Specify URLs?

URLs should be valid strings linking to external resources. Example URLs:

  • "data/stocks.csv"
  • "images/logo.png"
  • "https://vega.github.io/"

Special Object Types

Don't miss these specialized types! Check out:

FAQs

What is the "Any" type used for?

The "Any" type is very versatile and can accept any valid value, making it useful for properties that can be dynamic or vary greatly.

Can I mix numbers and strings in the same array?

While Vega-Lite allows arrays, the items often need to adhere to a specific type. Mixing types in an array is not common practice and may not be supported.

How do I use Vega-Lite expressions?

Expressions allow custom calculations within your visualizations. You write them using Vega's expression language, referring to data fields with the datum variable.

And there you have it! With these property types and examples, you're well on your way to creating amazing visualizations with Vega-Lite. Happy visualizing! 🎨📊