OxyPlot : integration in website/webservice

SamOxyPlot 5 year бұрын • жаңартылды 5 year бұрын 6

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,

Thanks for the fast response!

Tremendous help !
Satisfaction mark by SamOxyPlot 5 year бұрын
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:
Is it possible to build the OxyPlot.WindowsForms.dll in .NET 3.5 ?
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