Are there any source code charting packages that are available for the Mac?
I'd like a package that would be possible to display basic scientific graphs, or ideally something like RMChart, only on the MacOS platform or that could be cross compiled to other platforms.
Regards
Andrew
Plotting/Charting Packages
-
- User
- Posts: 24
- Joined: Mon May 30, 2011 12:17 pm
Plotting/Charting Packages
Andrew Lindsay
-----------------------------------------
-----------------------------------------
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Plotting/Charting Packages
If you can't find a package like RM Chart, you will still be able to DIY with PB. Nice example here:
http://rosettacode.org/wiki/Plot_coordi ... #PureBasic
http://rosettacode.org/wiki/Plot_coordi ... #PureBasic
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Plotting/Charting Packages
Please dont ask me to defend this code.... but it works
You can see more at http://code.google.com/apis/chart/inter ... chart.html
I saw an example somewhere here in the forum that got google maps to an imagegadget, probably possible to do the same here.
The charts are pretty nice and you have tons to choose from.
You can see more at http://code.google.com/apis/chart/inter ... chart.html
I saw an example somewhere here in the forum that got google maps to an imagegadget, probably possible to do the same here.
The charts are pretty nice and you have tons to choose from.
Code: Select all
a.s="<html>"+#CRLF$
a.s+" <head>"+#CRLF$
a.s+" <script type="+Chr(34)+"text/javascript"+Chr(34)+" src="+Chr(34)+"https://www.google.com/jsapi"+Chr(34)+"></script>"+#CRLF$
a.s+" <script type="+Chr(34)+"text/javascript"+Chr(34)+">"+#CRLF$
a.s+" google.load("+Chr(34)+"visualization"+Chr(34)+", "+Chr(34)+"1"+Chr(34)+", {packages:["+Chr(34)+"corechart"+Chr(34)+"]});"+#CRLF$
a.s+" google.setOnLoadCallback(drawChart);"+#CRLF$
a.s+" function drawChart() {"+#CRLF$
a.s+" var data = new google.visualization.DataTable();"+#CRLF$
a.s+" data.addColumn('string', 'Year');"+#CRLF$
a.s+" data.addColumn('number', 'Sales');"+#CRLF$
a.s+" data.addColumn('number', 'Expenses');"+#CRLF$
a.s+" data.addRows(["+#CRLF$
a.s+" ['2004', 1000, 400],"+#CRLF$
a.s+" ['2005', 1170, 460],"+#CRLF$
a.s+" ['2006', 660, 1120],"+#CRLF$
a.s+" ['2007', 1030, 540]"+#CRLF$
a.s+" ]);"+#CRLF$
a.s+""+#CRLF$
a.s+" var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));"+#CRLF$
a.s+" chart.draw(data, {width: 400, height: 240, title: 'Company Performance',"+#CRLF$
a.s+" hAxis: {title: 'Year', titleTextStyle: {color: '#FF0000'}}"+#CRLF$
a.s+" });"+#CRLF$
a.s+" }"+#CRLF$
a.s+" </script>"+#CRLF$
a.s+" </head>"+#CRLF$
a.s+" <body>"+#CRLF$
a.s+" <div id="+Chr(34)+"chart_div"+Chr(34)+"></div>"+#CRLF$
a.s+" </body>"+#CRLF$
a.s+"</html>"+#CRLF$
OpenFile(0,GetTemporaryDirectory()+"temp.html")
WriteString(0,a.s)
CloseFile(0)
OpenWindow(0,0,0,460,300,"CHART")
WebGadget(0,0,0,460,300,"file://"+GetTemporaryDirectory()+"temp.html")
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Plotting/Charting Packages
Defend your code Sir!
Sorry, couldn't resist
Sorry, couldn't resist

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Plotting/Charting Packages
The result is pretty awsome anyway 

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Plotting/Charting Packages
It certainly is 

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Plotting/Charting Packages
Time to be more proud of the code 
This code does:
* Plot a google chart api chart. There is a ton of them to choose from
* Paint it in a window as a imagegadget.
Benefit of imagegadget vs webgadget:
* Speed
* Memory
* Compatibility
(the webgadget with javascript activated can have a nice interactive chart with mouseovers, changing colors and other stuff... but it will cost you preformance, i prefer this static image variant).

This code does:
* Plot a google chart api chart. There is a ton of them to choose from
* Paint it in a window as a imagegadget.
Benefit of imagegadget vs webgadget:
* Speed
* Memory
* Compatibility
(the webgadget with javascript activated can have a nice interactive chart with mouseovers, changing colors and other stuff... but it will cost you preformance, i prefer this static image variant).
Code: Select all
; Google chart as imagegadget.
; Jesper Brännmark
; Based on Use Google Maps in PureBasic (Easy Procedure)
; Original discussion thread for Google Maps in Purebasic: http://www.purebasic.fr/english/viewtopic.php?t=46428
;This is usage of URL:
;https://chart.googleapis.com/chart?cht=<chart_type>&chd=<chart_data>&chs=<chart_size>&...additional_parameters...
;I use http instead of https and it works just as good.
;Google information on static image charts:
;http://code.google.com/apis/chart/image/docs/making_charts.html
;See this a starting ground to do something, its not something complete.
InitNetwork()
UsePNGImageDecoder()
Procedure.l getChartImage(cht.s = "p3", chd.s = "t:60,40", width.l = 250, height.l=100, chl.s="Hello|World")
;----------------------------------------------------------------------------------
RetVal = 0
myRequestTwo.s = "/chart?cht="+URLEncoder(cht.s)+"&chd="+URLEncoder(chd.s)+"&chs="+Str(width)+"x"+Str(height)+"&chl="+URLEncoder(chl.s)
myConnection = OpenNetworkConnection("chart.googleapis.com", 80, #PB_Network_TCP)
If myConnection > 0
myRequest.s = "GET "+ myRequestTwo + " HTTP/1.0" + #CRLF$
myRequest.s + "Content-Type: application/x-www-form-urlencoded; charset=iso-8859-1" + #CRLF$
myRequest.s + "Host: chart.googleapis.com" + #CRLF$ + #CRLF$
*buffer = AllocateMemory(65535)
*bufferTwo = AllocateMemory(65535)
bfTwoPtr = 0
mSize = 65535
SendNetworkString(myConnection, myRequest)
dwBytes = 1
While dwBytes > 0
dwBytes = ReceiveNetworkData(myConnection, *buffer, 65535)
If dwBytes > 0
If (*bufferTwo + dwBytes) >= mSize
mSize + 65535
*bufferTwo = ReAllocateMemory(*bufferTwo, mSize)
EndIf
CopyMemory(*buffer, (*bufferTwo+bfTwoPtr), dwBytes)
bfTwoPtr + dwBytes
EndIf
Wend
CloseNetworkConnection(myConnection)
FreeMemory(*buffer)
dblCrlf.s = #CRLF$+#CRLF$
found = 0
For k = 0 To bfTwoPtr
If k > bfTwoPtr
Break
EndIf
If PeekS(*bufferTwo+k, 4) = dblCrlf
found = k
headerInfo.s = PeekS(*bufferTwo, k)
dataBeginSpot = (k + 4)
*dataBegin = (*bufferTwo + dataBeginSpot)
dataLength = (bfTwoPtr - dataBeginSpot)
Break
EndIf
Next
RetVal = CatchImage(#PB_Any, *dataBegin, dataLength)
FreeMemory(*bufferTwo)
Else
RetVal = -1
EndIf
ProcedureReturn RetVal
EndProcedure
myImage = getChartImage()
If IsImage(myImage)
OpenWindow(0, 0, 0, 250,100, "Test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(1, 0, 0, 250,100, ImageID(myImage))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
FreeImage(myImage)
Else
MessageRequester("Didn't get a chart image!", "Hmm, Strange...")
EndIf