Annotations shift at print AND print preview

TeeChart for ActiveX, COM and ASP
Post Reply
jetgeek
Newbie
Newbie
Posts: 13
Joined: Thu Dec 02, 2004 5:00 am

Annotations shift at print AND print preview

Post by jetgeek » Tue Feb 28, 2006 4:55 am

Howdy,

I have scoured the posts for a solution to keep the annotiations from moving at print time. I display the selected PIE labels based on some very good code found in this forum to put the label for each PIE at the xcenter and ycenter. BUT, when we go to print this chart thru VB common dialog OR the print preview TEECOMMANDER, the annotations "fly around" the canvas. So, again I found some code snippets on this forum to reference the left and top axis as the starting points WHEN a var we called m_bChartIsPrinting = True. The QA staff is testing on various printiers and the annotations are non-existant OR tucked up into the top left-hand corner of the print out (we have 3 pies max).

I have a "Private Sub DrawAnnotations()" that gets called in the TChart1_OnBeforeDrawSeries() sub. The printouts here at our office on an HP4550 and the MS image writer (ms software printer) work fine (i.e. the annotations line-up ok), but at the QA shop they go bye-bye OR take an upper-corner nap. But, then again, I made some "tweeks" to the code to make them line-up properly in the OnBeforeDrawSeries at print time...

I get the same print results thru the IDE as well as the EXE.

I give up...gimme a vector, please? :roll:

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Feb 28, 2006 9:14 am

Hi jetgeek,

Could you please try if the example my colleague Pep posted at the public newsgroups works for you? The example is at news://www.steema.net/steema.public.attachments newsgroup. The thread is called "Still not printing".
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jetgeek
Newbie
Newbie
Posts: 13
Joined: Thu Dec 02, 2004 5:00 am

Post by jetgeek » Tue Feb 28, 2006 1:57 pm

Narcís,

Tanks for the fast reply! Yes, deadlines abound...

Yes, I have used that code, and it prints correctly on my printer. My code looks like this:
Private Sub DrawAnnotations()
On Error GoTo ErrRoutine

If m_enuChartType = CHT_PERF_STD_PIE_CUSTOM Then
1
Dim XCenter As Integer, YCenter As Integer, SeriesIndex As Integer, xwidth As Integer, ywidth As Integer

Dim xctr As Integer
Dim yctr As Integer
5
With TChart1
If Not m_bChartIsPrinting Then
.Environment.InternalRepaint
DoEvents
End If
10
For SeriesIndex = 0 To .SeriesCount - .Tools.Count - 1
.Tools.Add tcAnnotate
Next 'SeriesIndex
15
For SeriesIndex = 0 To .Tools.Count - 1
.Tools.Items(SeriesIndex).Active = False
Next 'SeriesIndex
20
For SeriesIndex = 0 To .SeriesCount - 1
If m_bChartIsPrinting Then
Select Case SeriesIndex
Case 0
XCenter = .Axis.Left.Position + (.Axis.Right.Position - .Axis.Left.Position) / 3
YCenter = .Axis.Top.Position + (.Axis.Bottom.Position - .Axis.Top.Position) / 4
Case 1
XCenter = .Axis.Left.Position + 2 * (.Axis.Right.Position - .Axis.Left.Position) / 3
YCenter = .Axis.Top.Position + (.Axis.Bottom.Position - .Axis.Top.Position) / 4
Case 2
XCenter = .Axis.Left.Position + (.Axis.Right.Position - .Axis.Left.Position) / 3
YCenter = .Axis.Top.Position + 3 * (.Axis.Bottom.Position - .Axis.Top.Position) / 4
Case 3
XCenter = .Axis.Left.Position + 2 * (.Axis.Right.Position - .Axis.Left.Position) / 3
YCenter = .Axis.Top.Position + 3 * (.Axis.Bottom.Position - .Axis.Top.Position) / 4
End Select
25
Else
XCenter = .Series(SeriesIndex).asPie.XCenter
YCenter = .Series(SeriesIndex).asPie.YCenter
30
xwidth = .Series(SeriesIndex).asPie.CircleWidth
ywidth = .Series(SeriesIndex).asPie.CircleHeight
40
If .SeriesCount = 2 And SeriesIndex = 1 Then
YCenter = .Series(SeriesIndex).asPie.YCenter '- ywidth / 6
45
ElseIf .SeriesCount = 3 And SeriesIndex = 2 Then
YCenter = .Series(SeriesIndex).asPie.YCenter '- ywidth / 6
50
End If
55
End If

.Tools.Items(SeriesIndex).Active = True
60
.Tools.Items(SeriesIndex).asAnnotation.Shape.ShapeStyle = fosRoundRectangle
.Tools.Items(SeriesIndex).asAnnotation.Shape.Font.Color = vbBlue
.Tools.Items(SeriesIndex).asAnnotation.Shape.Font.Bold = True
.Tools.Items(SeriesIndex).asAnnotation.Shape.CustomPosition = True
70
.Tools.Items(SeriesIndex).asAnnotation.Shape.Left = XCenter
.Tools.Items(SeriesIndex).asAnnotation.Shape.Top = YCenter
.Tools.Items(SeriesIndex).asAnnotation.Text = .Series(SeriesIndex).Title

Next SeriesIndex

End With
100
End If
Exit Sub
ErrRoutine:
Call HandleError(Erl, ConvertErrToTPCError(Err), "frmRG_CHART:DrawAnnotations")
End Sub

I am using the size of the axis size in the vert and horz dir to setup some sort of proportionality during printing...

Basically, I use this routine during the resize event (without it the mdi child that carries the tchart freaks out) due to the fact there is an infragistics resizer control doing the resize. I have tried this without the resizer--same results.

Tanks again.

jetgeek
Newbie
Newbie
Posts: 13
Joined: Thu Dec 02, 2004 5:00 am

Post by jetgeek » Tue Feb 28, 2006 3:05 pm

I uploaded the code to news://www.steema.net/steema.public.attachments and the subject is: "Annotations Shift At Print Time". I got it to break! I now prints the annotations shifted OFF the shown path. DOH! I fogot to remove the Infragistics Resizer control from the project...I tried it w/ and w/o--same results: The left-upper-corner shuffle!

Tanks!

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Mar 02, 2006 10:04 am

Hi,

could you please check with the following code ? I've just test it here and the labels print ok (to test just create a new vb project, place a chart component and add the code) :

Code: Select all

Private Sub Command1_Click()
TChart1.Printer.PrintChart

End Sub

Private Sub Form_Load()
With TChart1
    .Legend.Visible = False
    .AddSeries scPie
    .AddSeries scPie
    .AddSeries scPie
    .Series(0).FillSampleValues (4)
    .Series(1).FillSampleValues (4)
    .Series(2).FillSampleValues (4)
    .Tools.Add (tcAnnotate)
    .Tools.Add (tcAnnotate)
    .Tools.Add (tcAnnotate)    
End With
End Sub


Private Sub TChart1_OnBeforeDrawSeries()

With TChart1.Tools.Items(0).asAnnotation
.Text = "Series1"
.Shape.Font.Name = "Arial"
.Shape.Font.Color = vbBlack
.Shape.Left = TChart1.Axis.Left.Position + 140
.Shape.Top = TChart1.Axis.Top.Position + 115
End With

With TChart1.Tools.Items(1).asAnnotation
.Text = "Series2"
.Shape.Font.Name = "Arial"
.Shape.Font.Color = vbBlack
.Shape.Left = TChart1.Axis.Left.Position + 460
.Shape.Top = TChart1.Axis.Top.Position + 115
End With

With TChart1.Tools.Items(2).asAnnotation
.Text = "Series3"
.Shape.Font.Name = "Arial"
.Shape.Font.Color = vbBlack
.Shape.Left = TChart1.Axis.Left.Position + 140
.Shape.Top = TChart1.Axis.Top.Position + 200
End With
End Sub

jetgeek
Newbie
Newbie
Posts: 13
Joined: Thu Dec 02, 2004 5:00 am

Post by jetgeek » Thu Mar 02, 2006 4:33 pm

Pep,

WHAHOOOOOOOO!

Got it to work the best by using PERCENT versus pixels and basing the values on the number of PIEs available. We have a total of THREE (3) at any one time down to only ONE (1) PIE. So, we use the delete function to get rid of the PIEs without data (i.e. Recordset is used for three series of data, if the YVALUETOTAL=0, delete the series!).
So, we need to place the ANNOTATIONS differently at each condition. Here is the code I came up with:

Private Sub DrawAnnotations()
On Error GoTo ErrRoutine

If m_enuChartType = CHT_PERF_STD_PIE_CUSTOM Then
1
Dim XCenter As Integer, YCenter As Integer, SeriesIndex As Integer, xwidth As Integer, ywidth As Integer

Dim xctr As Integer
Dim yctr As Integer
5
With TChart1
'Hide what we don't need...
For SeriesIndex = 0 To .Tools.Count - 1
.Tools.Items(SeriesIndex).Active = False
Next 'SeriesIndex
10
'Now show the series annotations for series which are visible...
For SeriesIndex = 0 To .SeriesCount - 1
.Tools.Items(SeriesIndex).Active = True
15
Select Case .SeriesCount
Case 1
XCenter = 50 + IIf(m_bChartIsPrinting = True, 5, 0)
YCenter = 50 + IIf(m_bChartIsPrinting = True, 5, 0)
20
Case 2
Select Case SeriesIndex
Case 0
XCenter = 50 + IIf(m_bChartIsPrinting = True, 5, 0)
YCenter = 45 + IIf(m_bChartIsPrinting = True, 5, 0)
Case 1
XCenter = 50 + IIf(m_bChartIsPrinting = True, 5, 0)
YCenter = 64 + IIf(m_bChartIsPrinting = True, 5, 0)
End Select
30
Case 3
Select Case SeriesIndex
Case 0
XCenter = 30 + IIf(m_bChartIsPrinting = True, 5, 0)
YCenter = 45 + IIf(m_bChartIsPrinting = True, 5, 0)
Case 1
XCenter = 68 + IIf(m_bChartIsPrinting = True, 5, 0)
YCenter = 45 + IIf(m_bChartIsPrinting = True, 5, 0)
Case 2
XCenter = 30 + IIf(m_bChartIsPrinting = True, 5, 0)
YCenter = 64 + IIf(m_bChartIsPrinting = True, 5, 0)
End Select
40
End Select

.Tools.Items(SeriesIndex).asAnnotation.Shape.ShapeStyle = fosRoundRectangle
.Tools.Items(SeriesIndex).asAnnotation.Shape.Font.Color = vbBlue
.Tools.Items(SeriesIndex).asAnnotation.Shape.Font.Bold = True
.Tools.Items(SeriesIndex).asAnnotation.Shape.CustomPosition = True
.Tools.Items(SeriesIndex).asAnnotation.Shape.Left = XCenter
.Tools.Items(SeriesIndex).asAnnotation.Shape.Top = YCenter
.Tools.Items(SeriesIndex).asAnnotation.Text = .Series(SeriesIndex).Title
50
Next 'SeriesIndex

End With
End If
Exit Sub

I had to put in a FUDGE factor of 5% when it prints, no matter what printer they used, it kinda went off center at the printer refreshed time of printing the chart.

Thanks for the excellent and fast responses! 8)

P.S. Can you answer our Black And White Printer issue we posted the other day???? :)

Post Reply