cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
PWRBI_USER
Frequent Visitor

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,

 

3 ACCEPTED SOLUTIONS
ppm1
Solution Sage
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

 

Microsoft Employee

View solution in original post

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')"
    }
  },
  ...
}

dmp_1-1665355552758.png

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

Hi @PWRBI_USER - you can use the arc mark for pie charts in Vega-Lite.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

7 REPLIES 7
PWRBI_USER1
Helper I
Helper I

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.

 

PWRBI_USER1_0-1665152138412.png

 

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')"
    }
  },
  ...
}

dmp_1-1665355552758.png

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




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?

Hi @PWRBI_USER - you can use the arc mark for pie charts in Vega-Lite.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




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.

 

PWRBI_USER_0-1665487336487.png

 

 

 

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_USER1_0-1665476832804.png

 

ppm1
Solution Sage
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

 

Microsoft Employee

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors