Ugly Stool Rotating Header Image

Dumping a Sho Chart in the LINQPad Result Window

If you dump a Sho chart in LINQPad, LINQPad creates a new WinForms tab to hold the dump result.  Actually, every time a WinForm is dumped a new WinForm tab is created.  If you dump a lot of charts this can quickly add up to a lot of tabs.  Worse, the results are not inline so you have to constantly jump between tabs to get results.  Ideally, you want the dumps all in one tab.  There is a way.  LINQPad supports dumping BMP directly to the result window.  Render the chart onto a BMP, and then dump the BMP. 

Code to do the translation from WinForm to BMP is below.  I suggest you add it to your My Extensions class so it is always available.

void DumpShoChart(ShoChart shoChart, int width, int height)
    var field = shoChart.GetType().GetField("plot", BindingFlags.Instance | BindingFlags.NonPublic);
    var chart = field.GetValue(shoChart) as System.Windows.Forms.DataVisualization.Charting.Chart;
    chart.Dock = DockStyle.None;
    chart.Size = new Size(width, height);
    using (var stream = new MemoryStream())
        chart.SaveImage(stream, ImageFormat.Bmp);

Comments are closed.

Page optimized by WP Minify WordPress Plugin