0
Answered

OxyPlot : integration in website/webservice

SamOxyPlot 10 ár síðan Uppfært 10 ár síðan 6
Hi

I was wondering if it’s possible to use OxyPlot for exporting .png files on the fly that are shown in a website.

From what I know I can use it within Winforms / WPF.
But my goal is to have the plotviews available in my website.


We already have an webservice (.NET 4.0). Is it possible to integrate OxyPlot there?
I don’t want a dirty solution to start an external exe in the webpage/webservice that generates the PNG.


Maybe you’ve got an idea?


With kind regards,

+1
Under review
Yes, this should be possible. Use the `OxyPlot.WindowsForms.PngExporter` to write to the response stream.

Here is an example using WebAPI:
namespace WebApplication4.Controllers
{
    using System;
    using System.IO;
    using System.Net;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using OxyPlot;
    using OxyPlot.Series;
    using OxyPlot.WindowsForms;
    public class PlotsController : ApiController
    {
        public HttpResponseMessage Get(int id)
        {
            var model = new PlotModel { Title = "Plot #" + id };
            model.Series.Add(new FunctionSeries(Math.Sqrt, 0, 100, 0.01, "sqrt(x)"));
            var memoryStream = new MemoryStream();
            var exporter = new PngExporter();
            exporter.Export(model, memoryStream);
            var result = new HttpResponseMessage
                             {
                                 StatusCode = HttpStatusCode.OK,
                                 Content = new ByteArrayContent(memoryStream.ToArray())
                             };
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
            {
                FileName = string.Format("plot{0}.png", id)
            };
            return result;
        }
    }
}
The result is:
You could also consider using svg for your response.
Is it possible to build the OxyPlot.WindowsForms.dll in .NET 3.5 ?
+1
Yes, no changes in the code should be neccessary. Just copy the OxyPlot.WindowsForms_NET40.csproj, change the target to v3.5 and reference OxyPlot_NET35.csproj

OxyPlot.WindowsForms_NET35.csproj
I've got it working!

Big thanks!