lprun to html with chart

Hi, is it possible to use LinqPad chart when running lprun with html output? (LinqPad5)
In GUI all is perfect, but with lprun I get HTML files with images like img src="C:\TEMP\LINQPad5\_cguwfjvw\ukrbpe" which is not there after lprun is done..


  • You could convert the chart to a Bitmap object - look at the Chart() - customization sample in LINQPad's built-in samples for a demo - and then save the Bitmap to a location of your choice:

    Bitmap bitmap = xSeries.Chart().AddYSeries (ySeries, Util.SeriesType.Pie).ToBitmap();
    bitmap.Save (@"c:\temp\test.png", System.Drawing.Imaging.ImageFormat.Png);
    Util.RawHtml ("<img src='file:///c:/temp//test.png'>").Dump();
  • Hi Joe,
    with that I was successful. Looks a bit like a hack, as I have to do different things in lprun compared to GUI, but I think I can live with that. Thanks for the hint to bitmap.Save()

    foreach (var ser in issues.Select(i => i.Serial).Distinct())
        var ch = issues.Where(i => i.Serial == ser).Chart(i => i.Date);
        ch.AddYSeries(c => c.LSERIES, name: "LSERIES", seriesType: LINQPad.Util.SeriesType.Line);
        ch.AddYSeries(c => c.PSERIE, name: "PSERIE", seriesType: LINQPad.Util.SeriesType.Line);
        Bitmap bitmap = ch.ToBitmap();
        var title = $"{ser} series count";
    #if CMD
        bitmap.Save (@"d:\Defects\D_8087859\NIGHT\" + ser + "_2.png", System.Drawing.Imaging.ImageFormat.Png);
        Util.RawHtml ($"<h2>{title}</h2><img src='file:{ser}_2.png'>").Dump();
  • @Achim there is a batter way to have self-contained dump output, as previously mentioned at https://forum.linqpad.net/discussion/comment/2562#Comment_2562, though I had to make a slight modification.
    Put the following code to your "My Extensions":

    public static object ToDump(object input)
        var image = input as System.Drawing.Image;
        if (image != null)
            using (var ms = new MemoryStream())
                image.Save(ms, ImageFormat.Png);
                return Util.Image("data:image/png;base64," + Convert.ToBase64String(ms.ToArray()));
        return input;

    Then output chart as bitmap and you will have all resources in the same output:

    string[] xSeries = { "John", "Mary", "Sue" };
    int[] ySeries = { 100, 120, 140 };
    var chart = xSeries.Chart().AddYSeries(ySeries).ToBitmap(500, 300);
  • @lexxsoft After small modification, this worked great, thanks. I did not understand your last line, if I use that I don't get the image in the generated HTML. But using simply bitmap.Dump() it worked perfectly

        var ch = issues.Where(i => i.Serial == ser).Chart(i => i.Date);
  • @Achim last line generates output document that can be saved/sent as a self-contained report without any use of UI, all images are encoded inside Html.

Sign In or Register to comment.