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?
Link of the PBIX file:
https://drive.google.com/file/d/1gTyasUwTIVfGqbkrfCEpdsahH5Uauwj-/view?usp=share_link
Solved! Go to Solution.
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.
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:
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.
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.
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:
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.
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.
Hey @nailazubair, happy to look at this. Are you open to using a monospaced font? This would make this much more feasible.
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.