Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I have a Deneb question, is it possible using Vega-Lite to create a small multiple visual which will dynamical change the size of the multiples so it will all fit on one page and avoid the need of scrolling etc.
So wether there was say 5 products to show in the small multiples, or 15, each facet will dynamically change size depending on the number of products so it fits within the container of the page?
Thanks in advance.
Solved! Go to Solution.
Yes, it is possible to create a small multiple visual using Vega-Lite that dynamically adjusts the size of the multiples to fit on one page without the need for scrolling.
One way to achieve this is to use the `repeat` operator in Vega-Lite to create a grid of facets, where the number of rows and columns are determined dynamically based on the number of products being shown.
Here's an example Vega-Lite specification that demonstrates this:
```
{
"repeat": {"row": "product", "column": "year"},
"spec": {
"mark": "line",
"encoding": {
"x": {"field": "month", "type": "ordinal"},
"y": {"field": "sales", "type": "quantitative"}
}
},
"data": {
"values": [
{"product": "A", "year": 2020, "month": "Jan", "sales": 100},
{"product": "A", "year": 2020, "month": "Feb", "sales": 120},
{"product": "A", "year": 2020, "month": "Mar", "sales": 140},
{"product": "B", "year": 2020, "month": "Jan", "sales": 80},
{"product": "B", "year": 2020, "month": "Feb", "sales": 90},
{"product": "B", "year": 2020, "month": "Mar", "sales": 100},
{"product": "A", "year": 2021, "month": "Jan", "sales": 110},
{"product": "A", "year": 2021, "month": "Feb", "sales": 130},
{"product": "A", "year": 2021, "month": "Mar", "sales": 150},
{"product": "B", "year": 2021, "month": "Jan", "sales": 90},
{"product": "B", "year": 2021, "month": "Feb", "sales": 100},
{"product": "B", "year": 2021, "month": "Mar", "sales": 110}
]
},
"config": {
"view": {"stroke": "transparent"},
"axis": {"grid": false},
"scale": {"rangeStep": 20},
"facet": {"spacing": {"row": 10, "column": 10}}
}
}
```
In this example, the `repeat` operator is used to create a grid of facets based on the "product" and "year" fields. The `spec` property contains the visualization specification for each individual facet, which in this case is a line chart showing sales over time.
The `config` property is used to configure the layout and spacing of the facets. The `view` property sets the stroke to transparent to remove the border around each facet. The `axis` property sets the grid to false to remove the axis lines between the facets. The `scale` property sets the rangeStep to 20, which controls the size of the facets. The `facet` property sets the spacing between the facets in both the row and column directions.
With this approach, the size of the facets will dynamically adjust based on the number of products being shown, allowing all the facets to fit on one page without the need for scrolling.
Yes, it is possible to create a small multiple visual using Vega-Lite that dynamically adjusts the size of the multiples to fit on one page without the need for scrolling.
One way to achieve this is to use the `repeat` operator in Vega-Lite to create a grid of facets, where the number of rows and columns are determined dynamically based on the number of products being shown.
Here's an example Vega-Lite specification that demonstrates this:
```
{
"repeat": {"row": "product", "column": "year"},
"spec": {
"mark": "line",
"encoding": {
"x": {"field": "month", "type": "ordinal"},
"y": {"field": "sales", "type": "quantitative"}
}
},
"data": {
"values": [
{"product": "A", "year": 2020, "month": "Jan", "sales": 100},
{"product": "A", "year": 2020, "month": "Feb", "sales": 120},
{"product": "A", "year": 2020, "month": "Mar", "sales": 140},
{"product": "B", "year": 2020, "month": "Jan", "sales": 80},
{"product": "B", "year": 2020, "month": "Feb", "sales": 90},
{"product": "B", "year": 2020, "month": "Mar", "sales": 100},
{"product": "A", "year": 2021, "month": "Jan", "sales": 110},
{"product": "A", "year": 2021, "month": "Feb", "sales": 130},
{"product": "A", "year": 2021, "month": "Mar", "sales": 150},
{"product": "B", "year": 2021, "month": "Jan", "sales": 90},
{"product": "B", "year": 2021, "month": "Feb", "sales": 100},
{"product": "B", "year": 2021, "month": "Mar", "sales": 110}
]
},
"config": {
"view": {"stroke": "transparent"},
"axis": {"grid": false},
"scale": {"rangeStep": 20},
"facet": {"spacing": {"row": 10, "column": 10}}
}
}
```
In this example, the `repeat` operator is used to create a grid of facets based on the "product" and "year" fields. The `spec` property contains the visualization specification for each individual facet, which in this case is a line chart showing sales over time.
The `config` property is used to configure the layout and spacing of the facets. The `view` property sets the stroke to transparent to remove the border around each facet. The `axis` property sets the grid to false to remove the axis lines between the facets. The `scale` property sets the rangeStep to 20, which controls the size of the facets. The `facet` property sets the spacing between the facets in both the row and column directions.
With this approach, the size of the facets will dynamically adjust based on the number of products being shown, allowing all the facets to fit on one page without the need for scrolling.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
92 | |
86 | |
85 | |
66 | |
49 |
User | Count |
---|---|
140 | |
113 | |
104 | |
64 | |
60 |