Forum Discussion

htbull_'s avatar
htbull_
Frequent Visitor
6 months ago
Solved

Line Break in X-Axis of Bar Chart

Good afternoon, 

 

I am looking for a way to have line breaks within the x-axis title of a bar chart. I've previously been able to insert one line break within the title and have attached an image for reference. 


Within this example I've used a calculated column and used unichar(10) to insert the line break to varying results. Once trying to insert an additional break I receive misaligned titles and information. 


My intention is to have 3 different lines, one for Year, Gross Incurred, and Net Incurred. I would like it to look like the following below. (A card example)

 



  • Hi htbull_ ,

     

    For this you need to think outside the box using the custom labels and some additional calculations.

     

    Be aware that the use of the custom labels cannot be used when you use the legend so I suggest the following since it seems you only have 3 categories

     

    I assume that the chart will not have negative values do the following:

    • Change your chart to a line and stacked column chart
    • Create a measure for each of the categories
    • Create 3 new measures with fixed values:
      • -100000
      • -150000
      • -200000
      • (for example this may need adjustments based on the units you have)
    • Now configure the chart in this manner:
    • X-axis
      • Year
    • Column Y-Axis
      • The 3 measures for the values ytou want to represent
    • Line Y-Axis
      • The 3 new measures with the fix values
      • Rename the name of the fixed measures in the visual to the text you want in this case "Gross Incurred:" and "Net Incurred:"
    • Turn off values for the Secondary Y axis
    • Turn off lines
    • For each of the measures in the lines turn on the data labels
      • Change the value of thar data label to the measure you want in this case the MAX year, Gross Incurred and Net Incurred
      • Turn on the title
    • Turn of X-axis values

    Final result:

     

     

    This can also be achieved using Visual calculations for the fixed lines insted of creating new measures on your model.

     

    I also played around with doing a multi line value but on the visual the line break did not work.

7 Replies

  • Multiple line breaks in axis labels are a pain — the rendering in bar charts is inconsistent once you go past one break.
    Try using UNICHAR(13) & UNICHAR(10) instead of just UNICHAR(10) for each line break, some people get better results with that combo.
    Honestly though, the bar chart axis just doesn't handle 3 lines well and the misalignment you're seeing is a known issue. If it still doesn't work, your best bet is shortening the label text or accepting two lines max.

  • Hi htbull_ ,

     

    For this you need to think outside the box using the custom labels and some additional calculations.

     

    Be aware that the use of the custom labels cannot be used when you use the legend so I suggest the following since it seems you only have 3 categories

     

    I assume that the chart will not have negative values do the following:

    • Change your chart to a line and stacked column chart
    • Create a measure for each of the categories
    • Create 3 new measures with fixed values:
      • -100000
      • -150000
      • -200000
      • (for example this may need adjustments based on the units you have)
    • Now configure the chart in this manner:
    • X-axis
      • Year
    • Column Y-Axis
      • The 3 measures for the values ytou want to represent
    • Line Y-Axis
      • The 3 new measures with the fix values
      • Rename the name of the fixed measures in the visual to the text you want in this case "Gross Incurred:" and "Net Incurred:"
    • Turn off values for the Secondary Y axis
    • Turn off lines
    • For each of the measures in the lines turn on the data labels
      • Change the value of thar data label to the measure you want in this case the MAX year, Gross Incurred and Net Incurred
      • Turn on the title
    • Turn of X-axis values

    Final result:

     

     

    This can also be achieved using Visual calculations for the fixed lines insted of creating new measures on your model.

     

    I also played around with doing a multi line value but on the visual the line break did not work.

    • htbull_'s avatar
      htbull_
      Frequent Visitor

      Hey Miguel, thanks for the suggestion and for the most part it worked great! I am unable to have my axis titles underneath the bars however. They are currently viewing as labels within the chart. Any suggestions?

       

       

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi htbull_ ,

         

        That is because you have the Secondary Y-axis values turn on and to what I can see you have the measure for the label has positive values.

         

        First put them has negative so they can move to the bottom of the bars then and this is the trick go to secondary Y-Axis and the values should be turn off by default, turn them on and them turn off again this should make your chart with a single Y-axis on the left side and the values for the lines should move to the bottom.

  • As per my knowledge, default axis labels do not support. 

    Matrix does, you can verify it, but I understand that is not your requirement. To test, you can give a try!