PDFSHARP Chart erzeugen

  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von steffen_cl.

    PDFSHARP Chart erzeugen

    Hallo zusammen,

    ich versuche gerade ein Chart in einem PDF zu erzeugen. Dazu nutze Ich PDFSharp.dll und PDFSharp.Charting.dll. Es kommt zu folgendem Abbruch (Bild 1).

    Hätte jemand eine Idee wo mein Problem liegt?

    Vielen Dank vorab

    VB.NET-Quellcode

    1. Imports PdfSharp.Charting
    2. Imports PdfSharp.Drawing
    3. Imports PdfSharp.Pdf
    4. Public Class Form1
    5. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    6. ' Create a new PDF document
    7. Dim document As PdfDocument = New PdfDocument
    8. document.Info.Title = "Created with PDFsharp"
    9. ' Create an empty page
    10. Dim page As PdfPage = document.AddPage
    11. ' Get an XGraphics object for drawing
    12. Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
    13. #Region "Chart"
    14. Dim chart_1 As Chart = New Chart(ChartType.Line)
    15. Dim Series As Series = chart_1.SeriesCollection.AddSeries
    16. Series.Name = "series 1"
    17. Series.Add({1, 5, -3, 20, 11})
    18. Dim Series1 As Series = chart_1.SeriesCollection.AddSeries()
    19. Series.Name = "Series 2"
    20. Series.Add({22, 4, 12, 8, 12})
    21. chart_1.XAxis.MajorTickMark = TickMarkType.Outside
    22. chart_1.XAxis.Title.Caption = "X-Axis"
    23. chart_1.YAxis.MajorTickMark = TickMarkType.Outside
    24. chart_1.YAxis.Title.Caption = "Y-Axis"
    25. chart_1.YAxis.HasMajorGridlines = True
    26. chart_1.PlotArea.LineFormat.Color = XColors.DarkGray
    27. chart_1.PlotArea.LineFormat.Width = 1
    28. chart_1.PlotArea.LineFormat.Visible = True
    29. chart_1.Legend.Docking = DockingType.Bottom
    30. chart_1.Legend.LineFormat.Visible = True
    31. Dim XSeries As XSeries = chart_1.XValues.AddXSeries()
    32. XSeries.Add("A", "B", "C", "D", "E", "F")
    33. #End Region
    34. Dim chartFrame As New ChartFrame
    35. chartFrame.Location = New XPoint(100, 100)
    36. chartFrame.Size = New XSize(500, 500)
    37. chartFrame.Add(chart_1)
    38. 'XXXXXXXXXXXXX ABSTURZ XXXXXXXXXXXXX
    39. chartFrame.Draw(gfx) '
    40. ' Save the document...
    41. Dim filename As String = "TestChart.pdf"
    42. document.Save(filename)
    43. ' ...and start a viewer.
    44. Process.Start(filename)
    45. End Sub
    46. End Class
    Bilder
    • Bild 1.png

      11,77 kB, 545×311, 116 mal angesehen
    Dateien