{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"title": {
"text": "Residual Value Trend",
"fontSize": 20,
"anchor": "start",
"color": "#243781",
"offset": 15,
"font": "calibri"
},
"description": "Linechart with Country and Car Models",
"data": {
"name": "dataset"
},
"transform": [
{
"calculate": " datum.RV < 100 ? datum.Rv + '%' : datum.RV >= 1000 ? format(datum.Rv,','):datum.Rv",
"as": "Rv"
}
],
"encoding": {
"detail": {
"field": "Model-Fuel",
"type": "nominal"
},
"color": {
"field": "CD_ENERGY_CODE",
"type": "nominal",
"sort": {
"field": "CD_ENERGY_CODE",
"order": "ascending"
},
"scale":{
"domain":{
"data": "dataset",
"field": "CD_ENERGY_CODE"
},
"range":{
"data":"dataset",
"field": "ENERGY_COLOR"
}
},
"legend": {
"title": null,
"labelFontSize": 16,
"labelFont": "calibri"
}
},
"x": {
"field": "Visual Date",
"type": "nominal",
"axis": {
"labelFontSize": 16,
"title": null,
"labelAngle": 0,
"labelColor": "#243781",
"tickColor": "transparent",
"domainColor": "transparent",
"labelFont": "calibri"
}
},
"y": {
"field": "RV %/RV €",
"type": "quantitative",
"axis": {
"labelFontSize": 16,
"grid": false,
"title": null,
"labelColor": "#243781",
"tickColor": "transparent",
"domainColor": "transparent",
"labelFont": "calibri"
},
"scale": {
"zero": false
}
}
},
"layer": [
{
"mark": {
"type": "line",
"strokeWidth": 4
},
"encoding": {
"detail": {
"field": "Model-Fuel",
"type": "nominal"
}
}
},
{
"mark": {
"type": "point",
"filled": true,
"size": 60
},
"encoding": {
"tooltip": [
{
"field": "Model-Fuel",
"type": "nominal"
},
{
"field": "Rv",
"type": "nominal"
}
]
}
}
]
}
That’s the code I’m using right now,
X axis are quantitative values
Y axis a date expressed in quarter “Es 2021 Q1”
The lines connecting the points are different veichles and I want to color them based on a table containing :
In the first column the type of fuel
In the second column the color associated to the fuel
The table with the colors is linked with the fact table with the type of the fuel column ,
When I try to plot the line chart without selecting a specific fuel type from a slicer the colors shuffle between themselves, if I select only one it works , if I select more then one they start to shuffle again. That’s my problem.
Also I’m having the same problem on another visual with the same “mechanic”
I think I tried everything
Thanks in advance