Linqpad extension to plot graphs

1.9k views Asked by At

I tried to plot some graphs in Linqpad with with "Util.RawHtml()" and "Dump()" but it is not working with this example from amcharts.com. I created a string variable including all the HTML source code but the result is not working.

string html = "";
using (System.Net.WebClient client = new System.Net.WebClient ())
{
    html = client.DownloadString(@"http://pastebin.com/raw/pmMMwXhm");
}

Util.RawHtml(html).Dump();
3

There are 3 answers

0
sgmoore On

As I understand it, this will not work because the html contains scripts that will not be executed.

As an alternative, you can still use the old (and deprecated) google charts api, eg

var link = @"http://chart.apis.google.com/chart?chxt=y&chbh=a&chs=300x225&cht=bvg&chco=A2C180,3D7930&chd=t:10,20,30,40,50,60|30,35,40,45,55,60&chtt=Sample";

Util.Image (link).Dump();

or see http://blog.divebomb.org/2012/11/dumping-charts-in-linqpad/

0
Jim Patterson On

Not sure if it's the answer you're after but there may be value in looking at the DisplayWebPage method on the Util class in Linqpad. This correctly rendered your chart in the result window, (although there was a script error). Obviously, this may not solve your underlying issue.

I used version 5.10.00 to test this.

0
mbx On

Later versions of LinqPad 5 now support charting out of the box with Util.Chart. You can see the samples in the Samples Tab (next to My Queries) under

  • LINQPad Tutorial&Reference
    • Scratchpad Features
      • Charting with Chart

The following script is the Chart() - dual scale sample:

// Each y-series can have a different series type, and can be assigned to the secondary y-axis scale on the right.

var customers = new[]
{
    new { Name = "John", TotalOrders = 1000, PendingOrders = 50, CanceledOrders = 20 },
    new { Name = "Mary", TotalOrders = 1300, PendingOrders = 70, CanceledOrders = 25 },
    new { Name = "Sara", TotalOrders = 1400, PendingOrders = 60, CanceledOrders = 17 },
};

customers.Chart (c => c.Name)
    .AddYSeries (c => c.TotalOrders,    Util.SeriesType.Spline, "Total")
    .AddYSeries (c => c.PendingOrders,  Util.SeriesType.Column, "Pending",   useSecondaryYAxis:true)
    .AddYSeries (c => c.CanceledOrders, Util.SeriesType.Column, "Cancelled", useSecondaryYAxis:true)
    .Dump();