Jump to content
dormky

What could I use to draw custom graphs ?

Recommended Posts

I'm drawing custom graphs, for now using GDI. Here's an example from a test project :

image.thumb.png.700a152ed4876f9f40eb802eb46b4904.png

 

It's a mess but that's because I'm testing as many possibilities as I can with the management of the axis.

One problem that I'm running into is performance : 50ms to draw. This is annoying because it makes the graph jittery when dragging elements (lines and rectangles must be able to be moved by the user).

 

I've made modifications so that it can be rendered by OpenGL, which is obviously MUCH faster (<8ms without looking very much at other performance improvements). Unfortunately initializing OpenGL takes multiple seconds. This is fine when you're running a game, but I have forms with 12 of these graphs on screen at the same time, all showing different stuff...

 

So yeah. Is there any rendering engine on Windows that's got equivalent functionnality to GDI, but is just faster by vertue of using the GPU ? Any alternatives to consider ?

Share this post


Link to post
9 minutes ago, Alexander Sviridenkov said:

Use Direct2D

I did, but performance wasn't that much better, only 50 % 😕 And that's discounting a bunch of issues I've had making it work (it's still not a one-to-one of what I get with GDI, while OpenGL is and didn't cause me implementation issues)

Share this post


Link to post
4 hours ago, dormky said:

One problem that I'm running into is performance : 50ms to draw

Use a profiler and see what takes so much. I doubt that GDI drawing takes 50 ms for this on a modern CPU.

Share this post


Link to post
2 hours ago, David Heffernan said:

This can easily be drawn quickly with gdi. You don't need another library. 

Quickly yes, quickly enough no. And I'm already using things like Polyline and caching to reduce syscalls.

Share this post


Link to post
1 hour ago, Lars Fosdal said:

@dormky Did you take a look at TeeChart?

Would TeeChart allow me to draw arbitrary shapes onto the graph ? From what I've this doesn't seem to be the case but I might have missed something. I need complete control over how the axis are laid out etc.

Although if you know what exactly TeeChart uses under the hood that might point me in the right direction.

  • Like 1

Share this post


Link to post
17 minutes ago, Cristian Peța said:

Use a profiler and see what takes so much. I doubt that GDI drawing takes 50 ms for this on a modern CPU.

Main bottleneck is the repeated calls to the gdi canvas to draw lines. I have code that prevents drawing unnecessarily (ie check if 2 points are far enough apart that they won't get resolved to the same coordinates) and this reduces the time proportionally to the size of the canvas used.

Edited by dormky

Share this post


Link to post
23 minutes ago, dormky said:

Main bottleneck is the repeated calls to the gdi canvas to draw lines.

How many lines? GDI+ is slow but I suppose you are using GDI here.

I have 174 ms for 46000 lines.

EDIT: That means 13300 lines per 50 ms

Edited by Cristian Peța

Share this post


Link to post
20 minutes ago, dormky said:

Main bottleneck is the repeated calls to the gdi canvas to draw lines.

If you profiled this then how much from that 50 ms take the calls to draw lines.

Share this post


Link to post
3 hours ago, dormky said:

Quickly yes, quickly enough no. And I'm already using things like Polyline and caching to reduce syscalls.

Definitely quickly enough. So I use graphics 32 to draw off screen bitmap and blit that. Which is still gdi. But you aren't using gdi to draw lines to a DC. That's how you make it fast. It might even be fast enough to draw to off screen TBitmap and blit that. 

Edited by David Heffernan

Share this post


Link to post
4 hours ago, dormky said:

Would TeeChart allow me to draw arbitrary shapes onto the graph ? From what I've this doesn't seem to be the case but I might have missed something. I need complete control over how the axis are laid out etc.

Although if you know what exactly TeeChart uses under the hood that might point me in the right direction.

Yes you can use the Chart1.Canvas methods that wrap around a real canvas (gdi, gdi+, opengl, skia etc) to draw anything.

 

Axis have many property settings to position and configure them (and extra TChartAxis can be created).

 

The "TeeNew" folder demo here, has aprox 700 forms, each showing different features of many categories:

 

https://github.com/Steema/TeeChart-VCL-FMX-Samples/tree/main/VCL

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×