jsonvisualizationvega-litevegavega-lite-api

legend color according to a specific field and legend label on the other field in vega lite


I am creating a horizontal stack bar chart and want to add legend , but i want legend color on the basis of field are define in my data(i.e color_name) in each data element data formata

i want legend use my color field and also show legend label on the basis of different field i.e "occuring_event" . how it is possible what are modification in data set require to achieve this.

i just used scale range in specs as but not look same as i want scale range use plz check in editor


Solution

  • There is an example in the docs you can use as a guide:

    https://vega.github.io/vega-lite/docs/scale.html#example-setting-color-range-based-on-a-field

    enter image description here