当我打印使用DataVisualistion.Charting.Chart类生成的区域类型图表到PDF时,会引入一些奇怪的线条,它们是原始图像的一部分。我该怎样摆脱这些?
当转换为PDF或XPS时,所有打印输出上都会出现这些线条。到目前为止,我已经尝试过CutePDF,Postscript - > Adobe,XPS打印机。
考虑以下代码,可以将其粘贴到新表单中,以便快速重新创建。
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Friend WithEvents Chart1 As System.Windows.Forms.DataVisualization.Charting.Chart
Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub IC()
Me.Button1 = New System.Windows.Forms.Button()
Dim ChartArea1 As System.Windows.Forms.DataVisualization.Charting.ChartArea = New System.Windows.Forms.DataVisualization.Charting.ChartArea()
Dim Legend1 As System.Windows.Forms.DataVisualization.Charting.Legend = New System.Windows.Forms.DataVisualization.Charting.Legend()
Dim Series1 As System.Windows.Forms.DataVisualization.Charting.Series = New System.Windows.Forms.DataVisualization.Charting.Series()
Dim Series2 As System.Windows.Forms.DataVisualization.Charting.Series = New System.Windows.Forms.DataVisualization.Charting.Series()
Me.Chart1 = New System.Windows.Forms.DataVisualization.Charting.Chart()
CType(Me.Chart1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.Chart1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
ChartArea1.Name = "ChartArea1"
Me.Chart1.ChartAreas.Add(ChartArea1)
Legend1.Name = "Legend1"
Me.Chart1.Legends.Add(Legend1)
Me.Chart1.Location = New System.Drawing.Point(12, 12)
Me.Chart1.Name = "Chart1"
Series1.ChartArea = "ChartArea1"
Series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea
Series1.Legend = "Legend1"
Series1.Name = "Series1"
Series2.ChartArea = "ChartArea1"
Series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea
Series2.Legend = "Legend1"
Series2.Name = "Series2"
Me.Chart1.Series.Add(Series1)
Me.Chart1.Series.Add(Series2)
Me.Chart1.Size = New System.Drawing.Size(553, 343)
Me.Chart1.TabIndex = 0
Me.Chart1.Text = "Chart1"
Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.Location = New System.Drawing.Point(571, 118)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(127, 47)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Print"
Me.Button1.UseVisualStyleBackColor = True
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(710, 367)
Me.Controls.Add(Me.Chart1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.Chart1, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
IC()
Dim generator As New Random
GenData(generator, Me.Chart1.Series(0))
GenData(generator, Me.Chart1.Series(1))
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim PD As New PrintDialog
Dim OK As Boolean = PD.ShowDialog()
If OK Then
Me.Chart1.Printing.PrintDocument.PrinterSettings = PD.PrinterSettings
Me.Chart1.Printing.PrintDocument.Print()
End If
End Sub
Function GenData(ByRef generator As Random, ByRef S As Series)
For I As Integer = 1 To 30
Dim randomValue As Integer
randomValue = generator.Next(10, 100)
Dim dp As New DataPoint
dp.XValue = I
dp.YValues = {randomValue}
S.Points.Add(dp)
Next
Return S
End Function
End Class