Search code examples
python-3.xgraphchartskivykivymd

Creating a beautiful chart inside python kivymd


I want to create a beautiful chart inside my kivymd program, some like this:

Chart from svg.charts

I loved this design of chart, because have good colors and transparency, but I don't know how I can create a chart like this inside kivy or kivymd.

It was created by svg.charts, I tried to show it inside a Svg widget from kivy, but don't works. And I tried convert it to png too, using pylunasvg, but the background color turned black...

I saw that have kivy garden charts, that is very similar to matplotlib, but I think that its uggly, because I don't know how fill it with transparency or how to create a card with the lines titles. It's the chart image in the github:

Kivy garden graph charts

I saw too the akivymd chart, but it have a lot of colors and will be tiring the user. The print from the example application of the akivymd repository:

Akivymd chart

I don't know what to do anymore, somebody have a tip that how I create a chart like the first inside kivy?

EDITED

This was the file that the conversion created:

The converted file

It's my conversion method:


from PIL import Image as pImage
from pylunasvg import Document
from numpy import array
from typing import Optional, Union

def svg_to_image(svg_content: str,
                 savedir: Optional[str] = None,
                 filename: Optional[str] = None) -> Union[str, type(pImage)]:
    document = Document.loadFromData(svg_content)
    bitmap = document.renderToBitmap()

    img = pImage.fromarray(array(bitmap, copy=False))

    if savedir is not None:
        if filename is not None:
            if filename.endswith('.png'):
                _dir = join(savedir, filename)
            else:
                _dir = join(savedir, filename + '.png')
        elif savedir.endswith('.png'):
            _dir = savedir
        else:
            raise ValueError('Argument filename is None')
        img.save(_dir, format='png')
        return _dir
    else:
        return img

RESUMED

I will resume my question, how the better way to show a beautiful chart inside kivy?

Some like this:

Example


Solution

  • Well, such I don't find any good graph library, I created my own widget. It's took a while, but I got it. I published this widgets inside my repository, and I expect that it help another peoples like me, I used kivy 2.2.0.dev0 and kivymd 1.2.0.dev0. This is a print from the LineChart:

    Chart from svg.charts

    Thank you everybody that tried to help me!