Forum Discussion
Creating a striped bar chart
- 3 years ago
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
- 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
- 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
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?
- dm-p3 years agoSuper User
- PWRBI_USER13 years agoHelper I
Hi Daniel dm-p
I have an additional question. In the pie chart, is there any option to do stripe'ing based on a condition? I tried the same way I did in the bar. But somehow does not give me a luck.
Thanks for all the help.
- PWRBI_USER3 years agoFrequent Visitor
Hello Daniel dm-p ,
Thank you for the guidance. I would like to check whether we can do striped sections in the pie charts. I tried the same but did not get a luck.