Forum Discussion

dave_cousins's avatar
dave_cousins
Regular Visitor
2 years ago
Solved

Positioning of columns by a variable

I want to make a column chart, where the columns (values in Y axis) are positioned horizontally (Y axis) by another variable.

 

As a very crude workaround, for the X-variable staying in a set position, I made multiple column charts and adjusted the graphics so they (almost) looked like one chart), but surely I can give the X-variable a value and have Power BI position the columns accordingly.

 

This is how it looks with my workaround:

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi dave_cousins 

     

    For your problem, you can try using a python script . Make sure you have Python installed correctly and imported the matplotlib library before implementation.

     

    You can use the following code to achieve the desired effect

    import matplotlib.pyplot as plt
    
    data = {
        'index': [1, 3, 6, 10, 15, 20],
        'value': [-2.1, -2.5, -3, -2.8, -2.6, -2]
    }
    plt.bar(data['index'], data['value'])
    
    
    plt.title('Sample Bar Chart')
    plt.xlabel('Index')
    plt.ylabel('Value')
    
    
    plt.show()

     

    The value in index can be used to control the distance between each bar in the histogram

     

    This is the result you want

     

    If you want to change the distance between each bar, you can easily change it in the code and click the Run button in the top right corner

     

     

     

    Best Regards,

    Jayleny

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi dave_cousins 

     

    For your problem, you can try using a python script . Make sure you have Python installed correctly and imported the matplotlib library before implementation.

     

    You can use the following code to achieve the desired effect

    import matplotlib.pyplot as plt
    
    data = {
        'index': [1, 3, 6, 10, 15, 20],
        'value': [-2.1, -2.5, -3, -2.8, -2.6, -2]
    }
    plt.bar(data['index'], data['value'])
    
    
    plt.title('Sample Bar Chart')
    plt.xlabel('Index')
    plt.ylabel('Value')
    
    
    plt.show()

     

    The value in index can be used to control the distance between each bar in the histogram

     

    This is the result you want

     

    If you want to change the distance between each bar, you can easily change it in the code and click the Run button in the top right corner

     

     

     

    Best Regards,

    Jayleny

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.