SharpPlot example by Nicolas Delcros

For users of dfns, both novice and expert

SharpPlot example by Nicolas Delcros

Postby Leo on Sat Dec 09, 2017 1:40 pm

Version: 16.0.31693.0 64 Unicode
Created: Dec 3 2017 at 19:58:11
Windows 7

Hello DyalogAPL'er
The SharpPlot example by Nicolas Delcros
      NicolasExample
⍝ Quelle: Nicolas Delcros-Dyalog'17-Hesingor
⍝ 1. Set Frame
⎕USING←',sharpplot.dll' ',system.drawing.dll'
sp←⎕NEW Causeway.SharpPlot(800 600)
⍝ 2. Set Parameters
sp.Heading←'My Chart'
sp.LineGraphStyle←Causeway.LineGraphStyles.GridLines
⍝ 3. Draw
data←+\¯40+?100⍴100
sp.DrawLineGraph⊂data
⍝ 4. Output(to file or stream)
System.Drawing.Imaging.ImageFormat.Png
sp.SaveImage'D:\mychart.png'[aplcode]

ends with the following errors:
      Png
LENGTH ERROR
NicolasExample[18] sp.SaveImage'D:\mychart.png'

For this feature and for SharpPlot programming following questions:

1. What are the lines for
      System.Drawing.Imaging.ImageFormat.Png
sp.SaveImage'D:\mychart.png'

2. What should the two lines look like for the above function to run without errors?

3. Is there any description for the implementation of SharpPlot - C # in SharpPlot - DyalogAPL Commands?

4. How must e.g. the C # command
      sp = new SharpPlot (PaperSize.Landscape (PaperSize.A5));
be rewritten for DyalogAPL?


Many thanks in advance for your help!

Leo
Leo
 
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm

Re: SharpPlot example by Nicolas Delcros

Postby Morten|Dyalog on Sun Dec 10, 2017 8:56 am

Hi Leo,

I believe the code should look like this:

Code: Select all
 NicolasExample;data;sp;⎕USING
⍝ Quelle: Nicolas Delcros-Dyalog'17-Hesingor
⍝ 1. Set Frame
 ⎕USING←',sharpplot.dll' ',system.drawing.dll'
 sp←⎕NEW Causeway.SharpPlot(800 600)
⍝ 2. Set Parameters
 sp.Heading←'My Chart'
 sp.LineGraphStyle←Causeway.LineGraphStyles.GridLines
⍝ 3. Draw
 data←+\¯40+?100⍴100
 sp.DrawLineGraph⊂data
⍝ 4. Output(to file or stream)
 sp.SaveImage 'c:\temp\mychart.png' System.Drawing.Imaging.ImageFormat.Png

(I had to change the output file name to get it to work on my laptop).

To answer your other questions:
    1. (and 2:) These two lines should have been a single line, the last one above.
    3. Not able to answer this right now, we'll have to wait for Nic.
    4. ⎕NEW takes a 2-element vector as its right argument, a reference to a class and an array containing the constructor arguments:
    Code: Select all
    sp←⎕NEW SharpPlot (PaperSize.Landscape PaperSize.A5)
User avatar
Morten|Dyalog
 
Posts: 462
Joined: Tue Sep 09, 2008 3:52 pm

Re: SharpPlot example by Nicolas Delcros

Postby Leo on Mon Dec 11, 2017 5:35 pm

Version: 16.0.31693.0 64 Unicode
Created: Dec 3 2017 at 19:58:11
Windows 7

Hello Mr. Morton,
Thank you for the fast answer. She helped me a lot in SharpPlot.

The below modified - "NicolasExample" function is executable. The calculation result is written to the file (c: \ temp \ NicolasExample.png) and displayed on the screen at the same time.
      ∇ NicolasExample;dat;sp;⎕USING
[1] ⍝ Quelle: Nicolas Delcros-Dyalog'17-Hesingor
[2]
[3] ⍝ 1. Set Frame
[4] ⎕USING←',sharpplot.dll' ',system.drawing.dll' ⍝ ⎕USING: Aufruf der .NET-Suchpfade für sp-Namespaces
[5] ⎕USING,←('Causeway,sharpplot.dll')('CausewayViewer,sharpplot.dll')
[6] ⎕USING,←'System.Windows.Forms,System.Windows.Forms.dll' 'System.Drawing,System.Drawing.dll' ''
[7]
[8] sp←⎕NEW Causeway.SharpPlot(800 600)
[9] ⍝ sp←⎕NEW SharpPlot(PaperSize.Landscape PaperSize.A7)
[10]
[11] ⍝ 2. Set Parameters
[12] sp.Heading←'NicolasExample'
[13] sp.LineGraphStyle←Causeway.LineGraphStyles.GridLines
[14]
[15] ⍝ 3. Draw
[16] data←+\¯40+?100⍴100
[17] sp.DrawLineGraph⊂data
[18]
[19] ⍝ 4. Output
[20] ⍝ 4.1 Graphic in Datei schreiben
[21] sp.SaveImage'c:\temp\NicolasExample.png'System.Drawing.Imaging.ImageFormat.Png
[22]
[23] ⍝ 4.2 Graphic auf Bildschirm
[24] viewer←⎕NEW SharpPlotViewer
[25] viewer.SharpPlot←sp
[26] viewer.Show ⍬

But here are some more questions:

1. When I attempting to activate paper size with line [9] (line [8] is inactive), the function ends with a LENGTH ERROR.
      [9] sp←⎕NEW SharpPlot(PaperSize.Landscape PaperSize.A7)
LENGTH ERROR
Why?

2. What must the output command look like in the above function to write the graphic in .pdf format to a file?

3. The output file can not be written to another disk partition (eg to D: \ tmp \ NicolasExample.png). Is there a reason for this?

Many thanks for the help and many greetings!

Leo
Leo
 
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm

Re: SharpPlot example by Nicolas Delcros

Postby Morten|Dyalog on Tue Dec 12, 2017 10:22 pm

Hi Leo, sorry for the slow response, had a busy couple of days!

1. I missed the fact that PaperSize.Landscape is a function... You need to pass A7 as an argument to it:
Code: Select all
   sp←⎕NEW SharpPlot (PaperSize.Landscape ⊂PaperSize.A7)

2. Can you try:
Code: Select all
   sp.SavePdf ⊂'c:\temp\NicolasExample.pdf'

3. I can't think of a reason for this... I see you have spaces in the file in your post, that probably isn't a good idea?

Morten
User avatar
Morten|Dyalog
 
Posts: 462
Joined: Tue Sep 09, 2008 3:52 pm

Re: SharpPlot example by Nicolas Delcros

Postby Leo on Wed Dec 13, 2017 12:48 pm

Thank you Mr. Morton!
Thanks to your help, the NicolasExample now works fine.
I have it in this State put in the forum. Maybe can someone may need it.
      ∇ NicolasExample;dat;sp;⎕USING
[1] ⍝ Quelle: Nicolas Delcros-Dyalog'17-Hesingor
[2] ⍝
[3] ⍝ 1. Set Frame
[4] ⎕USING←',sharpplot.dll' ',system.drawing.dll' ⍝ ⎕USING: Aufruf der .NET-Suchpfade für sp-Namespaces
[5] ⎕USING,←('Causeway,sharpplot.dll')('CausewayViewer,sharpplot.dll')
[6] ⎕USING,←'System.Windows.Forms,System.Windows.Forms.dll' 'System.Drawing,System.Drawing.dll' ''
[7] ⍝
[8] ⍝ sp←⎕NEW Causeway.SharpPlot(800 600) default version
[9] sp←⎕NEW SharpPlot(PaperSize.Landscape⊂PaperSize.A7)
[10] ⍝ 2. Set Parameters
[11] sp.Heading←'NicolasExample'
[12] sp.LineGraphStyle←Causeway.LineGraphStyles.GridLines
[13] ⍝ 3. Draw
[14] data←+\¯40+?100⍴100
[15] sp.DrawLineGraph⊂data
[16] ⍝ 4. Output
[17] ⍝ 4.1 Graphic in *.png - write file
[18] sp.SaveImage'c:\temp\NicolasExample.png'System.Drawing.Imaging.ImageFormat.Png
[19] ⍝ 4.2 Graphic in *.pdf - write file
[20] sp.SavePdf⊂'c:\temp\NicolasExample.pdf'
[21] ⍝ 4.3 Graphic on screen show
[22] viewer←⎕NEW SharpPlotViewer
[23] viewer.SharpPlot←sp
[24] viewer.Show ⍬
[25] ⍝

Many greetings!
Leo
Leo
 
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm


Return to Functional Programming

Who is online

Users browsing this forum: No registered users and 0 guests