Search code examples
pythonchartspygal

Render pygal charts without borders


I am looking for the way of rendering charts without borders using pygal. I have no found anything useful in the documentation. However, I have identified a very strange situation looking the examples. Lets see:

Chart with no border in the y-axis

In this example, you can see that the chart has no frame in the y-axi, but there is not a specific statement to achieve this. Now take a look at this other example:

enter image description here

In this case, the example shows how truncate the labels of the x-axis, but for some reason there is a border in the y-axi, and again there is not a specific statement.

What is happening? How could I deal with it? I would need to know the way for rendering the chart without any border, does anyone know something about it? Thank you so much.


Solution

  • In the code for graph/graph.py the y axis is only printed out if there are x_labels.

    By borders in the chart it seems like you are referring to gridlines. So if you would like to remove them in the line chart you are building you can add two functions to the Line class in graph/line.py or any other chart type that you would like to remove them from.

    Just put in a new CustomLine class where you're building your application like below:

    import pygal
    
    
    class CustomLine(pygal.Line):
    
        def __init__(self, *args, **kwargs):
            super(CustomLine, self).__init__(*args, **kwargs)
    
        def _x_axis(self):
            pass
    
        def _y_axis(self):
            pass
    
    
    chart = CustomLine()
    chart.add('Series 1', [0, 0.005, 0.002])
    chart.render_response()
    

    enter image description here Hope this helps!