none
Problem with output of System.Windows.Forms.DataVisualization.Charting.Chart.SaveImage() RRS feed

  • Question

  • I'm generating a simple stacked area chart using System.Windows.Forms.DataVisualization.Charting.Chart, then saving the output as EMF. I am seeing problems with the output files, which is somewhat dependent on the renderer.

    If I load the EMF into Inkscape, or insert the EMF into Word and export the document as a PDF, or print to PostScript and convert to PDF, I see thin vertical lines of the chartarea background between the columns (I have verified this by setting chartarea backcolor). If I edit the path in the EMF that makes up a column, and set the stroke of the path to the same colour as the fill, the problem goes away.

    Is this a known issue, and/or are there any solutions or workarounds? I've tried EMFPlus (and EMFDual) as formats, but the same problem occurs. The quality of rasterised formats is not good enough; I really need to export as a vector format.

    My testbed code is below. Excuse the deliberately disgusting colours! :)

     var chartArea1 = new ChartArea("my area");
                chartArea1.BackColor = Color.Yellow;
                chart1.Size = new Size(1024, 768);

                chart1.BackColor = Color.Purple;
                chart1.ForeColor = Color.Purple;

                chart1.ChartAreas.Clear();
                chart1.ChartAreas.Add(chartArea1);
                chart1.Name = "chart1";

                chart1.TabIndex = 0;
                chart1.Text = "chart1";
                chart1.Series.Clear();
                chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
                chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;

                var series1 = new Series
                {
                    Name = "Series1",
                    Color = Color.Green,
                    IsVisibleInLegend = false,
                    IsXValueIndexed = false,
                    ChartType = SeriesChartType.StackedArea,
                    XAxisType = AxisType.Primary,
                };

                series1.XAxisType = AxisType.Primary;
                series1.XValueType = ChartValueType.Auto;


                chart1.Series.Add(series1);

                for (var i = 0; i < 10; i++)
                {
                    series1.Points.AddXY(i, 1); //f(i));
                }

                var series2 = new Series
                {
                    Name = "Series2",
                    Color = Color.Red,
                    IsVisibleInLegend = false,
                    IsXValueIndexed = false,
                    ChartType = SeriesChartType.StackedArea
                };

                chart1.Series.Add(series2);

                for (var i = 0; i < 10; i++)
                {
                    series2.Points.AddXY(i, 2); //f(i));
                }

                chart1.Invalidate();

    chart1.SaveImage("out.emf", ChartImageFormat.Emf);



    Thanks,



    Chris





    Monday, May 14, 2018 10:39 AM

Answers

  • Hi Wendy

    Thanks for your response.

    It turns out that this is a render problem that affects various PDF viewers, including Acrobat Reader. It occurs when the PDF Viewer tries to smooth /anti-alias vector graphics. See https://helpx.adobe.com/indesign/kb/thin-white-dark-lines-stitching.html, for example. It is solved by turning off line-art smoothing in the viewer (e.g. in Acrobat Reader, go to Edit > Preferences > Page Display, and uncheck Smooth line art).

    Not every viewer reproduces it reliably, and it depends on zoom levels.

    For completeness, I inserted the EMF into Word using Insert ribbon > Pictures, then created the PDF using Export > Create XPS/PDF Document, using the Standard profile.

    I will mark this as resolved.

    Chris

    Tuesday, May 15, 2018 1:31 PM

All replies

  • Hi Chris Bradfield,

    Thank you for posting here.

    For your question, I test the code you provided to get a emf file.

    >>insert the EMF into Word and export the document as a PDF

    How do you do this? Using C# code?

    I insert the .emf file to word.

    And then save this word as pdf.

    All works well. There is no thin vertical lines of the chartarea background between the columns.

    Please provide more details about this.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 15, 2018 8:23 AM
    Moderator
  • Hi Wendy

    Thanks for your response.

    It turns out that this is a render problem that affects various PDF viewers, including Acrobat Reader. It occurs when the PDF Viewer tries to smooth /anti-alias vector graphics. See https://helpx.adobe.com/indesign/kb/thin-white-dark-lines-stitching.html, for example. It is solved by turning off line-art smoothing in the viewer (e.g. in Acrobat Reader, go to Edit > Preferences > Page Display, and uncheck Smooth line art).

    Not every viewer reproduces it reliably, and it depends on zoom levels.

    For completeness, I inserted the EMF into Word using Insert ribbon > Pictures, then created the PDF using Export > Create XPS/PDF Document, using the Standard profile.

    I will mark this as resolved.

    Chris

    Tuesday, May 15, 2018 1:31 PM