使用什么数据可视化控件在LINQPad中显示结果?或者在.NET中显示分层数据还有其他选择吗?
答案 0 :(得分:4)
LINQPad使用WebBrowser控件来显示动态生成的HTML页面。您甚至可以通过右键单击结果窗口来查看其源代码。所以它基本上是Internet Explorer的包装器。就HTML的生成而言,它使用自定义构建的XhtmlFormatter来访问对象图并基于XDocument发出XHTML。
答案 1 :(得分:3)
LINQPad还可以调用Windows Forms附带的所有旧Dundas charting controls。只需转储任何Bitmap对象,LINQPad尽职尽责地在HTML中显示它。尝试以下操作,确保在 F4 引用中有System.Drawing
,System.Windows.Forms
和System.Windows.Forms.DataVisualization
,粘贴并点击 F5 。它也可以与更高级别的SHO图表一起使用,这些图表是为IronPython量身定制的,但是在C#中工作得很好。
// Almost the smallest meaningful example of Charting
void Main()
{
// Chart must have a chart area, but it's not externally referenced later
var chartArea1 = new ChartArea();
var chart1 = new Chart();
chart1.ChartAreas.Add(chartArea1);
var series1 = new Series();
// The following goes beyond the minimal, but just a little. You can delete these two lines.
// Fun to set the series ChartType; default is column chart
series1.ChartType = SeriesChartType.Pie;
series1.CustomProperties = "LabelsRadialLineSize=1, PieDrawingStyle=Concave, LabelStyle=outside";
var r = new Random(Guid.NewGuid().GetHashCode());
var ys = Enumerable.Range(0, 5).Select (e => r.NextDouble()).Dump("Doubles");
var xs = Enumerable.Range(0, 5).Select (e => GetRandomString(3).ToUpper()).Dump("Strings");
series1.Points.DataBindXY(xs.ToArray(), ys.ToArray());
chart1.Series.Add(series1);
var b = new Bitmap(width: chart1.Width, height: chart1.Height);
chart1.DrawToBitmap(b, chart1.Bounds);
b.Dump();
var frm = new Form();
// Seems 300 x 300 is the default chart-area size and chart size, so set the form to hold it
frm.ClientSize = new Size(width: 300, height: 300);
frm.Controls.Add(chart1);
Application.Run(frm);
}
static IEnumerable<string> CharRange(Char c, int length)
{
return (from e in Enumerable.Range(Convert.ToInt32(c), length)
select Char.ConvertFromUtf32(e));
}
static string GetRandomString(int length)
{
var sb = new StringBuilder();
do
sb.Append(Path.GetRandomFileName().Replace(".", "").Substring(0, length < 11 ? length : 11));
while ((length -= 11) > 0);
return sb.ToString();
}