简体   繁体   中英

Draw PdfSharp chart on PictureBox

Is there a way to draw PdfSharp Chart on PictureBox rather then to pdf?

    PdfDocument doc = new PdfDocument();
    PdfPage page = doc.AddPage();
    page.Size = PdfSharp.PageSize.A4;
    XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
    XGraphics gfx = XGraphics.FromPdfPage(page);

    Chart chart = LineChart();
    ChartFrame chartFrame = new ChartFrame();
    chartFrame.Location = new XPoint(30, 30);
    chartFrame.Size = new XSize(500, 200);
    chartFrame.Add(chart);
    chartFrame.Draw(gfx);

That gives my nice chart that I can save as pdf. LineChart() is just creating a simple chart.

I need to draw this chart over PictureBox component.

With PDFsharp, you can try the following:

You can use method Graphics.FromImage to get a Graphics object for an Image.
You can use method XGraphics.FromGraphics to get an XGraphics object for that Graphics object.
This should allow the chart to draw directly on the Image instead of creating a PDF file.

The PictureBox should be able to display the Image.

Just theory - I didn't try it myself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM