内联转储自定义的LINQPad图表

时间:2019-04-25 16:49:17

标签: charts linqpad

如果我没有在LINQPad中自定义图表,则有一种方法可以使用linqpadChart.DumpInline()内联转储。

是否有类似的方法来内联转储自定义的图表,还是像在本示例中那样创建和转储Bitmap

string[] xSeries = { "John", "Mary", "Sue" };
int[] ySeries = { 100, 120, 140 };

var winChart = xSeries.Chart().AddYSeries (ySeries, Util.SeriesType.Pie).ToWindowsChart();

// Make tweaks/customizations:
var area = winChart.ChartAreas.First();
area.Area3DStyle.Enable3D = true;
area.Area3DStyle.Inclination = 50;
winChart.Series.First().Points[2].SetCustomProperty ("Exploded", "true");

// Draw it to a bitmap and then dump it:
using (var bitmap = new Bitmap(500, 500))
{
    winChart.DrawToBitmap(bitmap, new Rectangle(Point.Empty, bitmap.Size));
    bitmap.Dump();
}

1 个答案:

答案 0 :(得分:1)

是的,尽管有WebChart,这类似于DumpInline在幕后所做的事情。

这是LINQPadChart中的代码,如果您想将其复制到我的扩展程序

public static class MyExtensions
{
    public static Bitmap ToBitmap (this Chart webChart) => ToBitmap (webChart, 0, 0);

    public static Bitmap ToBitmap (this Chart webChart, int width, int height)
    {
        if (width <= 0) width = Screen.PrimaryScreen.WorkingArea.Width / 2;
        if (height <= 0) height = width / 2;

        var img = new Bitmap (width, height);
        using (var g = Graphics.FromImage (img)) webChart.Paint (g, new Rectangle (0, 0, width, height));
        return img;
    }
}