2011-06-11 79 views

回答

4

LINQPad使用WebBrowser控件來顯示動態生成的HTML頁面。您甚至可以通過右鍵單擊結果窗口來查看其源代碼。所以它基本上是Internet Explorer的封裝。就HTML的生成而言,它使用定製的XhtmlFormatter來訪問對象圖併發出基於XDocument的XHTML。

+0

該死的你是對的! =)。非常感謝你 – 2011-06-11 17:11:52

3

LINQPad還可以調用Windows Forms附帶的所有舊Dundas charting controls。只需轉儲任何Bitmap對象和LINQPad就盡職盡責地將其顯示在HTML中。請嘗試以下操作,確保您有System.Drawing,System.Windows.FormsSystem.Windows.Forms.DataVisualization,在您的F4參考中,粘貼並點擊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(); 
} 
相關問題