Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 932
Luis González Avatar asked Jun 09 '26 12:06

Luis González


1 Answers

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!

like image 189
hektorsuhr Avatar answered Jun 12 '26 02:06

hektorsuhr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!