| ||
SharpPlot Tutorials General Tutorials Chart Samples Style Examples SharpLeaf Tutorials Document Layout Tutorials Text Flow Tutorials Table Tutorials Visual Glossaries SharpPlot Reference SharpPlot Class SharpPlot Properties SharpPlot Methods SharpPlot Structures SharpPlot Enumerations PageMap Class SharpLeaf Reference SharpLeaf Class SharpLeaf Properties SharpLeaf Methods Table Class Table Properties Table Methods SharpLeaf Structures FontType Structure ParagraphStyle Structure BoxStyle Structure SharpLeaf Enumerations DocumentLayout Classes DocumentLayout Class PageLayout Class PageElement Abstract Class Frame : PageElement Class TextBlock : PageElement Class ImageBlock : PageElement Class Box : PageElement Class Rule : PageElement Class Common Reference Document Class VectorMath Class DbUtil Class Release Notes Licensing |
Getting Started > SharpPlot in different Languages SharpPlot in different LanguagesSharpPlot being delivered both as a .Net assembly and as an APL workspace, it can be used in many different languages. This tutorial shows how to write the same SharpPlot script in different languages (C#, VB/.Net, Dyalog APL/.Net, Dyalog APL). Sample chart in C#Here’s the code to produce that chart from C#. It can be used as a Rosetta stone for users trying to write scripts in other languages. To build this project in Visual Studio, a few steps are required :
using System; using System.Drawing; // Requires adding a reference to System.Drawing to the C# project using System.Drawing.Imaging; using Causeway; // Requires adding a reference to sharpplot.dll to the C# project namespace MyNamespace { class MyClass { static void Main(string[] args) { int[] data = {33, 18, 12, 10}; int[] exp = {0, 0, 0, 20}; string[] key = {"UK", "France", "Italy", "Ireland"}; SharpPlot sp = new SharpPlot(); // Use default size sp.Heading = "Sample pie chart"; // Property sp.SetKeyText(key); // Simple function sp.KeyStyle = KeyStyles.CenterAlign|KeyStyles.BottomAlign; // Flag property sp.PieChartStyle = PieChartStyles.ValueTags; sp.DrawPieChart(data, exp); // Multiple-argument function sp.SaveImage("samplepie.png", ImageFormat.Png); // Save chart as PNG image at default size Console.WriteLine(sp.RenderSvg()); // Output SVG image source to standard text stream } } } Sample chart in VB.NetHere’s the same script in VB.Net. You can build it in a few steps :
Imports System Imports System.Drawing ' Requires adding a reference to System.Drawing to the VB.Net project Imports System.Drawing.Imaging Imports Causeway ' Requires adding a reference to sharpplot.dll to the VB.Net project Module MyModule Sub Main() Dim data As Integer() = New Integer() {33, 18, 12, 10} Dim exp As Integer() = New Integer() {0, 0, 0, 20} Dim key As String() = New String() {"UK", "France", "Italy", "Ireland"} Dim sp As SharpPlot = New SharpPlot ' Use default size sp.Heading = "Sample pie chart" ' Property sp.SetKeyText(key) ' Function sp.KeyStyle = KeyStyles.CenterAlign+KeyStyles.BottomAlign ' Flag property sp.PieChartStyle = PieChartStyles.ValueTags sp.DrawPieChart(data, exp) ' Function with multiple arguments sp.SaveImage("samplepie.png", ImageFormat.Png) ' Save the chart as PNG image at default size Console.WriteLine(sp.RenderSvg()) ' Output SVG image source to standard text stream End Sub End Module Sample chart in Dyalog APL/.NetBecause Dyalog has a .Net bridge, it can use sharpplot.dll directly, which is in the default Dyalog installation directory, and can be accessed by setting ⎕USING to ‘,sharpplot.dll’. Refer to the Dyalog .Net Interface Guide if you need explanations about how to use .Net objects and pass arrays as arguments. ∇ {svg}←MyChart;⎕USING;data;exp;key;sp ⎕USING←'System.Drawing,system.drawing.dll' 'System.Drawing.Imaging' 'Causeway,sharpplot.dll' data←33 18 12 10 exp←0 0 0 20 key←'UK' 'France' 'Italy' 'Ireland' sp←⎕NEW SharpPlot ⍝ Default size sp.Heading←'Sample pie chart' ⍝ Property sp.SetKeyText(⊂key) ⍝ Need to enclose the key vector because it is a single argument, rather than a list of arguments sp.KeyStyle←KeyStyles.(CenterAlign+BottomAlign) ⍝ Flag property sp.PieChartStyle←PieChartStyles.ValueTags sp.DrawPieChart(data exp) ⍝ No need to enclose here because the 2-item vector maps to 2 different arguments sp.SaveImage('samplepie.png' ImageFormat.Png) ⍝ Save the chart as a PNG image, at default size svg←sp.RenderSvg ⍬ ⍝ Return SVG image source ∇See the ]chartUser Command for more samples, and a GUI interface to build chart scripts. Sample chart in non-.Net Dyalog APLSince Dyalog v14.0, SharpPlot is also shipped as a pure-APL workspace, than can be used on all platforms supported by Dyalog. All you need to do is to copy sharpplot.dws. The main difference from using SharpPlot through the .Net bridge is the lack of support for raster graphics. Charts can be output only as SVG, PostScript or PDF (VML is deprecated and should not be used). Because of the number of different classes provided by the sharpplot workspace, you probably want to bring them in a parent namespace for charting. ⎕CS 'Causeway' ⎕NS '' ⋄⎕CY 'sharpplot.dws' ⍝ copy all classes in a single namespace called "Causeway" ∇ {svg}←MyChart;data;exp;key;sp data←33 18 12 10 exp←0 0 0 20 key←'UK' 'France' 'Italy' 'Ireland' sp←⎕NEW SharpPlot ⍝ default size sp.Heading←'Sample pie chart' ⍝ Property sp.SetKeyText(⊂key) ⍝ better enclose it for interoperability with SharpPlot/.Net sp.KeyStyle←KeyStyles.(CenterAlign+BottomAlign) ⍝ Flag property sp.PieChartStyle←PieChartStyles.ValueTags sp.DrawPieChart(data exp) ⍝ Two arguments sp.SaveSvg(⊂'samplepie.svg') ⍝ SharpPlot/APL doesn't support raster graphics : SVG is the recommended way to export charts. svg←sp.RenderSvg ⍬ ⍝ Return SVG image source ∇ See the #.Samples namespace in sharpplot.dws for more example scripts. See also ...Getting Started | SharpPlot Tutorials | SharpLeaf Tutorials | Installing SharpPlot | SharpPlot Members |