Conditional formatting stroke colour of bar chart using Deneb

Hi everyone,

I am trying to create a bar chart with conditional colour formatting for the fill and stroke colours. It works fine for the fill colours but I cannot get it to work for the stroke colours.

In my PBIX file attached, I have the templates (how it should look like but hardcoded) in the top row. For the two rows below I tried two different ways of making the stroke colour of the Target YTD bar change depending on if the actual reaches the target or not. Although it works for changing the bar colour between green and red, my stroke colour always stays green and I cannot figure out why.

Thanks everyone for your help!

Deneb Templates - overlapping bars for target.pbix (1.4 MB)

Hi @fabian

Well, it appears that there’s a behaviour inteaction between corner rounding and stroke colour in Vega-Lite. I was able to get the code to work, but needed to remove the corner rounding from the middle (YTD) bar.

(Same code used for both Deneb visuals.)

As is my practice, the first thing I did with your code was to adjust all of the in-visual fields (transforms and params) to start with an underscore to make it immediately obvious whether I’m using a dataset field or a calculated field. I also simplified the field references in the various corner radius key:value pairs in the first bar (Einde BJ). Finally, to try to isolate the issue, I added calculate transforms for the fill and stroke colours, then modified the middle bar (YTD) to use field references directly. Here’s the relevant code snippets:


      "calculate": "datum['_neg_value'] == true ? '#F8A4A7': '#e6f7ee'",
      "as": "_neg_fill_colour"
      "calculate": "datum['_neg_value'] == true ? '#FB6464' : '#66d096'",
      "as": "_neg_stroke_colour"

Code References:

      "description": "Target (YTD)",
      "mark": {
        "type": "bar",
        "yOffset": -10,
        "fill": {
          "expr": "datum['_neg_fill_colour']"
        "stroke": {
          "expr": "datum['_neg_stroke_colour']"
        "tooltip": true,
        "size": {"expr": "_bar2_height"}
      "encoding": {
        "x": {
          "field": "Target (YTD)",
          "type": "quantitative"
        "tooltip": [
          {"field": "Target (YTD)"}

So, one option is to use something like the above and not use the corner rounding. Then you can add the corner rounding back in and see if you still get what you want.

Hope it helps.
eDNA Forum - Deneb Stroke Colour.pbix (1.4 MB)

1 Like

Hi @Greg,

First of all my apologies for responding that late. I was sick last week and did not find the energy to pursue this.
Thank you so much for all your efforts! The solution you provided is very helpful.
I saw that you indeed modified the coding for the rounded bar shapes. The way I had done it seemed unnecessarily complicated and counter intuitive indeed. But I was intending rounded corners to indicate the direction of my bars. This was the only way I could get it to work that in case my bars represent negative numbers the left side of the bar would be rounded. In the modified version this does not work anymore (look screenshot below for an example). But anyway - I should probably just get rid of all the corner rounding for all bars since I really cannot find out how to implement everything together.

Thanks again for all the help!