Plot chart Godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By x4rkz

I would like to plot chart using godot. My research let me think that this can’t be done with godot unless I reinvent the wheel using Line2D for instance. The best way would be to be able to use another language which will plot my charts.

First is possible?

How can I do it using python? And if this is not possible how about c++?

:bust_in_silhouette: Reply From: Zylann

My research let me think that this can’t be done with godot


unless I reinvent the wheel using Line2D for instance

It’s not re-inventing the wheel (at best it makes you a wheel that can run in realtime using cross-platform accelerated graphics and very few dependencies), Godot allows you to draw lines. Then it’s up to you to decide from which data the points will come from.

The best way would be to be able to use another language which will plot my charts.

Programming languages have nothing to do with plotting a chart. In any case you have to use Godot’s API to draw things.

How can I do it using python? And if this is not possible how about c++?

You could use Python with the Python binding, or C++, but as I said above, none of them will help you to better plot your chart.

In any case, what you need to do is to get the data for your chart, and display it either by setting the points of a Line2D node with a script, or by drawing it from a _draw callback if you want more procedural control. There is nothing hard in these solutions.
Then it depends which kind of chart you want, and how you want to display it.

I already starting doing it with godot, I’m able to draw a curve, xAxis, yAxis so that it shows the good scale dynamically etc… it’s starting to use unnecessary time.
I’m drawing the curve in real time and I want my scale to adapt.

It also means that I need a Line2D for my curve, two others for my axis, several more to mark graduations. I need to write labels next to it, it’s quickly becoming messy (a working plugin would be perfect, I found one but only works for godot < 2.1). Moreover how can I draw a point on godot? → I think I just found draw_circle.

Finally, is it possible to plot with python and to display on a small panel only the result of the python plot? I’m really exploring this for the specific features such as scale etc, but if you convince me I can do what I want using godot easily, I won’t need this part (I’m still curious about the answer).

In case doing it godot on godot is really the best solution because it doesn’t take that much time, and if a plugin doesn’t already exists, I’m thinking about writing this as a plugin.

x4rkz | 2019-09-15 07:50

Godot is a game engine, so indeed plotting a graph as fully-fledged as one you find in a spreadsheet program is not built-in. It will require some work. Turns out, the Godot editor itself plots charts already, like the profiler or the curve editor, so that’s doable.

It’s feasible to make a generic chart control answering the same capabilities since Godot has all drawing functions required to make one, but I can tell you for sure that enforcing the use of an entire foreign programming language such as Python will be more trouble.

I plotted simple charts myself in a few of my apps, and I thought about making such addon but never really did since what I got was enough for me at the time.

Zylann | 2019-09-15 14:28

Bonjour Zylan,

Old guy new to Python and even newer to Godot here. I am exploring Godot to see if I could use it to make teaching material for my classes. I had exactly the same requirement: the ability to make some generic charts. I don’t know what the profiler or the curve editor is yet, but I’ll go and find out: in the meantime, is it possible to see some of the examples you mention in your post. I am not sure if we can see that on your web site and if so, which product I should be looking at.

Please let me know when you can, and I will come back to ask some questions when I have done my homework

All the best. C

Cricri | 2020-01-04 18:21

The curves you see in the profiler and curve editor were made on the spot. From memory, their drawing code fits in about 50 lines each. They turned different because written by different persons with different needs. One uses sampled points while the other one uses bezier. It’s really just about drawing points in the end, for which Godot offers various ways to draw lines within a for loop or using Line2D.

If you are looking for a graphing library for Godot, you could use this GDScript addon: GitHub - binogure-studio/chart-gd: Animated charts for Godot Engine
If you are new to Python and Godot, I’d recommend learning GDScript instead. Python can be used in Godot but its integration to the engine is second-class in comparison.

Zylann | 2020-01-04 19:02

HI Zylann,

Thank you for replying, especially on a Saturday night. I am indeed planning to use GDScript only.

I downloaded and installed Godot, and loaded a couple of examples. I also searched the documentation: the problem is it does not mention the PROFILER or the CURVE EDITOR. So, obviously, I am not seeing curves in them because I am not seeing them at all. The search in the online docs gives me nothing on profiler and only unrelated results on curve editor. So kind of stuck at first base.

Anyway, it’s the weekend and you have other things to do (already brilliant you had time to answer), so for now I will check out your recommendation for the graphing library.

All the best. C

Cricri | 2020-01-04 20:08