0
votes

I am drawing a pie chart with CorePlot, which I am turning into a PDF for viewing, printing and emailing. All this works fine, except that when I add a borderLineStyle I also get artefacts around the edges of the pie chart.

You don't really notice them on the iPhone's screen, or when printed, but when emailed and viewed on a large screen (in acrobat reader) they are immediately obvious. This screenshot is zoomed to 400%, but they are clearly visible at 100% too. You can see the clipping artefacts on both the inside and outside of the pie chart.

CPTPieChart with artifacts round the edges

If I leave off the borderLineStyle then the pie chart is nice and clean. The artefacts only show up when the line style is set. Which I do like this:

CPTMutableLineStyle *segmentLineStyle = [CPTMutableLineStyle lineStyle];
segmentLineStyle.lineColor = colour;
segmentLineStyle.lineWidth = size;
_pieChart.borderLineStyle = segmentLineStyle;

To me they look like clipping or dithering artefacts, so I tried setting background colours and the graph fill to white or clear, but this makes no difference.

I am using CorePlot 1.1. Does anyone have any ideas why this is happening? Any help would be much appreciated.

Thanks.

1
Are you using an overlay layer or a shadow? Core Graphics renders to an old PDF format that doesn't support transparency. - Eric Skroch
Thanks Eric, I do use an overlay, but I have tried without, which makes no difference :( - AW101

1 Answers

0
votes

To answer my own question. Thanks to Eric's hint that Core Graphics renders to an old PDF format that doesn't support transparencies, I thought I would change the way I was rending the pie chart.

Previously I was simply rendering the pie chart into the pdf context, like this:

CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[pieChartView.layer renderInContext:pdfContext];

Now I am first rendering the pie chart to a UIImage and then rendering the image to the pdf context. Like this:

// Pre-render the pie chart into a temporary UIImage
UIGraphicsBeginImageContextWithOptions (pieChartView.frame.size, YES, 0.0f);
CGContextRef tmpContext = UIGraphicsGetCurrentContext();
[pieChartView.layer renderInContext:tmpContext];
UIImage *pieChartTmpImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Draw the pre-rendered pie chart in to the PDF context.
[pieChartTmpImage drawInRect:CGRectMake(0, 0, pieChartTmpImage.size.width, pieChartTmpImage.size.height)];

This now renders the pie chart cleanly :)

It is worth pointing out that the pdf context is already established when this code runs and the temporary image context is nested, but that is fine.