[Library] Chart using Gdiplus

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

[Library] Chart using Gdiplus

Post by neovis » 12 Jun 2022, 11:09

Chart libaray for Autohotkey v1

Source on Github: https://github.com/neovis22/chart
chart_all.png
chart_all.png (115.67 KiB) Viewed 4355 times
live_chart.gif
live_chart.gif (244.83 KiB) Viewed 4355 times
Here is a simple usage example:

Code: Select all

#Include <chart/chart>
#include <chart/gdip_all>

OnExit(Func("Gdip_Shutdown").bind(Gdip_Startup()))

Gui Add, Pic, xm w600 h300 0xE Hwndhwnd
chart := chart(hwnd, "Line").title("Title of Chart").labels("Item 1,Item 2")
chart.xAxis.title("X Axis").labels("Apple,Lime,Mango,Orange,Banana")
chart.yAxis.title("Y Axis").range(0, 100).grid(5)

loop 2 {
    chart.data(data := [])
    loop 10 {
        Random n, 0, 100
        data.push(n)
    }
}
chart.plot()

Gui Show
Output like this.
chart.png
chart.png (20.44 KiB) Viewed 4492 times
Last edited by neovis on 12 Jun 2022, 22:30, edited 1 time in total.

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: [Libaray] Chart using Gdiplus

Post by boiler » 12 Jun 2022, 18:43

Very nice. :thumbup:

User avatar
flyingDman
Posts: 2776
Joined: 29 Sep 2013, 19:01

Re: [Libaray] Chart using Gdiplus

Post by flyingDman » 12 Jun 2022, 22:58

Nicely done!! I have done this a few times using Excel. Always nice to be able to do this natively.
14.3 & 1.3.7

sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: [Libaray] Chart using Gdiplus

Post by sofista » 13 Jun 2022, 11:00

Looks impressive :bravo:

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [Libaray] Chart using Gdiplus

Post by jNizM » 14 Jun 2022, 02:01

Reminds me of Chart.js for webpages.

Well done
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: [Library] Chart using Gdiplus

Post by Relayer » 14 Jun 2022, 12:24

Very impressive. I will learn a lot from your coding. Thank you.

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: [Libaray] Chart using Gdiplus

Post by neovis » 14 Jun 2022, 23:09

jNizM wrote:
14 Jun 2022, 02:01
Reminds me of Chart.js for webpages.

Well done
Your reminds right. 8-)
I referred chart.js for using chart library to how to use it. I got a idea about chart types and options structure like using key to access data objects (xkey, ykey, rkey). so similar to usage.

User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: [Library] Chart using Gdiplus

Post by Relayer » 30 Jun 2022, 12:08

I have been playing with this class and really like it. I would like to encourage you to continue to enhance it! I often need to work with very large data files from sensors that are plotted against time. I often need to zoom in on particular details. Excel is very poor at large files. I am using your class to create a time plot of data in a scrollable/scaleable format that only reads a section of the data into memory at a time instead of trying to load the whole file.

Relayer

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [Library] Chart using Gdiplus

Post by jNizM » 01 Jul 2022, 02:45

Would be nice to see this for v2 in the near future as well.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

User avatar
moefr01
Posts: 115
Joined: 25 Nov 2015, 09:01
Location: Germany

Re: [Library] Chart using Gdiplus

Post by moefr01 » 03 Jul 2022, 03:20

Great job @neovis ...thank you!

To avoid flickers insert the following at line 10 of your live chart example:
Gui, +E0x02080000 ; doublebuffering

cheers
moefr01 :wave:

toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: [Library] Chart using Gdiplus

Post by toralf » 03 Jul 2022, 05:48

Dear neovis.

This is awesome.
And very clean code. This is very good to learn from it.

I have not tested it yet, so forgive me if this questions is stupid:
When a graph is shown in the GUI, is it possible to detect on which element a mouse pointer is hovering and show a tooltip with information of that element (e.g. the exact value of that bar)?
ciao
toralf

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: [Library] Chart using Gdiplus

Post by neovis » 03 Jul 2022, 21:55

Relayer wrote: I have been playing with this class and really like it. I would like to encourage you to continue to enhance it! I often need to work with very large data files from sensors that are plotted against time. I often need to zoom in on particular details. Excel is very poor at large files. I am using your class to create a time plot of data in a scrollable/scaleable format that only reads a section of the data into memory at a time instead of trying to load the whole file.
Thanks for your comments.
I haven't tried it on a lot of data yet. Please let me know if you have any ideas for improve it.
jNizM wrote: Would be nice to see this for v2 in the near future as well.
I want to migrate to v2, but I think it's still a bit early. However, I'll write it in v2 later.
moefr01 wrote: To avoid flickers insert the following at line 10 of your live chart example:
Gui, +E0x02080000 ; doublebuffering
Thank you for telling me. I'll add it.

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: [Library] Chart using Gdiplus

Post by neovis » 03 Jul 2022, 22:38

toralf wrote:
03 Jul 2022, 05:48
When a graph is shown in the GUI, is it possible to detect on which element a mouse pointer is hovering and show a tooltip with information of that element (e.g. the exact value of that bar)?
Not yet supported.
I've been thinking about it, but I still don't know how to implement it. Any ideas?

toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: [Library] Chart using Gdiplus

Post by toralf » 04 Jul 2022, 14:39

neovis wrote:
03 Jul 2022, 22:38
Any ideas?
Not really, For the time being I'm placing Picture Controls. So I can detect their hwnd and react to it.
ciao
toralf

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: [Library] Chart using Gdiplus

Post by neovis » 04 Jul 2022, 23:28

toralf wrote:
04 Jul 2022, 14:39
neovis wrote:
03 Jul 2022, 22:38
Any ideas?
Not really, For the time being I'm placing Picture Controls. So I can detect their hwnd and react to it.
I added a at(x, y) method. Its return value from point. Currently, only bar and line charts are supported.

Try to this code to add on your chart script. Careful a chart variable name if you use a different name.

Code: Select all

OnMessage(0x200, "onHover") ; WM_MOUSEMOVE

onHover(wparam, lparam, msg, hwnd) {
    global chart ; chart variable
    MouseGetPos,,,, hwnd, 2
    if (chart.hwnd == hwnd) {
        VarSetCapacity(pt, 8, 0)
        DllCall("GetCursorPos", "ptr",&pt)
        DllCall("ScreenToClient", "ptr",hwnd, "ptr",&pt)
        ToolTip % chart.at(NumGet(pt, 0, "int"), NumGet(pt, 4, "int"))
    }
}

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Library] Chart using Gdiplus

Post by kczx3 » 16 Jul 2022, 19:13

This is extremely impressive. Nicely done. And I second @jNizM about a v2-compatible version! I think you'll find writing this kind of code is much simpler in v2.

EDIT: Corrected improper @mention.
Last edited by kczx3 on 16 Jul 2022, 19:26, edited 1 time in total.

gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: [Library] Chart using Gdiplus

Post by gregster » 16 Jul 2022, 19:21

I guess you meant jNizM ;)

User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: [Library] Chart using Gdiplus

Post by SirSocks » 24 Jul 2022, 11:42

Super awesome, and useful. Thank you. :)

User avatar
oldbrother
Posts: 265
Joined: 23 Oct 2013, 05:08

Re: [Library] Chart using Gdiplus

Post by oldbrother » 24 Jul 2022, 15:14

Nice Job! Thank you so much!

Is it possible to add text or numbers in the bars?

Image
Attachments
pic.png
pic.png (25.51 KiB) Viewed 2567 times

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: [Library] Chart using Gdiplus

Post by neovis » 28 Mar 2023, 23:02

oldbrother wrote:
24 Jul 2022, 15:14
Nice Job! Thank you so much!

Is it possible to add text or numbers in the bars?

Image

This is example for you.

Code: Select all

#Include <chart/chart>
#include <chart/gdip_all>

OnExit(Func("Gdip_Shutdown").bind(Gdip_Startup()))

Gui Add, Pic, xm w600 h300 0xE Hwndhwnd
chart := chart(hwnd, "Bar").theme("dark")
chart.yAxis.range(0, 100).grid(5)
chart.render := Func("chart_drawValue")

loop 2 {
    chart.data(data := [])
    loop 5 {
        Random n, 0, 100
        data.push(n)
    }
}
chart.plot()

Gui Show

chart_drawValue(chart, g) {
    chart.base.render.call(chart, g)
    
    tr := new chart.TextRenderer("Center vCenter Bold", "Segoe UI")
    tr.color := chart.color
    switch (chart.type) {
        case "Bar", "BarV":
            Gdip_RotateWorldTransform(g, -90)
            for i, v in chart.elements {
                tr.x := -(v.y+v.height)
                tr.y := v.x
                tr.width := Max(v.height, 60)
                tr.height := v.width
                tr.render(g, v.value)
            }
            Gdip_ResetWorldTransform(g)
        case "BarH":
            for i, v in chart.elements {
                tr.x := v.x
                tr.y := v.y
                tr.width := v.width
                tr.height := v.height
                tr.render(g, v.value)
            }
    }
}
Attachments
2023-03-29 130305.png
2023-03-29 130305.png (12.36 KiB) Viewed 1730 times

Post Reply

Return to “Scripts and Functions (v1)”