AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Graphing Dll - RMChart
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
engunneer



Joined: 30 Aug 2005
Posts: 7703
Location: Madison, WI

PostPosted: Thu Apr 12, 2007 3:06 pm    Post subject: Graphing Dll - RMChart Reply with quote

Skan pointed out a cool dll to be used for generic graphing that looks pretty cool. Sean helped get the Dll loaded correctly and created a control, and I was able to get it to show up in a Gui. I don't have plans for this, but it looks like Skan does. Here is the basic functional code to get started, a link to the original topic, and a copy of Skan's post for reference.

Code:


hModule := DllCall("LoadLibrary", "str", "rmchart.dll")

Gui +LastFound


hGui  := WinExist()

result := DllCall("rmchart.dll\RMC_CREATECHARTFROMFILE"
                 , "UInt", hGui   ; Parent
                 , "UInt", 1001   ; CtrlId
                 , "UInt", 5      ; X
                 , "UInt", 5      ; Y
                 , "UInt", 0      ; ExportOnly
                 , "Str", "candlesticks.rmc"     ) ; RMCFile

result := DllCall("rmchart.dll\RMC_DRAW"
                 , "UInt", 1001)   ; CtrlId

Gui, Show, w700 h500, RM Chart

Return

GuiClose:
GuiEscape:
 ExitApp
Return



Post: http://www.autohotkey.com/forum/viewtopic.php?t=18267

Skan wrote:
Dear Sean, Smile

Further to my private message, I am posting here the details:
I am trying to create and embed a chart control with help of a 3rd party dll provided by rmchart.com

See the introduction: Basic concepts RMChart.dll

The problem:
The RMC_CREATECHART function requires the hwnd of the control before it is created ( atleast that is what I understand ).
I took a peek into the various Basic code provided in the package. They just create a picture control and pass its ID to the function. In one example they declare the control hwnd as a constant 10001 ?!

The DllCall fails and returns a -6 ( RMC_ERROR_CTRLID Wrong control ID (0) )

Code:
/*

nResult (LONG) = RMC_CreateChart(
ByVal nParentHndl (LONG),
ByVal nCtrlId (LONG),
ByVal nX (LONG),
ByVal nY (LONG),
ByVal nWidth (LONG),
ByVal nHeight (LONG),
Optional ByVal nBackColor (LONG),
Optional ByVal nCtrlStyle (LONG),
Optional ByVal nExportOnly (LONG),
Optional ByRef sBgImage (ASCIIZ),
Optional ByRef sFontName (ASCIIZ),
Optional ByVal nToolTipWidth (LONG),
Optional ByVal nBitmapBKColor (LONG)
)

*/

Gui +LastFound
hGui  := WinExist()

hCtrl := 0

MsgBox, % DllCall( "rmchart.dll\RMC_CREATECHART"
                 , UInt, hGui   ; Parent
                 , UInt, hCtrl  ; CtrlId
                 , UInt, 0      ; X
                 , UInt, 0      ; Y
                 , UInt, 300    ; W
                 , UInt, 300    ; h
                 , UInt, 0      ;
                 , UInt, 0      ;
                 , UInt, 0      ;
                 , Str , ""     ;
                 , Str , ""     ;
                 , UInt, 0      ;
                 , UInt, 0 )

MsgBox, % Errorlevel                 

Gui, Show, w400 h300, RM Chart
Return

GuiClose:
GuiEscape:
 ExitApp
Return


I thought, maybe I should create the control beforehand with CreateWindowEx() , but I could not as I do not know how to register a Class Name:

Code:
WS_CHILD := 0x40000000 , WS_VISIBLE := 0x10000000

hCtrl := DLLCall("CreateWindowEx"
                 , UInt, 0                               ; Style
                 , UInt, 0                               ; Class Name
                 , UInt, 0                               ; Window name
                 , UInt, WS_CHILD|WS_VISIBLE|0x00000400  ; window style
                 , Int , 5                               ; Left
                 , Int , 5                               ; Top
                 , Int , 290                             ; Right
                 , Int , 200                             ; Bottom
                 , UInt, hGui                            ; Handle of parent
                 , Int , 0                               ; Menu
                 , UInt, 0                               ; hInstance
                 , UInt, 0 )

MsgBox, % hCtrl "`n" errorlevel "`n" A_LastError


There is also a way to create the control with a Device context, again it requires CtrlHwnd beforehand. Sad

A Snapshot of the control:


Documentation links for Control Creation:
RMC_CREATECHART
RMC_CREATECHARTFROMFILE
RMC_CREATECHARTFROMFILEONDC
RMC_CREATECHARTI
RMC_CREATECHARTONDC
RMC_CREATECHARTONDCI

The CHM Documentation file: RMChart.chm [580 KB]
The DLL : RMChart.dll [128 KB]
Dependency: GDIPlus.dll [1570 KB] ( Only for OS older than XP )

RMChart Download Page: http://www.rmchart.com/rmc/Downloads.htm
I would be grateful if you help me just to get kickstarted. That would help me very much in writing the wrapper.

Thank you. Smile

_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 2296

PostPosted: Thu Apr 12, 2007 3:15 pm    Post subject: Reply with quote

Thanks! I found it pretty cool.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 4250
Location: Belgrade

PostPosted: Fri Apr 13, 2007 10:19 am    Post subject: Reply with quote

Indeed
_________________
Back to top
View user's profile Send private message
Dave72



Joined: 27 Jan 2007
Posts: 30
Location: Canada

PostPosted: Sat May 05, 2007 4:40 am    Post subject: Reply with quote

@engunneer, thanks a bunch for posting that.. it was very timely for me.

@All: Im no whiz at ahk or programming in general.. but I was able to get Apcupsd (a monitoring util for APC backup power supplies) running and logging.. then used AHK to script the log out to a more standard CSV table file... and now finally (thanks to you guys) a nice graph pop up window (using RMChart) of my UPS activity (lineV, batt%, load% and Temp).

Its probably obvious enough that I dont see it.. but

How do I get RMChart to look at the current data table, instead of the data it used as loaded in the designer ?
Back to top
View user's profile Send private message
Dave72



Joined: 27 Jan 2007
Posts: 30
Location: Canada

PostPosted: Sun May 06, 2007 3:46 am    Post subject: Reply with quote

Ok.. I managed to fix it, but Im not sure how (lol). The script call to the dll using the latest .csv I generate is indeed displaying a 'current' graph now.

On to the next headache.. I cant seem to get a timeline into the graph.
My data file starts and ends at a random time (military time format).. RMChart seems to prefer more serial type data... No luck with labelling into the timeline so far..
Back to top
View user's profile Send private message
Dave72



Joined: 27 Jan 2007
Posts: 30
Location: Canada

PostPosted: Fri May 25, 2007 1:51 am    Post subject: Reply with quote

btw, the project is at http://www.autohotkey.net/~Dave72/

I gave you guys credit (in code) for making the graph thing work with ahk. Smile

That charting module is really slick.. nice find.
Back to top
View user's profile Send private message
lingoist



Joined: 05 Oct 2004
Posts: 121
Location: Brasília, Brazil

PostPosted: Fri Jun 22, 2007 2:37 am    Post subject: Reply with quote

I've written some functions to better manipulate data in RMChart. I recommend that you read documentation file of RMChart DLL http://www.rmchart.com/.

Here are the functions (version 1.0):
Code:
      #SingleInstance force
      SetWorkingDir, %A_ScriptDir%
 
   Gui, Show, w700 h500, RM Chart
   Return
   GuiClose:
   GuiEscape:
   ExitApp
 
f8::
   ;nParentHndl
   nCtrlId=1001
   nRegion = 1
   sRMCFile = C:\folder\4 regions.rmc
   ;AHK_RMC_CreateChartFromFile(nParentHndl, nCtrlId, nX, nY, nExportOnly, sRMCFile)
   AHK_RMC_CreateChart(nParentHndl, nCtrlId, 50, 50, 500, 400)
   AHK_RMC_AddRegion(nCtrlId)
   AHK_RMC_AddCaption(nCtrlId, nRegion, "teste*weqw")
   AHK_RMC_AddGrid(nCtrlId, nRegion)
   AHK_RMC_AddLabelAxis(nCtrlId, nRegion, "Abr/06*Mai*Jun*Jul*Ago*Set*Out*Nov*Dez*Jan/07*Fev*Mar")
   AHK_RMC_AddDataAxis(nCtrlId, nRegion)
   AHK_RMC_AddDataAxis(nCtrlId, nRegion)
   AHK_RMC_AddLineSeries(nCtrlId, nRegion)
   ;AHK_RMC_SetSeriesData(nCtrlId, nRegion, 1, "20070612", nDataValuesCount)
   
   AHK_RMC_Draw(nCtrlId)
   Return
f9::
   AHK_RMC_WriteRMCFile(1001, "C:\_delete_rmc_" . A_Now)
   Return

AHK_RMC_CreateChartFromFile(nParentHndl, nCtrlId, nX, nY, nExportOnly, sRMCFile) {
   { ;GLOBALs
      ;GLOBAL nParentHndl
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nParentHndl =
      {
         Gui +LastFound
         nParentHndl  := WinExist()
      }
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_CreateChartFromFile(
      ByVal nParentHndl (LONG),
      ByVal nCtrlId (LONG),
      ByVal nX (LONG),
      ByVal nY (LONG),
      ByVal nExportOnly (LONG),
      ByRef sRMCFile (ASCIIZ)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_CREATECHARTFROMFILE"
                 , "UInt", nParentHndl
                 , "UInt", nCtrlId
                 , "UInt", nX
                 , "UInt", nY
                 , "UInt", nExportOnly
                 , "Str", sRMCFile)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_CreateChart(nParentHndl, nCtrlId, nX, nY, nWidth, nHeight, nBackColor="", nCtrlStyle="", nExportOnly="", sBgImage="", sFontName="", nToolTipWidth="", nBitmapBKColor="") {
   { ;GLOBALs
      ;GLOBAL nParentHndl
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nParentHndl =
      {
         Gui +LastFound
         nParentHndl  := WinExist()
      }
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_CreateChart(
      ByVal nParentHndl (LONG),
      ByVal nCtrlId (LONG),
      ByVal nX (LONG),
      ByVal nY (LONG),
      ByVal nWidth (LONG),
      ByVal nHeight (LONG),
      Optional ByVal nBackColor (LONG),
      Optional ByVal nCtrlStyle (LONG),
      Optional ByVal nExportOnly (LONG),
      Optional ByRef sBgImage (ASCIIZ),
      Optional ByRef sFontName (ASCIIZ),
      Optional ByVal nToolTipWidth (LONG),
      Optional ByVal nBitmapBKColor (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_CREATECHART"
                 , "UInt", nParentHndl
                 , "UInt", nCtrlId
                 , "UInt", nX
                 , "UInt", nY
                 , "UInt", nWidth
                 , "UInt", nHeight
                 , "UInt", nBackColor
                 , "UInt", nCtrlStyle
                 , "UInt", nExportOnly
                 , "Str", sBgImage
                 , "Str", sFontName
                 , "UInt", nToolTipWidth
                 , "UInt", nBitmapBKColor)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddRegion(nCtrlId, nLeft="", nTop="", nWidth="", nHeight="", sFooter="", nShowBorder="") {
   { ;GLOBALs
      ;GLOBAL nParentHndl
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_AddRegion(
      ByVal nCtrlId (LONG),
      Optional ByVal nLeft (LONG),
      Optional ByVal nTop (LONG),
      Optional ByVal nWidth (LONG),
      Optional ByVal nHeight (LONG),
      Optional ByRef sFooter (ASCIIZ),
      Optional ByVal nShowBorder (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDREGION"
                 , "UInt", nCtrlId
                 , "UInt", nLeft
                 , "UInt", nTop
                 , "UInt", nWidth
                 , "UInt", nHeight
                 , "Str", sFooter
                 , "UInt", nShowBorder)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddCaption(nCtrlId, nRegion, sCaption, nBackColor="", nTextColor="", nFontsize="", nFontbold="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_AddCaption(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      ByRef sCaption (ASCIIZ),
      Optional ByVal nBackColor (LONG),
      Optional ByVal nTextColor (LONG),
      Optional ByVal nFontsize (LONG),
      Optional ByVal nFontbold (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDCAPTION"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
                 , "Str", sCaption
                 , "UInt", nBackColor
                 , "UInt", nTextColor
                 , "UInt", nFontsize
                 , "UInt", nFontbold)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddLegend(nCtrlId, nRegion, sLegendtext, nAlignment="", nBackColor="", nStyle="", nTextColor="", nFontsize="", nFontbold="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_AddLegend(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      ByRef sLegendtext (ASCIIZ),
      Optional ByVal nAlignment (LONG),
      Optional ByVal nBackColor (LONG),
      Optional ByVal nStyle (LONG),
      Optional ByVal nTextColor (LONG),
      Optional ByVal nFontsize (LONG),
      Optional ByVal nFontbold (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDCAPTION"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
                 , "Str", sLegendtext
                 , "UInt", nAlignment
                 , "UInt", nBackColor
                 , "UInt", nStyle
                 , "UInt", nTextColor
                 , "UInt", nFontsize
                 , "UInt", nFontbold)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddGrid(nCtrlId, nRegion, nBackColor="", nAsGradient="", nLeft="", nTop="", nWidth="", nHeight="", nBiColor="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_AddGrid(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      Optional ByVal nBackColor (LONG),
      Optional ByVal nAsGradient (LONG),
      Optional ByVal nLeft (LONG),
      Optional ByVal nTop (LONG),
      Optional ByVal nWidth (LONG),
      Optional ByVal nHeight (LONG),
      Optional ByVal nBiColor (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDGRID"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
                 , "UInt", nBackColor
                 , "UInt", nAsGradient
                 , "UInt", nLeft
                 , "UInt", nTop
                 , "UInt", nWidth
                 , "UInt", nHeight
                 , "UInt", nBiColor)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddLabelAxis(nCtrlId, nRegion, sLabels, nAxisCount="", nTickcount="", nAlignment="", nFontsize="", nTextcolor="", nTextalignment="", nLinecolor="", nLinestyle="", sText="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_AddLabelAxis(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      ByRef sLabels (ASCIIZ),
      Optional ByVal nAxisCount (LONG),
      Optional ByVal nTickcount (LONG),
      Optional ByVal nAlignment (LONG),
      Optional ByVal nFontsize (LONG),
      Optional ByVal nTextcolor (LONG),
      Optional ByVal nTextalignment (LONG),
      Optional ByVal nLinecolor (LONG),
      Optional ByVal nLinestyle (LONG),
      Optional ByRef sText (ASCIIZ)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDLABELAXIS"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
                 , "Str", sLabels
                 , "UInt", nAxisCount
                 , "UInt", nTickcount
                 , "UInt", nAlignment
                 , "UInt", nFontsize
                 , "UInt", nTextcolor
                 , "UInt", nTextalignment
                 , "UInt", nLinecolor
                 , "UInt", nLinestyle
                 , "Str", sText)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddDataAxis(nCtrlId, nRegion, nAlignment="", nMinvalue="", nMaxvalue="", nTickcount="", nFontsize="", nTextcolor="", nLinecolor="", nLinestyle="", nDecimalDigits="", sUnit="", sText="", sLabels="", nLabelAlignment="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_AddDataAxis(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      Optional ByVal nAlignment (LONG),
      Optional ByVal nMinvalue (DOUBLE),
      Optional ByVal nMaxvalue (DOUBLE),
      Optional ByVal nTickco  (ASCCIZ),
      Optional ByRef nLabelAlignment (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDDATAAXIS"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
             , "UInt", nAlignment
             , "UInt", nMinvalue
             , "UInt", nMaxvalue
             , "UInt", nTickcount
             , "UInt", nFontsize
             , "UInt", nTextcolor
             , "UInt", nLinecolor
             , "UInt", nLinestyle
             , "UInt", nDecimalDigits
             , "Str", sUnit
             , "Str", sText
             , "Str", sLabels
             , "UInt", nLabelAlignment)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_AddLineSeries(nCtrlId, nRegion, nFirstDataValue="", nDataValuesCount="", nFirstPPCValue="", nPPCValuesCount="", nType="", nStyle="", nLineStyle="", nIsLucent="", nColor="", nSymbol="", nWhichDataAxis="", nValueLabelOn="", nHatchMode="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult& = RMC_AddLineSeries(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      Optional ByRef nFirstDataValue (DOUBLE),
      Optional ByVal nDataValuesCount (LONG),
      Optional ByRef nFirstPPCValue (LONG),
      Optional ByVal nPPCValuesCount (LONG),
      Optional ByVal nType (LONG),
      Optional ByVal nStyle (LONG),
      Optional ByVal nLineStyle (LONG),
      Optional ByVal nIsLucent (LONG),
      Optional ByVal nColor (LONG),
      Optional ByVal nSymbol (LONG),
      Optional ByVal nWhichDataAxis (LONG),
      Optional ByVal nValueLabelOn (LONG),
      Optional ByVal nHatchMode (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_ADDLINESERIES"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
             , "UInt", nFirstDataValue
             , "UInt", nDataValuesCount
             , "UInt", nFirstPPCValue
             , "UInt", nPPCValuesCount
             , "UInt", nType
             , "UInt", nStyle
             , "UInt", nLineStyle
             , "UInt", nIsLucent
             , "UInt", nColor
             , "UInt", nSymbol
             , "UInt", nWhichDataAxis
             , "UInt", nValueLabelOn
             , "UInt", nHatchMode)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_SetSeriesData(nCtrlId, nRegion, nSeries, nFirstDataValue, nDataValuesCount, nYData="") {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
      If nRegion =
         nRegion = 1
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_SetSeriesData(
      ByVal nCtrlId (LONG),
      ByVal nRegion (LONG),
      ByVal nSeries (LONG),
      ByRef nFirstDataValue (DOUBLE),
      ByVal nDataValuesCount (LONG),
      Optional ByVal nYData (LONG)
      )
      */
   }
   { ;CALL DLL
      nResult := DllCall("rmchart.dll\RMC_SETSERIESDATA"
                 , "UInt", nCtrlId
                 , "UInt", nRegion
             , "UInt", nSeries
             , "UInt", nFirstDataValue
             , "UInt", nDataValuesCount
             , "UInt", nYData)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_Draw(nCtrlId) {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_Draw(
      ByVal nCtrlId (LONG)
      )
      */
   }
   { ;CALL DLL
      nresult := DllCall("rmchart.dll\RMC_DRAW"
                 , "UInt", nCtrlId)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}
AHK_RMC_WriteRMCFile(nCtrlId, sRMCFile) {
   { ;GLOBALs
      ;GLOBAL
      ;STATIC
   }
   { ;DEFAULTs
      If nCtrlId =
         nCtrlId = 1001
   }
   { ;LOAD LIBRARY
      hModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   }
   { ;SYNTAX
      /*
      nResult (LONG) = RMC_WriteRMCFile(
      ByVal nCtrlId (LONG),
      ByRef sRMCFile (ASCIIZ)
      )
      */
   }
   { ;CALL DLL
      nresult := DllCall("rmchart.dll\RMC_WRITERMCFILE"
                 , "UInt", nCtrlId
                 , "Str", sRMCFile)
   }
   { ;ERROR
      If nResult <> 0
         MsgBox, 0, Error RMChart - Line %A_LineNumber%, %nResult%
   }
}


Use F8 and F9 to create the chart.

I strongly recommend Notepad++ to use functions

The code of the file 4 regions.rmc is (altogether in one line):
Code:
00003700|00004500|000054|000061|000071|00008-984833|00009221|00011Tahoma
|100011|100032|100042|10005348|10006248|1000910|100101|100111|100181|100200|10021100
|1002211|100238|100331|100341|100355|100378|100481|100491|10051-984833|10052-16777216
|10053-657956|100541|100558|10056-16777216|10057-16777216|10060-16777216|10061-16777216
|10187Label 1*Label 2*Label 3*Label 4*Label 5|110011|110021|110031
|110046|110056|11006-1|110091|110131|11014-1|110171|1102111|110221|110235|1105330*40*70*60*20
|200011|20003352|200042|20005-2|20006248|2000910|200101|200111|200181|200200|20021100|2002211
|200238|200331|200341|200355|200378|200484|200491|20051-984833|20052-16777216|20053-657956
|200544|200555|20056-16777216|20057-16777216|20060-16777216|20061-16777216|20187Label 1*Label 2*Label 3*Label 4*Label 5
|210011|210023|210033|210045|210055|21006-1|210091|210101|210131|21014-1|210171|2102111|210221
|210235|2105320*10*15*25*30|220011|220023|220033|220045|220055|22006-1|220091|220101|220131
|22014-1|220171|2202111|220221|220235|2205325*30*10*20*15|230011|230023|230033|230045|230055
|23006-1|230091|230101|230131|23014-1|230171|2302111|230221|230235|2305310*20*40*20*30|240011
|240023|240033|240045|240055|24006-1|240091|240101|240131|24014-1|240171|2402111|240221|240235
|2405340*30*20*30*20|300011|300032|30004252|30005348|30006-2|3000910|300101|300181|300481
|300491|30051-984833|30052-16777216|30053-657956|310011|3100251|310031|3100454|310054|310071
|310091|310121|310151|310161|310171|310182|310211|310221|310235|3105330*50*20*40*60|400011
|40003352|40004252|40005-2|40006-2|4000910|400101|400111|400131|400181|40020100|40021250
|4002211|400238|400281|400292|400300|400310|400322|400331|400341|4003510|400378|400482
|400492|40051-984833|40052-16777216|40053-984833|400541|400558|40056-16776961|40057-16777216
|400592|40060-16777216|40061-16777216|40183$ |40185 %|410011
|410021|410031|410043|410053|41006-1|4100950|410131|41014-1|410171|41019-10496|4102111|410221
|4102310|41053240*230*220*180*170*160*145*130*125*115|420011|4200221|420035|4200422|420052
|420061|420071|4200963|420111|420121|420131|420171|42019-16744448|4202115|420221|4202310
|420261|420538.1*6.2*4.3*2.2*1.2*3.1*5.2*11.4*7.3*4.2


[Moderator's note - This codeblock was edited to make it not crazy wide - all of those numbers should be in one line]
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 827

PostPosted: Wed Aug 08, 2007 3:54 pm    Post subject: Reply with quote

Ok,

Just finished playing with the RMChart designer and it looks pretty cool.
The only thing is, that I am not quite sure I understand how to embed the chart, and how to insert new data to it on AHK gui.

The designer is capable of generating a Visual Basic code that is ready to paste - but how are all the implementations discussed here are doing it?
Back to top
View user's profile Send private message Visit poster's website
Icarus



Joined: 24 Nov 2005
Posts: 827

PostPosted: Sun Aug 12, 2007 12:25 pm    Post subject: Reply with quote

Ok,

I am looking for a charting solution for AHK for a long time, and it looks like this is it.
The first demo script in this thread did not work for me, but thankfully, the UPS script was short and clear.

So I created a small demo here, for the rest of the people who are looking to use RMChart as a charting solution for AHK.

The concept that I think we should stick to is this:
1. Design the chart in the RMChart Designer
2. In the designer, point the chart to an external data file (CSV)
3. Save the RMC file (now containing your design and reference to the data file)
4. In AutoHotkey, just call a generic function to display the chart using the design specified in the RMC file

I am sure this is all obvious, but I noticed that someone tried to wrap all of RMChart's functions and I am not sure I am fond of this method.

So, first copy this code to test.ahk (in a folder with the rmchart.dll)

Code:
#SingleInstance Force

Gui +LastFound
GuiID  := WinExist()
AddChart( GuiID, "MyBars.rmc" )
Gui Show, w700 h500, Chart Test

Return

GuiClose:
GuiEscape:
   ExitApp
Return
 
AddChart( GuiID, DesignFile ) {
   ; Load RMChart DLL
   ChartModule := DllCall("LoadLibrary", "str", "rmchart.dll")
   
   ; Build the chart based on the RMC file
   result := DllCall("rmchart.dll\RMC_CREATECHARTFROMFILE" 
         ,UInt,GuiID
         ,UInt,1000         ; ctrl id of the chart window
         ,UInt,0             ; x
         ,UInt,0             ; y
         ,UInt,0             ; display only
         ,Str,DesignFile )    ; RMCFile
         
   ; Draw the chart
   result := DllCall("rmchart.dll\RMC_DRAW"
         ,UInt,1000 )   ; CtrlId
}



Then, copy the below to mybars.rmc in the same folder

Code:
00003500|00004400|000051|000061|00008-984833|00009401|00011Tahoma|100011|100035|100045|10005-5
|10006-5|1000911|100101|100111|100121|100181|100200|100210|1002211|100238|100331|100341|100355|100378
|100481|100491|10051-16776961|10052-256|10053-1|100541|100558|10056-16777216|10057-16777216|10060-16777216
|10061-16777216|100623|10063-1|100651|10181This is the chart's caption|10187danny1*danny2
|110011|110021|110031|110043|110053|11006-1|110091|110131|11014-1|110171|1102111|110222|110235|11055test.csv
|110562|110571,-1|11058,


[Moderator's note - This codeblock was edited to make it less wide. all of the numbers, etc should be on one line.]

and finally, copy the below to test.csv (same folder)

Code:
1,30
2,90
3,80
4,120
5,60



Now, running the AHK script should show the pre-designed chart, with the CSV data - that can be modified by your script.

Unfortunately, it looks like some content elements that should have been excluded from the RMC file (such as Caption and Axis Labels) are a part of the RMC file, so there are in my opinion two ways to overcome this:

1. The simple and dirty way - is to alter the RMC file prior to using it (for example, StrReplace on the caption string)
2. To create some basic wrappers for the required content elements (i.e. use RMSet... to change caption and axis labels).

To the more experienced people here - does it make sense?

[/code]
Back to top
View user's profile Send private message Visit poster's website
Icarus



Joined: 24 Nov 2005
Posts: 827

PostPosted: Mon Aug 20, 2007 1:32 pm    Post subject: Help Needed: Round() returns invalid value after dllcall Reply with quote

The following code demonstrates the problem.

The Round() function returns a different value after the DllCall

Code:
myNumber  := 1043.22
myRounded := Round( myNumber, -1 )
msgbox 32,,Before: %myRounded%
   
ChartModule := DllCall("LoadLibrary", "str", "rmchart.dll")

myNumber  := 1043.22
myRounded := Round( myNumber, -1 )
msgbox 32,,After %myRounded%



The first call generates 1040 as expected, the second call - 1039...
Can anyone explain why?
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 7703
Location: Madison, WI

PostPosted: Mon Aug 20, 2007 5:12 pm    Post subject: Reply with quote

you may want to make a post in the Bug Report forum about this. Link back to here so Chris can get the DLL.

Does any other DLL have the problem?
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
Icarus



Joined: 24 Nov 2005
Posts: 827

PostPosted: Mon Aug 20, 2007 5:37 pm    Post subject: Reply with quote

Thanks - will post a bug report.

I tried with some Windows DLLs (copied some DllCalls('LoadLibrary"...) lines from the forum, and no - it only happens with this DLL.

From what I could tell, the problem is consistent - Round returns the rounded number -1
Back to top
View user's profile Send private message Visit poster's website
Icarus



Joined: 24 Nov 2005
Posts: 827

PostPosted: Mon Aug 27, 2007 10:59 pm    Post subject: Reply with quote

Ok,

I tried to get some help in regards to sending ByRef to the RMChart dll in the Ask for Help thread, but I thought this is becoming too specific to RMChart.

If anyone else is using this DLL, and can help me in understanding how to send ByRef arrays to it, it would be appreciated.

Specifically, I am trying to draw a custom object on the chart, using the COLINE function.

Here is the code I am using.
Error and ErrorLevel are both clean:

Code:
   VarSetCapacity(ArrayX, 8, 0)  ; Two 4-byte integers
   VarSetCapacity(ArrayY, 8, 0)  ; Two 4-byte integers
   
   XA := NumPut( 10 , ArrayX, 0)
   NumPut( 500, ArrayX, 4)
   YA := NumPut( 100,  ArrayY, 0)
   NumPut( 500, ArrayY, 4)
   
   msgbox %XA%
   
   Error := DllCall( "..\Res\DLLs\rmchart.dll\RMC_COLINE"
      ,UInt,    ControlID
      ,UInt,   100         ; ByVal nCOIndex (LONG)
      ,UInt,   XA         ; ByRef nXPoints (LONG),
      ,UInt,   YA         ; ByRef nYPoints (LONG),
      ,UInt,   2          ; ByVal nPointsCount (LONG),
      ,UInt,  0          ; Optional ByVal nStyle (LONG),
      ,UInt,  0xff0000   ; Optional ByVal nColor (LONG),
      ,UInt,  0         ; Optional ByVal nAsSpline (LONG),
      ,UInt,  2         ; Optional ByVal nLineWidth (LONG),
      ,UInt,  0         ; Optional ByVal nStartCap (LONG),
      ,UInt,  0 )         ; Optional ByVal nEndCap (LONG)
      
   if( error )
      msgbox error %error%
      
   if( errorlevel )
      msgbox errorlevel %errorlevel%


I tried many variations of this command, and in the full code, it is called before the Draw Chart function is called.

Here is also a link to the original thread in the Help forum
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 2296

PostPosted: Tue Aug 28, 2007 2:33 am    Post subject: Reply with quote

You should've used
Code:
XA-4
YA-4

not
Code:
XA
YA


BTW, just in case, don't forget to do LoadLibrary first.
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 827

PostPosted: Tue Aug 28, 2007 6:35 am    Post subject: Reply with quote

Thanks for the correction, still nada.

btw - in this case, does the XA-4 eqyal to &ArrayX?

Here is the function and sub-function I use to create a chart. I do load the library and the chart is drawn nicely, except the part inside the ; TEST------ comments.

Code:
AddChart( GuiID, DesignFile, DataFile, X, Y, Width=0, Height=0 ) {
;
; Return Value: Control ID
;
; GuiID         AHK Parent Window ID
; DesignFile   RMC filename, created by RMChart Designer
; DataFile      CSV filename
; X,Y         Coordinates of the chart on the AHK GUI window
; Width,Height   Dimensions (optional)
;
;-------------------------------------------------------------------------------
   Static ControlID := 1000

   ; Load RMChart DLL
   If( ControlID = 1000 ) ; This is the first time we are called
      ChartModule := DllCall("LoadLibrary", "str", "..\Res\DLLs\rmchart.dll")
   
   Error := _BuildChart( GuiID, ControlID, DesignFile, DataFile, X, Y, Width, Height )
   
   ControlID += 1
   If( Error )
      msgbox Error in AddChart: %Error%
   Else
      Return ControlID-1
}


_BuildChart( GuiID, ControlID, DesignFile, DataFile, X, Y, Width=0, Height=0 ) {
;
; Called internally by AddChart and RebuildChart
; Returns an error code or 0 if all went well
;
;-------------------------------------------------------------------------------
   Error := 0
   
   ; Determine how many series we have in this data file
   FileReadLine SampleLine, %DataFile%, 1
   StringSplit Token, SampleLine, `,
   ColCount := Token0
   
   ; Build the chart based on the RMC file
   Error += DllCall( "..\Res\DLLs\rmchart.dll\RMC_CREATECHARTFROMFILE" 
      ,UInt,GuiID
      ,UInt,ControlID      ; Chart Control ID
      ,UInt,X             ; X
      ,UInt,Y             ; Y
      ,UInt,0             ; Display Only
      ,Str,DesignFile )    ; RMCFile

   ; Assign the data file
   Loop % ColCount-1 {
      ThisCol := A_Index+1
      Error += DllCall( "..\Res\DLLs\rmchart.dll\RMC_SETSERIESDATAFILE"
         ,UInt, ControlID
         ,UInt,1
         ,UInt,A_Index
         ,Str,DataFile
         ,Str,""
         ,Str,ThisCol
         ,Str,"," )
   }
   
   ; Set labels, based on the min/max values of the first column
   TICK_COUNT := 10
   MinLabel := ""
   FileRead FileString, %DataFile%
   Loop Parse, FileString, `n,`r
   {
      If( A_LoopField = "" )
         Continue
      StringSplit Token, A_LoopField, `,
      If( MinLabel = "" )
         MinLabel := Token1
   }
   MaxLabel := Token1
   
   LabelStep := (MaxLabel-MinLabel) / (TICK_COUNT-1)
   
   Labels := ""
   Loop %TICK_COUNT% {
      ThisLabel := MinLabel + ((A_Index-1) * LabelStep )
      StringSplit ThisLabel, ThisLabel, .
      Labels .= ThisLabel1 . "|"
   }
   
   Error += DllCall( "..\Res\DLLs\rmchart.dll\RMC_SETLAXLABELS"
      ,UInt,ControlID
      ,UInt,1
      ,Str,Labels )
      
   Error += DllCall( "..\Res\DLLs\rmchart.dll\RMC_SETLAXTICKCOUNT"
      ,UInt, ControlID
      ,UInt, 1
      ,UInt, TICK_COUNT )
      
   ; Optional: change chart dimensions
   If( Width<>0 )and ( Height<>0 ) {
      Error += DllCall("..\Res\DLLs\rmchart.dll\RMC_SETCTRLSIZE"
         ,UInt,ControlID
         ,UInt,Width
         ,UInt,Height )      
   }
   
   
   ; TEST----------------------------------------------------------------------
   Size := 4
   
   VarSetCapacity(ArrayX, Size, 0)  ; Two 4-byte integers
   VarSetCapacity(ArrayY, Size, 0)  ; Two 4-byte integers
   
   XA := NumPut( 100 , ArrayX, 0) - 4
         NumPut( 100 , ArrayX, Size)
   YA := NumPut( 10  , ArrayY, 0) - 4
         NumPut( 300 , ArrayY, Size)     
   
   Error := DllCall( "..\Res\DLLs\rmchart.dll\RMC_COLINE"
      ,UInt, ControlID
      ,UInt, 1         ; ByVal nCOIndex (LONG)
      ,UInt, XA         ; ByRef nXPoints (LONG),
      ,UInt, YA         ; ByRef nYPoints (LONG),
      ,UInt, 2           ; ByVal nPointsCount (LONG),
      ,UInt, 0          ; Optional ByVal nStyle (LONG),
      ,UInt, 0xff0000      ; Optional ByVal nColor (LONG),
      ,UInt, 0         ; Optional ByVal nAsSpline (LONG),
      ,UInt, 0         ; Optional ByVal nLineWidth (LONG),
      ,UInt, 0         ; Optional ByVal nStartCap (LONG),
      ,UInt, 0 )         ; Optional ByVal nEndCap (LONG)
      
   if( error )
      msgbox error %error%
      
   if( errorlevel )
      msgbox errorlevel %errorlevel%
   ; TEST----------------------------------------------------------------------   
      
   
   ; Draw the chart
   Error += DllCall( "..\Res\DLLs\rmchart.dll\RMC_PAINT"
      ,UInt,ControlID )      ; Control ID
      
   Return Error
}


I can post the entire code, but it also requires two external files (the design file and data file)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group