[Doc] Update Bar Chart Hightlighted Segment: 2 Thresholds#3227
[Doc] Update Bar Chart Hightlighted Segment: 2 Thresholds#3227ChiaLingWeng wants to merge 3 commits intovega:mainfrom
Conversation
|
Thank you for pushing this @ChiaLingWeng! I tried to add my commit as a suggestion, but that was not allowed since the change covered deleted lines. With this suggestion we do not need the Explaining the change, instead of doing this: highlight = alt.Chart(source).mark_bar(color="#5BA3CF").encode(
x='year:O',
y='baseline:Q',
y2='wheat:Q'
).transform_filter(
alt.datum.wheat > 20
).transform_calculate(
"baseline", "20"
)We can write it as such: highlight = alt.Chart(source).mark_bar(color="#5BA3CF").encode(
x='year:O',
y='wheat:Q',
y2=alt.datum(20)
).transform_filter(
alt.datum.wheat > 20
)Observe using Thinking more, we might be able to use a layer-repeat operator here. alt.Chart(source, width=600).mark_bar().encode(
x='year:O',
y='wheat:Q',
y2=alt.Y2Datum(alt.repeat('layer')),
color=alt.ColorDatum(alt.repeat('layer'))
).repeat(layer=['0','20', '60'])But adding a repeat operator to a filter transform does not work alt.Chart(source, width=600).mark_bar().encode(
x='year:O',
y='wheat:Q',
y2=alt.Y2Datum(alt.repeat('layer')),
color=alt.ColorDatum(alt.repeat('layer'))
).transform_filter(
alt.FieldGTPredicate(field='wheat', gt=alt.repeat('layer'))
).repeat(layer=['0','20', '60'])
See also vega/vega-lite#7398. The expecting VL-spec should look as such Open the Chart in the Vega Editor |
|
Thanks for your feedback @mattijn ! |
|
Close it since the issue solved. |

This will close #2996 and related to #1109

Add another highlighted sections and label text to show more flexibility
One thing need to be improved is to use variable instead of key-in value in
transform_filter()andtransform_calculate().Use for loop like #1109 (comment) may help, but not sure if it is clear enough