question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create dashed line based on condition

See original GitHub issue

Hey, folks!

Is there a way to use conditions do change the strokeDash on a line chart?

I have a dataframe w/ some projections for 2020, including (1) a baseline scenario and (2) several other stressed scenarios. I’d like to plot them on a single chart (that is, one line per scenario), and highlight the baseline one by making it dashed. Is it possible?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
joelostblomcommented, Mar 27, 2021

@ethanabrooks You can see an example of the syntax vega-lite required for multiple comparison at the end of this page in the docs. For altair to create the same expression you need to use (alt.datum.symbol == 'GOOG') | (alt.datum.symbol == 'AMZN') as the condition. You could also manually type out the comparison dictionary instead of using alt.condition to generate it as shown here.

0reactions
ethanabrookscommented, Mar 26, 2021

I’m just curious (and I can start a new issue if you prefer) but how would you get two lines to show up dashed? When I use

alt.Chart(source).mark_line().encode(
    x='date',
    y='price',
    color='symbol',
    strokeDash=alt.condition(
        alt.datum.symbol == 'GOOG' or alt.datum.symbol == 'AMZN',
        alt.value([5, 5]),  # dashed line: 5 pixels  dash + 5 pixels space
        alt.value([0]),  # solid line
    )
)

Only GOOG gets the dash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

matplotlib - dashed line between points if one condition is met
I am using matplotlib to draw a plot.
Read more >
How to create a conditional dashed line? - Qlik Community
I want the line to change to a dashed line when it becomes budgetted data. I can't find what the code is for...
Read more >
How to Add Dotted Lines to Line Graphs in Microsoft Excel
Click Twice to Edit Pieces of the Line​​ You would click on the dot in this screenshot, for example, to edit just the...
Read more >
How to plot a dashed line in matplotlib? - GeeksforGeeks
To plot the dashed line we will create the dataset and then we use the above syntax to plot dashed datapoints.
Read more >
Chart with Actual Solid Lines and Projected Dashed Lines
This tutorial shows how to create a chart with actual and projected data, with actual data formatted with a solid line and projected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found