0

I have the following elements:

1. MigraDoc.DocumentObjectModel.Shapes.Charts.Chart
2. MigraDoc.DocumentObjectModel.Tables.Table

I want to show the data table (2) on the right side of the chart (1). Something like a legend, but with more information. This custom table will give more information than the standard legend.

For some reason, I can add them one above the other by using:

PdfDoc.LastSection.Add(Chart);
PdfDoc.LastSection.Add(Table);

But this is vertical addition. Can I place them horizontally?

1 Answers1

1

There are several ways to position the items horizontally.

Chart is derived from Shape and can be placed at any position (absolute or relative). A table can be placed inside a TextFrame which is also derived from Shape. Shape placement is a bit tricky though.

Most likely I would use a table and place the chart inside one cell of the table. Using MergeDown and maybe MergeRight you can create almost anything.

Example: Your legend needs two columns and six rows. Create a table with three columns and six (or seven) rows, set MergeDown=5 (or 6) for the first cell in the first column. You can set borders only for the cells in columns 2 and 3 and the first six rows. You should use 7 rows if the legend might be shorter than the chart. If you know the legend is longer than the chart then 6 rows will be enough.

Note: MergeDown=5 will create one cell that spans 6 rows.

The Invoice sample shows MergeDown and MergeRight at work:
http://www.pdfsharp.net/wiki/Invoice-sample.ashx

  • Thanks for the idea. However, my case is a bit more trickier. Sorry for not mentioning it earlier. The table which will act as legend extends up to 2 or 3 pages as of now. I have also tried to use some like: pdfChart.RightArea.Add(pdfTable); But, with this loc, the table gets cut off after page 1. – njdotnetdev Oct 13 '15 at 15:03
  • This makes things a bit more complicated, but the approach with the extra column and MergeDown can still be used. You just have to make sure the region used with the MergeDown is small enough to fit on the first page. – I liked the old Stack Overflow Oct 13 '15 at 15:43
  • A table that spans several pages cannot be placed in a TextFrame. You can set the left indentation for the table to leave space on the left for the chart and then use the absolute placement option of shapes to place the chart on the first page beside the table. When doing this, you must make sure there is enough space for the chart on the first page. No problem if you can add a page break before the table. For the chart you have to set `WrapFormat.Style = WrapStyle.Through;`. See also: http://forum.pdfsharp.net/viewtopic.php?p=6922#p6922 – I liked the old Stack Overflow Oct 13 '15 at 15:48
  • Thomas thanks for the help. I guess, am not following you completely. I tried this approach but result wasn't fruitful. Would you have any working example. Also, following was my original issue for which I thought of this work around: -- My pie chart has approximately 100 slices and if legend is being shown(chart.rightarea.addlegend()) it goes out of the chart plot area and looks ugly. To solve this I thought we can create a table for the data and show it as legend on the right side of the chart. – njdotnetdev Oct 15 '15 at 19:05