Forum Discussion
Deneb: Multi-layer card
- 3 years ago
Hi Salle,
I assume that you want the text to display the mean value? If so, you need to add a text encoding channel property and put the field in there. So, your snippet of JSON that didn't match Vega-Lite's construct for what I think you want to do should look like this:
"encoding": { "text": { "field": "Diameter Mean" }, "x": {"value": 0}, "y": {"value": 10} }My output now looks as follows:
Revised spec:
{ "data": {"name": "dataset"}, "title": "Information", "background": "lightblue", "height": 400, "width": 200, "layer": [ { "mark": { "type": "text", "align": "left", "baseline": "top", "font": "sans-serif", "fontSize": 24, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "text": { "field": "Diameter Mean" }, "x": {"value": 0}, "y": {"value": 10} } }, { "mark": { "text": "Mean", "type": "text", "align": "left", "baseline": "top", "font": "sans-serif", "fontSize": 16, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "x": {"value": 0}, "y": {"value": 30} } }, { "mark": { "text": "Diameter Median", "type": "text", "baseline": "top", "align": "left", "font": "sans-serif", "fontSize": 16, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "x": {"value": 0}, "y": {"value": 80} } }, { "mark": { "text": "Diameter Max", "type": "text", "baseline": "top", "align": "left", "font": "sans-serif", "fontSize": 16, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "x": {"value": 0}, "y": {"value": 130} } } ] }Regards,
Daniel
Thank you dm-p,
for taking the time and provide your input. It never crossed my mind to approach it by the use of bar.
I will try and use and test your input now and likely will have some follow up questions 🙂
Basically I am trying to replica a multi-card I set up in Power BI.
With the following dax measures as inputs.
Each measure with text label I like to be able to pin to a certain individual position e.g. 0, 10; 0, 9 etc.
Note; In a later step I will try to replace the DAX measure input by doing the calculation in Deneb instead; but that will be another topic later...
Hi dm-p , so I realized from your response I did not really need the A and B field at all to position the text labels.
But I ran into problems when I trying to position my Measure "Diameter mean", got specification error message:
"encoding": {
"field": "Diameter Mean",
"x": {"value": 0},
"y": {"value": 10}
}Changing the code a bit I was able to get the measure printed but in wrong position.
I want it to be positioned just above the Mean text label but I guess I am fumbeling with the setup of y-value.
{
"data": {"name": "dataset"},
"title": "Information",
"background": "lightblue",
"height": 400,
"width": 200,
"layer":[
{
"mark": {
"type": "text",
"align": "left",
"baseline": "top",
"font": "sans-serif",
"fontSize": 24,
"dx": 10,
"dy": 0,
"xOffset": 0,
"yOffset": 0
},
"encoding": {
"field": "Diameter Mean",
"x": {"value": 0},
"y": {"value": 10}
}
},
{
"mark": {
"text": "Mean",
"type": "text",
"align": "left",
"baseline": "top",
"font": "sans-serif",
"fontSize": 16,
"dx": 10,
"dy": 0,
"xOffset": 0,
"yOffset": 0
},
"encoding": {
"x": {"value": 0},
"y": {"value": 30}
}
},
{
"mark": {
"text": "Diameter Median",
"type": "text",
"baseline": "top",
"align": "left",
"font": "sans-serif",
"fontSize": 16,
"dx": 10,
"dy": 0,
"xOffset": 0,
"yOffset": 0
},
"encoding": {
"x": {"value": 0},
"y": {"value": 80}
}
},
{
"mark": {
"text": "Diameter Max",
"type": "text",
"baseline": "top",
"align": "left",
"font": "sans-serif",
"fontSize": 16,
"dx": 10,
"dy": 0,
"xOffset": 0,
"yOffset": 0
},
"encoding": {
"x": {"value": 0},
"y": {"value": 130}
}
}
]
}Any help would be appreciated. Thanks in advance!
- dm-p3 years agoSuper User
Hi Salle,
I assume that you want the text to display the mean value? If so, you need to add a text encoding channel property and put the field in there. So, your snippet of JSON that didn't match Vega-Lite's construct for what I think you want to do should look like this:
"encoding": { "text": { "field": "Diameter Mean" }, "x": {"value": 0}, "y": {"value": 10} }My output now looks as follows:
Revised spec:
{ "data": {"name": "dataset"}, "title": "Information", "background": "lightblue", "height": 400, "width": 200, "layer": [ { "mark": { "type": "text", "align": "left", "baseline": "top", "font": "sans-serif", "fontSize": 24, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "text": { "field": "Diameter Mean" }, "x": {"value": 0}, "y": {"value": 10} } }, { "mark": { "text": "Mean", "type": "text", "align": "left", "baseline": "top", "font": "sans-serif", "fontSize": 16, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "x": {"value": 0}, "y": {"value": 30} } }, { "mark": { "text": "Diameter Median", "type": "text", "baseline": "top", "align": "left", "font": "sans-serif", "fontSize": 16, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "x": {"value": 0}, "y": {"value": 80} } }, { "mark": { "text": "Diameter Max", "type": "text", "baseline": "top", "align": "left", "font": "sans-serif", "fontSize": 16, "dx": 10, "dy": 0, "xOffset": 0, "yOffset": 0 }, "encoding": { "x": {"value": 0}, "y": {"value": 130} } } ] }Regards,
Daniel
- dm-p3 years agoSuper User
Hi Salle,
This may be jumping ahead of your learning journey, but possibly something for you to think about to avoid too much repetition.
If you're just adding measures and your dataset is effectively one row, you can use a fold transform (which is the same as an unpivot in Power Query) and specify your measure names, to get a simpler list of name/value pairs that you can encode just using two marks.
So, if my dataset looks like this...
I can add the following transform...
"transform": [ { "fold": [ "Diameter Mean", "Diameter Median", "Diameter Max" ], "as": ["measure", "value"] } ],...and the resulting dataset (now named as data_0 by Vega-Lite) will look like this:
You'll notice that this is now 3 rows, with additional measure and value columns. You'll get as many rows as entries you specify in the fold operation (as long as they are in your dataset).
The plan here is that I can encode the y channel to measure, which will position vertically by this field, and then I can add a text mark that encodes the text channel to the value column, and another that encodes text to the measure column.
Here's what this spec might look like as a whole:
{ "data": {"name": "dataset"}, "title": "Information", "background": "lightblue", "transform": [ { "fold": [ "Diameter Mean", "Diameter Median", "Diameter Max" ], "as": ["measure", "value"] } ], "encoding": { "y": { "field": "measure", "axis": null } }, "layer": [ { "mark": { "type": "text", "align": "left", "baseline": "bottom", "fontSize": 24 }, "encoding": { "text": {"field": "value"} } }, { "mark": { "type": "text", "align": "left", "baseline": "top", "fontSize": 16 }, "encoding": { "text": {"field": "measure"} } } ] }And here's the output:
Hopefully this might help you reduce the amount of maintenance you could potentially have with this one. Good luck!
Daniel
EDIT: if you want the y-encoding to sort in the order you type the measures in the fold transform, just add "sort": null to enforce this order (ref). The y-encoding from above would now look as follows:
"encoding": { "y": { "field": "measure", "axis": null, "sort": null } },- Salle3 years agoAdvocate I
dm-p:
Daniel, thank you for all the time and effort you put in to guide me through some of the basic elements in Deneb! I really appreciate all the support and tips!
I will certainly look into your suggestion with using fold, I did not know it existed.
But I am starting to learn that anything is possible with Deneb 😉
Cheers/Carl