Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Quick and easy helper to render chars in LinqPad
<Query Kind="Program">
void Main()
new LpChart(series: GetSeries(), chartType: SeriesChartType.Column, width: 1250).Dump();
new LpChart(series: GetSeries(), chartType: SeriesChartType.Line, width: 1250).Dump();
new LpChart(series: GetSeries(), chartType: SeriesChartType.Bar, width: 500).Dump();
private ChartSeries GetSeries()
var items = Enumerable.Range(1, 25).Select(x => string.Format("item-{0}", x));
var rand = new Random(100);
var prices = items.Select(x => rand.NextDouble());
return new ChartSeries { XSeries = items.ToList(), YSeries = prices.ToList() };
public class ChartSeries
public IList<string> XSeries { get; set; }
public IList<double> YSeries { get; set; }
public class LpChart
public Chart Chart { get; private set; }
public ChartArea ChartArea { get; private set; }
public Series Series { get; private set; }
public Bitmap Bitmap { get; private set; }
public LpChart(ChartSeries series, SeriesChartType chartType = SeriesChartType.Column, int width = 1200)
this.Chart = new Chart();
this.ChartArea = new ChartArea();
this.Series = new Series();
this.Series.ChartType = chartType;
this.Series.Points.DataBindXY(series.XSeries.ToArray(), series.YSeries.ToArray());
this.Chart.Width = width;
this.Bitmap = new Bitmap(width: this.Chart.Width, height: this.Chart.Height);
public void Dump()
this.Chart.DrawToBitmap(this.Bitmap, this.Chart.Bounds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment