PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XY scatter chart
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2243
Page 1 of 1

Author:  cptZap [ Mon Nov 26, 2012 9:20 pm ]
Post subject:  XY scatter chart

Is there a way to create an XY scatter plot using MigraDoc/PDFsharp? As far as I can tell, the x-axis must contain an array of Strings. Alternatively, is there a way to add a chart from ZedGraph or some other package?

Thanks in advance for any help.

Author:  Thomas Hoevel [ Tue Nov 27, 2012 9:49 am ]
Post subject:  Re: XY scatter chart

cptZap wrote:
Alternatively, is there a way to add a chart from ZedGraph or some other package?
If the chart is a PDF or an image (e.g. PNG), you can add it to PDF files created with PDFsharp or MigraDoc.

Author:  rwest500 [ Mon Jun 15, 2015 4:08 am ]
Post subject:  Re: XY scatter chart

In case anyone else is looking for a quick way to add XY Plotting I've attached some patch files for version 1.32 here.
Its an unofficial quick fix but it might be all you need.
In MigraDoc and PDFSharp I've implemented a 'PointX' class and added support for it Series and Series Element.
In PDFSharp I've modified some renderers to recognize these and draw them.

In the patch files I've added a method Series.Add( double x, double y )
Here is a pseudocode example below of how to use it.
Assuming you have some an array of point structures having properties x and y
Thanks PDFSharp Team for sharing this codebase.
Good luck.

Code:
            Chart chart = new Chart();
            chart.Left = 0;
            chart.Width = Unit.FromCentimeter(16);
            chart.Height = Unit.FromCentimeter(12);
           
            chart.XAxis.MinimumScale = 0;
            chart.XAxis.MaximumScale = YOUR_MAX_X;
            chart.XAxis.MajorTickMark = TickMarkType.None;
            chart.XAxis.Title.Caption = "X_AXIS";
            chart.XAxis.MajorTick = 100; // your interval
         
            chart.YAxis.MajorTickMark = TickMarkType.Outside;
            chart.YAxis.HasMajorGridlines = true;

            chart.PlotArea.LineFormat.Color = Colors.DarkGray;
            chart.PlotArea.LineFormat.Width = 1;

         
            Series series = chart.SeriesCollection.AddSeries();
            series.ChartType = ChartType.Line;
            series.MarkerStyle = MarkerStyle.None;
            foreach( MyDataPoint pt in  MyPoints)
            {
                    series.Add(pt.X, pt.Y );
            }


            document.LastSection.Add(chart);


Attachments:
File comment: Patch files for Series.Add(x,y)
PDFSharp_XYPlot.zip [23.01 KiB]
Downloaded 657 times

Author:  rex [ Thu Feb 04, 2016 2:46 am ]
Post subject:  Re: XY scatter chart

How can I patch the files? I also need to use scatter chart

Author:  rwest5000 [ Sun Feb 07, 2016 4:30 pm ]
Post subject:  Re: XY scatter chart

You have to download the attached zip file. Update the source with files from the zip. Recompile the library.

Author:  kyleung3897 [ Thu Jul 08, 2021 12:21 am ]
Post subject:  Re: XY scatter chart

Hi, I realize this is a really old post, but I'm trying to get scatter charts to work.

I've downloaded 1.50 Beta 5 and applied the zip changes. Had to make a few modifications, as the base code has changed.

It runs, but when I try to create a scatter chart, all I get in the PDF output is:
Quote:
{"message":"Field '_lineFormat' defined on type 'MigraDoc.DocumentObjectModel.Shapes.Charts.Point' is not a field on the target object which is of type 'MigraDoc.DocumentObjectModel.Shapes.Charts.PointX'."}


I can't find where this is coming from the code. Anyone know what this means and/or how to resolve?

Thanks.

Author:  west500 [ Sat Aug 12, 2023 3:05 am ]
Post subject:  Re: XY scatter chart

I've ported the XY patch to a fork on GitHub and tested it on .NET 7.0.
It works for me.

Here is the link:
https://github.com/rwest500/PDFsharp.git

Good luck!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/