Jump to content

Easiest approach to plot data to line graph jpg file?


Recommended Posts

Hello,

for some informational html page I would like to plot a line graph from inside an autoit script.

I've used before the GraphGDIplus UDF, to display a line graph in an Autoit GUI (different task).

The Graph shall be saved to a JPG file only, no displaying is required (script is running as a service).  I'd just like to ask, if someone is aware of other approaches to do so, maybe some new, now buildin functionality of Autoit?

TIA, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

When using GraphGDIplus UDF you can save the GUI directly after drawing the graph with _Draw_Graph() by adding something like this:

#include <ScreenCapture.au3>
_ScreenCapture_CaptureWnd(@ScriptDir & "\_graph.png", $GUI)

I recommend to use png instead of jpg, because GDI might distort colors for jpg output.

 

Edit:

I saw that the GUI must be visible for this to work. But looking at the UDF I saw that it's possible to access the backbuffer directly, even if the GUI is not visible the graph is there.

$Graph = _GraphGDIPlus_Create($GUI, 40, 30, 530, 520, 0xFF000000, 0xFF88B3DD)
...
...
_Draw_Graph()
; directly after draw call
_GDIPlus_ImageSaveToFile($Graph[16], @ScriptDir & "\_graph.png")

 

Edited by KaFu
Link to comment
Share on other sites

I don't know if it works for you.
I mention this as an idea

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <Excel.au3>

Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookNew($oExcel)

Global $aData[][] = [ _
        ["Month", "Bears", "Dolphins", "Whales"], _
        ["jan", 8, 150, 80], _
        ["feb", 54, 77, 54], _
        ["mar", 93, 32, 10], _
        ["apr", 116, 11, 76], _
        ["may", 137, 6, 93], _
        ["jun", 184, 1, 72]]

_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aData, "A1")
Global $oChart = $oWorkbook.Activesheet.ChartObjects.Add(300, 10, 600, 400)
Global $iRow = UBound($aData)
Global $iCol = UBound($aData, 2)
Global $sRng = "A1:" & _Excel_ColumnToLetter($iCol) & $iRow

$oChart.Chart.SetSourceData($oWorkbook.Activesheet.Range($sRng))
$oChart.Chart.ChartType = 65 ;65 xlLineMarkers - Line with Markers.
;https://learn.microsoft.com/en-us/office/vba/api/excel.xlcharttype

;~ $oChart.Chart.Export(@ScriptDir & "\export_chart.gif", "GIF")
$oChart.Chart.Export(@ScriptDir & "\export_chart.jpg", "JPG")

 

Edited by ioa747
UpDate

I know that I know nothing

Link to comment
Share on other sites

  • 2 weeks later...

BTW: There is an ExcelChart UDF available.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks for pointing out this UDF to do Excel charts.

I will give it a try, but basically I would prefer to create the required JPG file without additional software packages to be applied first. Like Microsoft Office (Excel)

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...