Forum Discussion

PWRBI_USER's avatar
PWRBI_USER
Frequent Visitor
3 years ago
Solved

Creating a striped bar chart

Hi,

  I would like to check whether it is possible to create a striped bar chart (Chart with inclined bars inside).

My exact requirement is that if data matches with a condition, I need to show striped bar. Else regular bar.

 

Thanks,

 

  • There will be some learning curve, but pattern fills are possible with the Deneb custom visual (which leverages Vega-Lite). You could create a measure that returns 0 or 1 depending on your criterion, and then conditionally set the pattern to striped or solid.

     

    Pattern Fills | Deneb (deneb-viz.github.io)

     

    Pat

     

  • dm-p's avatar
    dm-p
    3 years ago

    Hi PWRBI_USER1 - for Vega-Lite, conditions are only possible to use in encoding channels, and not mark properties.

    If you want to do this in the mark property, then the fill property can use an ExprRef. This uses the Vega expression language, which is detailed here.

    It's not entirely clear from your example what the condition is, or the name of the fields in your dataset, so I'll use a simple bar chart, where I will fill the bar based on my Country field: if it matches 'Australia', I'll apply the pattern fill, otherwise I'll colour the bar black. 

    {
      ...
      "mark": {
        "type": "bar",
        "stroke": "black",
        "fill": {
          "expr": "if(datum['Country'] == 'Australia', 'url(#diagonal-stripe-1)', 'black')"
        }
      },
      ...
    }

    Regards,

    Daniel

7 Replies

  • ppm1's avatar
    ppm1
    Solution Sage

    There will be some learning curve, but pattern fills are possible with the Deneb custom visual (which leverages Vega-Lite). You could create a measure that returns 0 or 1 depending on your criterion, and then conditionally set the pattern to striped or solid.

     

    Pattern Fills | Deneb (deneb-viz.github.io)

     

    Pat

     

  • Hello Pat ppm1 ,

      Thank you for your inputs. That was big help.

    An additional question. As I am a newbie into Vegalite, I am getting an error when I give the condition. With the plain fill (without condition) it is working. Any inputs is highly appreciated.

     

     

    • dm-p's avatar
      dm-p
      Super User

      Hi PWRBI_USER1 - for Vega-Lite, conditions are only possible to use in encoding channels, and not mark properties.

      If you want to do this in the mark property, then the fill property can use an ExprRef. This uses the Vega expression language, which is detailed here.

      It's not entirely clear from your example what the condition is, or the name of the fields in your dataset, so I'll use a simple bar chart, where I will fill the bar based on my Country field: if it matches 'Australia', I'll apply the pattern fill, otherwise I'll colour the bar black. 

      {
        ...
        "mark": {
          "type": "bar",
          "stroke": "black",
          "fill": {
            "expr": "if(datum['Country'] == 'Australia', 'url(#diagonal-stripe-1)', 'black')"
          }
        },
        ...
      }

      Regards,

      Daniel

      • PWRBI_USER's avatar
        PWRBI_USER
        Frequent Visitor

        Thank you so much Daniel dm-p . I added in encoding but your inputs helped.

        One additional question. Can I create pie chart as well through Deneb?