How to get bitmap data of the chart object from System.Windows.Forms.DataVisualization.Charting for GTK# and mono?

Viewed 538

I want to bring back DataVisualization.Charting in .NET mono GTK# projects to life. I have used nplot and also ScottPlot which also outputs data as Bitmap which I then use to convert it into gif file format so it can be displayed on the GTK# window. DataVisualization.Charting is supported by mono WinForms and I have displayed charts on Winforms on Linux using mono and not on GTK#. I want to do the same with DataVisualization.Charting which I have done with ScottPlot & Nplot.

Example Code of using 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

Code for 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.

Below are links for these project if you want to check out:

  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

The platform that i'm using:

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

Thanks

0 Answers
Related