Как получить растровые данные объекта диаграммы из System. Windows .Forms.DataVisualization.Charting для GTK # и mono? - PullRequest
2 голосов
/ 29 февраля 2020

Я хочу вернуть DataVisualization.Charting. NET моно GTK # проектов к жизни. Я использовал nplot, а также ScottPlot, который также выводит данные в виде растрового изображения, которое я затем использую для преобразования их в формат файла gif, чтобы их можно было отобразить в окне GTK #. DataVisualization.Charting поддерживается моно WinForms, и я отображал диаграммы на Winforms на Linux, используя моно, а не на GTK #. Я хочу сделать то же самое с DataVisualization.Charting, который я сделал с ScottPlot & Nplot.

Пример кода использования ScottPlot:

    double[] dataXs = { 1,2 };
    double[] dataSin = { 10,100 };

    var plt = new ScottPlot.Plot(600, 400);
    plt.Title("Simple Bar Plot");
    plt.PlotBar(dataXs, dataSin, barWidth: .5);
    var bitmap = plt.GetBitmap(); //Gets the Bitmap of the chart

    MemoryStream memStream = new MemoryStream();
    bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif); //storing the bitmap as GIF in memory
    var data = memStream.ToArray();

    var pixbuf = new Gdk.Pixbuf(data);
    image1.Pixbuf = pixbuf; //Passing the GIF data to the GTK# image Control

Код для DataVisualization.Charting:

  // Build a pie series
    Series series = new Series("Default");
    series.ChartType = SeriesChartType.Pie;
    series["PieLabelStyle"] = "Disabled";
    chart.Series.Add(series);


    // Define the chart area
    ChartArea chartArea = new ChartArea();
    ChartArea3DStyle areaStyle = new ChartArea3DStyle(chartArea);
    areaStyle.Rotation = 0;

    double[] yValues = { 15, 60, 12, 13 };
    string[] xValues = { "September", "October", "November", "December" };

    chart.Series.Add("Default");
    chart.ChartAreas.Add("ChartArea1");

    chart.Series[0].ChartArea = "ChartArea1";
    chart.Series[0].ChartType = SeriesChartType.Pie;

    chart.Series["Default"].Points.DataBindXY(xValues, yValues);
    var data = getBitmap(chart);//I have no idea on how to get bitmap data from chart object.

Ниже приведены ссылки на этот проект, если вы хотите проверить:

  1. https://github.com/swharden/ScottPlot
  2. https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datavisualization.charting?view=netframework-4.8
  3. https://weblogs.asp.net/scottgu/built-in-charting-controls-vs-2010-and-net-4-series

Платформа, которую я использую:

Linux Distribution: Ubuntu 18.04.3 LTS
Mono release is: 6.8.0 Stable (6.8.0.105)
MonoDevelop IDE release is: 7.6 (7.6.9.22)
Graphics ToolKit: GTK# 2.12
.NET Framework 4.7

Спасибо

...