cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nailazubair
Helper II
Helper II

Limit data label in Deneb

Hi Team,

 

I have started working and exploring Deneb and I got a Gantt chart. I want to limit the width of data label like it should restrict the data lable to the size of the bar and it should not cross the range of the data bar like in the below snapshot. I am attaching the pbix file. Can anyone please check and play around a bit to see if I can adjust the data labels?

 

nailazubair_0-1679275765459.png

 

Link of the PBIX file:

https://drive.google.com/file/d/1gTyasUwTIVfGqbkrfCEpdsahH5Uauwj-/view?usp=share_link

 

 

1 ACCEPTED SOLUTION
giammariam
Impactful Individual
Impactful Individual

Hey @nailazubair, I didn't end up needing to change the font. I forgot that there is a property called limit that will truncate the text to fit within a certain width. The challenge was knowing the bar width at the time of the rendering the text without creating a cycle in the dataflow graph.

giammariam_0-1679340331034.png

I essentially wanted to use the x scale, but couldn't because it was creating a circular reference. 

 

The workaround that I went with was to implement vertical concatenation and have the first "chart" render nothing. What this first chart does do though is create a identical x scale to the one used for the bars and text. This scale is then later used to determine the bar widths without creating a cycle in the dataflow graph. So this first x scale is called concat_0_x and the second one used to render the bars and text is called concat_1_x. I determine the bar widths via transforms:

"transform": [
        {
          "calculate": "scale('concat_0_x', datum['StartDate'])",
          "as": "bar_x"
        },
        {
          "calculate": "scale('concat_0_x', datum['EndDate2'])",
          "as": "bar_x2"
        },
        {
          "calculate": "datum['bar_x2']-datum['bar_x']-(2*text_horizontal_padding)",
          "as": "bar_width"
        }
      ],

I also gave it a little bit of padding so the text wouldn't be right up against the bar edges.

 

result:

giammariam_1-1679344643283.jpeg

 

Here is the .pbix.

 

If this is enough to get you going please consider liking this reply and choosing it as the solution. Otherwise, I'm happy to help further.

 



Madison Giammaria
Super User In Training‌ 😄
LinkedIn

View solution in original post

5 REPLIES 5
giammariam
Impactful Individual
Impactful Individual

Hey @nailazubair, I didn't end up needing to change the font. I forgot that there is a property called limit that will truncate the text to fit within a certain width. The challenge was knowing the bar width at the time of the rendering the text without creating a cycle in the dataflow graph.

giammariam_0-1679340331034.png

I essentially wanted to use the x scale, but couldn't because it was creating a circular reference. 

 

The workaround that I went with was to implement vertical concatenation and have the first "chart" render nothing. What this first chart does do though is create a identical x scale to the one used for the bars and text. This scale is then later used to determine the bar widths without creating a cycle in the dataflow graph. So this first x scale is called concat_0_x and the second one used to render the bars and text is called concat_1_x. I determine the bar widths via transforms:

"transform": [
        {
          "calculate": "scale('concat_0_x', datum['StartDate'])",
          "as": "bar_x"
        },
        {
          "calculate": "scale('concat_0_x', datum['EndDate2'])",
          "as": "bar_x2"
        },
        {
          "calculate": "datum['bar_x2']-datum['bar_x']-(2*text_horizontal_padding)",
          "as": "bar_width"
        }
      ],

I also gave it a little bit of padding so the text wouldn't be right up against the bar edges.

 

result:

giammariam_1-1679344643283.jpeg

 

Here is the .pbix.

 

If this is enough to get you going please consider liking this reply and choosing it as the solution. Otherwise, I'm happy to help further.

 



Madison Giammaria
Super User In Training‌ 😄
LinkedIn

Hi Madison,

 

Thank you very much for your response. It is exactly what I was looking for and your explanation was spot on as well. I am new to Vega Lite, so it was a big help. I have another issue which I am not sure how to fix. I am sure I am missing some very easy trick but I will create a new topic for this and tag you in it 🙂

 

Thanks again !!

Glad it's going to work for you! Congrats on diving into Deneb. It's a game changer. Thanks for planning to tag me in your next post. Feel free to hit me up anytime if you have questions in the future.



Madison Giammaria
Super User In Training‌ 😄
LinkedIn
giammariam
Impactful Individual
Impactful Individual

Hey @nailazubair, happy to look at this. Are you open to using a monospaced font? This would make this much more feasible.



Madison Giammaria
Super User In Training‌ 😄
LinkedIn

Yes sure @giammariam . I am happy to use the monospaced font if it resolves my issue. I am struggling to find the solution of this problem.

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors
Top Kudoed Authors