Preassigned colors for multiple line charts
See original GitHub issueI would like to set the color for each of the chart externally.
I try to do make a scale which is array of available colors like :
{
"name": "color",
"type": "ordinal",
"range": [
'#84C9CB',
'#8A3EC3',
'#C3587E',
'#097D8A',
'#98F76D',
'#54AD38',
'#EC1055'
]
}
then in marks, I have set it as :
"marks": [
{
"type": "group",
"clip": true,
"from": {
"facet": {
"name": "series",
"data": "table",
"groupby": "PointId"
}
},
"marks": [
{
"type": "line",
"from": {"data": "series"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "TimeStamp"},
"y": {"scale": "yscale", "field": "Value"},
"stroke": {"scale": "PointId", "field": "PointId"},
"strokeWidth": {"value": 2}
},
"update": {
"x": {"scale": "xscale", "field": "TimeStamp"},
"y": {"scale": "yscale", "field": "Value"},
"strokeWidth": {"value": 2},
"stroke": {"signal": "colorupdate"}
},
"select": {
"strokeWidth": {
"value": 3
}
},
"hover": {
"fillOpacity": {"value": 0.5}
}
}
}
]
}
]
Stroke value points to the signal:
{
"name": "colorupdate",
"update": "scale('color', 'PointId % 6')" // point id is id of the group and 6 is length of color array. There should be better way for array.length in Vega but again I am no expert in Vega.
},
This same formula is used externally for items selected for chart: 'color = [‘PointId’] % color.length
For some reason, and I am no expert in Vega, same color shows for all charts…
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to Choose Colors for Data Visualizations
If you have a dashboard or report that includes multiple charts, it is a good idea to match colors between charts when they...
Read more >Excel Multi-colored Line Charts
The chart below contains 3 lines; red, yellow and green. They are sitting on top of one another to give the appearance of...
Read more >Vary the colors of same-series data markers in a chart
Set varying colors of data markers (bars, columns, lines, pie or doughnut slices, dots, and other shapes) automatically in an Office chart.
Read more >matlab color code
Matlab Color CodeSet color order for visualizing - MATLAB …. Specify Color of a Bar Chart Copy Command Create a red bar chart...
Read more >Multi-colored Excel Line Charts - YouTube
3 easy ways to create multi- colored Excel Line charts. Download the Excel file here: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

If you need to debug a signal expression, you can use the
warnfunction to print debugging output to the browser’s JavaScript console. For more, see the documentation at https://vega.github.io/vega/docs/expressions/#warnHi!
'PointId % 6'is a string, so you are always applying your color scale to a string constant. Also, signals compute values, not functions, so referencing"colorupdate"in your encoder will only provide a constant.Try using the following for your stroke color encoder. The contained expression will then get evaluated for each data point being visualized.
p.s. There is also a
length(array)function for getting the length of an array. For examplelength(range('color')). All expression functions are documented here: https://vega.github.io/vega/docs/expressions/