2 steps to plot your ESAPI script data.


In this article, I’ll show you how to plot data using simple HTML and JavaScript, then how to implement this pattern in C# to plot your ESAPI data.

Why are we using the browser?

var x = new List<double>{1,2,3,4,5};
var y = new List<double>{2,4,6,8,10};

WPF and Oxyplot would be the choices to plot in C#, however it is not recommended to use this pattern in a single file. And since we tend to avoid compiled scripts (binary plugins) or executable scripts, I think using HTML and JavaScript is an easy turnaround to solve this simple problem.


  1. Think about the plot you need;
  2. Emulate some data to feed the plot;
  3. Code JavaScript and HTML;
  4. Use C# to create a document containing JavaScript and HTML;
  5. Feed data from ESAPI into the plain JavaScript and HTML;

Simple HTML and Simple JS to plot with Plot.ly

However, searching a bit in Google for 3D plot JavaScript, I’ve found Plot.ly.

Reading 1 minute of the documentation, I was able to render a 3D scatter Plot.

Below is all the code we need for our example. We referenced the library via CDN and got some boilerplate code.

Result for 3D scatter plot with Plot.ly JS

And with plot.ly you get all features for rotation, pan, zoom etc. It is as easy as can get.

C# do this HTML document for me please.

Reference the VMS.TPS libraries (.dll) to be able to run the script.

Paste the following code in the main .cs file, rename it to PlotMU_SSD_Dmax.cs.

The code has 3 main scopes, one is responsible for gathering info from the ScriptContext: SSD, Metersets and MaxDose in percentage. Another is to create a static text with 3 lists (xs,ys,zs), that will be passed to the a runner that will start the file with the default program for .html files (the browser).

Run the script, searching for the folder where the solution is saved:

And !

Result for MU (X) SSD(Y) Dmax(Z)

This is a turnaround to perform easy plots in JavaScript from C# code. It is not the safest option.

And you can use the power of JavaScript and HTML to build reports, when learning WPF is not easy.



Radiation Therapy Medical Physicist and Programmer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store