Discussion:
Problems with MSChart1.EditCopy .. not respecting the properties of X Axis
(too old to reply)
AGarza
2004-11-29 17:32:00 UTC
Permalink
I have a big problem for me ... maybe single for you ...
I have to print a MSChart an I am ussing the next code to print it.

MSChart1.editcopy
printer.paintpicture clipboard.getdata(),0,0
printer.enddoc

This MSChart1 is a XY Chart, previously I modify the properties XY
With MSChart1.Plot
(*).Axis(VtChAxisIdX).ValueScale.Auto = False
(*).Axis(VtChAxisIdX).ValueScale.Minimum = Format(txt_x_min, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.Maximum = Format(txt_x_max, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.MinorDivision = 1
(*).Axis(VtChAxisIdX).ValueScale.MajorDivision = 3

.Axis(VtChAxisIdY).ValueScale.Auto = False
.Axis(VtChAxisIdY).ValueScale.Minimum = Format(txt_y_min, "0.00")
.Axis(VtChAxisIdY).ValueScale.Maximum = Format(txt_y_max, "0.00")
.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
.Axis(VtChAxisIdY).ValueScale.MajorDivision = 3
End With

Finally, I see the MSchart1 it's ok in my form.. but the problem is
when I send it to print MSChart1.EditCopy, the print chart it's OK in
the "Y" Axis, but doesn't respecting the origin properties of "X"
Axis. (*****)

Can you help me ...
Thanks, I have invested a lot of time learning all about this control,
and it makes me sad that I can't obtain the wished results

Ana Garza
Monterrey Mexico
Mike D Sutton
2004-11-29 18:15:11 UTC
Permalink
Post by AGarza
I have a big problem for me ... maybe single for you ...
I have to print a MSChart an I am ussing the next code to print it.
<code snipped>
Post by AGarza
Finally, I see the MSchart1 it's ok in my form.. but the problem is
when I send it to print MSChart1.EditCopy, the print chart it's OK in
the "Y" Axis, but doesn't respecting the origin properties of "X"
Axis. (*****)
Can you help me ...
Thanks, I have invested a lot of time learning all about this control,
and it makes me sad that I can't obtain the wished results
I'm unfamiliar with the control so I don't know if there's some functionality it exposes for getting at the image it displays,
however one thing you may want to try is to get the control to paint itself either into another image and then blit that to the
printer or make it draw directly to the printer (depending on how it's performing it's drawing this may not be possible as not all
the GDI commands work as expected on a printer DC.)
Have a look at the WM_PRINT/WM_PAINT/WM_PRINTCLIENT messages however if the control doesn't support them properly then you may need
to look at this article on the subject:
http://www.fengyuan.com/article/wmprint.html
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ***@mvps.org
WWW: Http://EDais.mvps.org/
Mike D Sutton
2004-11-29 19:27:13 UTC
Permalink
Post by Mike D Sutton
I'm unfamiliar with the control so I don't know if there's some functionality it exposes for getting at the image it displays,
however one thing you may want to try is to get the control to paint itself either into another image and then blit that to the
printer or make it draw directly to the printer (depending on how it's performing it's drawing this may not be possible as not all
the GDI commands work as expected on a printer DC.)
Have a look at the WM_PRINT/WM_PAINT/WM_PRINTCLIENT messages however if the control doesn't support them properly then you may
need
Post by Mike D Sutton
http://www.fengyuan.com/article/wmprint.html
For anyone else following the thread, here's a page from the MSDN (from the OP) that demonstrates the proposed solution.
http://support.microsoft.com/kb/q197487/
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ***@mvps.org
WWW: Http://EDais.mvps.org/
Christoph Basedau
2004-12-08 06:43:34 UTC
Permalink
29.11.2004 18:32, AGarza schrieb:

I also did have a hard time with printing MSChart with the
method mentioned below (EditCopy->Printer.Picture)
Looks like there is a lot of auto-converting going on.
I finally found out, that i get nicer and more appropriate results
concerning label formats and also legendtext and some other features
which get lost along the Copy & Paste process, if I *simply*
*use* *PrintForm*.
The only thing to do was to hide the other controls before printing
by moving the MSChart to 0,0 and then shrinking the Form to the Charts
Width and Height.
In order to not making it look very strange, I created a new form for
printing with: Set frmPrint = New frmChart
toggled Visibility to False, and applied all the settings once again to the
Chart on frmPrint, which was actually only one methods call.

I know PrintForm is generally a depreciated way for printing in VB.
But under these circumstances it worked better.
Still some features did not get printed out, e.g. I used dotted lines for
AxisGrids which became straight lines on printing.
MSChart is very strange is some respects, for example if you print the
Chart with EditCopy+Printer.Picture the LegendText for Series is missed out
and is reset to "S1" or something, if it's set by:
SeriesCollection(index).LegendText = "LegendText"
but it is printed out if it is set by:
DataGrid.ColumnLabes(ColIndex,LabelLevel) = "LegendText"

MS should definitely have fixed some bugs after the release in 1998.
Post by AGarza
I have a big problem for me ... maybe single for you ...
I have to print a MSChart an I am ussing the next code to print it.
MSChart1.editcopy
printer.paintpicture clipboard.getdata(),0,0
printer.enddoc
This MSChart1 is a XY Chart, previously I modify the properties XY
With MSChart1.Plot
(*).Axis(VtChAxisIdX).ValueScale.Auto = False
(*).Axis(VtChAxisIdX).ValueScale.Minimum = Format(txt_x_min, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.Maximum = Format(txt_x_max, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.MinorDivision = 1
(*).Axis(VtChAxisIdX).ValueScale.MajorDivision = 3
.Axis(VtChAxisIdY).ValueScale.Auto = False
.Axis(VtChAxisIdY).ValueScale.Minimum = Format(txt_y_min, "0.00")
.Axis(VtChAxisIdY).ValueScale.Maximum = Format(txt_y_max, "0.00")
.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
.Axis(VtChAxisIdY).ValueScale.MajorDivision = 3
End With
Finally, I see the MSchart1 it's ok in my form.. but the problem is
when I send it to print MSChart1.EditCopy, the print chart it's OK in
the "Y" Axis, but doesn't respecting the origin properties of "X"
Axis. (*****)
Did you try how it works if you don't set the values programmtically on runtime
but rather in properties-dialog on design-time?
Post by AGarza
Can you help me ...
Thanks, I have invested a lot of time learning all about this control,
and it makes me sad that I can't obtain the wished results
Ana Garza
Monterrey Mexico
--
Gruesse, Christoph

Rio Riay Riayo - Gordon Sumner, 1979
flop
2004-12-14 19:09:26 UTC
Permalink
Post by AGarza
I have a big problem for me ... maybe single for you ...
I have to print a MSChart an I am ussing the next code to print it.
MSChart1.editcopy
printer.paintpicture clipboard.getdata(),0,0
printer.enddoc
This MSChart1 is a XY Chart, previously I modify the properties XY
With MSChart1.Plot
(*).Axis(VtChAxisIdX).ValueScale.Auto = False
(*).Axis(VtChAxisIdX).ValueScale.Minimum = Format(txt_x_min, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.Maximum = Format(txt_x_max, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.MinorDivision = 1
(*).Axis(VtChAxisIdX).ValueScale.MajorDivision = 3
.Axis(VtChAxisIdY).ValueScale.Auto = False
.Axis(VtChAxisIdY).ValueScale.Minimum = Format(txt_y_min, "0.00")
.Axis(VtChAxisIdY).ValueScale.Maximum = Format(txt_y_max, "0.00")
.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
.Axis(VtChAxisIdY).ValueScale.MajorDivision = 3
End With
Finally, I see the MSchart1 it's ok in my form.. but the problem is
when I send it to print MSChart1.EditCopy, the print chart it's OK in
the "Y" Axis, but doesn't respecting the origin properties of "X"
Axis. (*****)
Can you help me ...
Thanks, I have invested a lot of time learning all about this control,
and it makes me sad that I can't obtain the wished results
Ana Garza
Monterrey Mexico
This is the method I use. It provides the best looking output I have
found so far. This is used in VB6.
Editcopy, in my expericence, will cause a memory leak on win9x
systems. I was never able to pin down the problem so that it was 100%
reproducable, but it happened enough that it caused me heartache.
This method has given me no problems (so far)

'-----------------------------------------------------------------
'Add these two items to the declarations sections of the form/module

Type RECTL
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Declare Function OleDraw Lib "ole32.dll" _
(ByVal pUnk As Object, ByVal dwAspect As Long, _
ByVal hdcDraw As Long, lprcBounds As RECTL) As Long

'--------------------------------------------------------------------
'Add this to the same form/module
'you may have to reconstruct some of these lines due to word wrapping
'of the newsreader.

Sub PrintChart()
Dim LngRet As Long
Dim RC As RECTL

On Error GoTo CantPrint

Screen.MousePointer = vbHourglass

'PrintInLandscape is a flag I use elsewhere in the
'program to allow the user to change the printout
If PrintInLandscape = True Then
Printer.Orientation = vbPRORLandscape
Else
Printer.Orientation = vbPRORPortrait
End If

DoEvents


Printer.ScaleMode = vbTwips
'Adds a little space to keep labels from cropping
RC.Top = 100
RC.Left = 100
RC.Right = (Printer.ScaleWidth / Printer.TwipsPerPixelX) -
200
RC.Bottom = (Printer.ScaleHeight / Printer.TwipsPerPixelY) -
200


'turn off any selections, so they don't show up on the printout
Form_Graph.Chart_Den.AllowSelections = False
Form_Graph.Chart_Den.Enabled = False

DoEvents
'printing a space ensures the enddoc will work
Printer.Print " "
LngRet = OleDraw(Form_Graph.Chart_Den.Object, 1, Printer.hDC,
RC)
Printer.EndDoc

DoEvents

Screen.MousePointer = vbDefault
Form_Graph.Chart_Den.AllowSelections = True
Form_Graph.Chart_Den.Enabled = True
Exit Sub

CantPrint:
'you could probably do better than this....
MsgBox "Error " & Format$(Err) & " (" & Error$ & ") " & vbLf &
"While trying to print. Exiting Print Sub."
Screen.MousePointer = vbDefault
Form_Graph.Chart_Den.AllowSelections = True
Form_Graph.Chart_Den.Enabled = True
Exit Sub
'-------------------------------------------------------------

Then all to have to do is put a call to the Printchart sub in your
program
flop
2004-12-14 20:25:45 UTC
Permalink
Post by flop
Post by AGarza
I have a big problem for me ... maybe single for you ...
I have to print a MSChart an I am ussing the next code to print it.
MSChart1.editcopy
printer.paintpicture clipboard.getdata(),0,0
printer.enddoc
This MSChart1 is a XY Chart, previously I modify the properties XY
With MSChart1.Plot
(*).Axis(VtChAxisIdX).ValueScale.Auto = False
(*).Axis(VtChAxisIdX).ValueScale.Minimum = Format(txt_x_min, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.Maximum = Format(txt_x_max, "0.00")
(*).Axis(VtChAxisIdX).ValueScale.MinorDivision = 1
(*).Axis(VtChAxisIdX).ValueScale.MajorDivision = 3
.Axis(VtChAxisIdY).ValueScale.Auto = False
.Axis(VtChAxisIdY).ValueScale.Minimum = Format(txt_y_min, "0.00")
.Axis(VtChAxisIdY).ValueScale.Maximum = Format(txt_y_max, "0.00")
.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
.Axis(VtChAxisIdY).ValueScale.MajorDivision = 3
End With
Finally, I see the MSchart1 it's ok in my form.. but the problem is
when I send it to print MSChart1.EditCopy, the print chart it's OK in
the "Y" Axis, but doesn't respecting the origin properties of "X"
Axis. (*****)
Can you help me ...
Thanks, I have invested a lot of time learning all about this control,
and it makes me sad that I can't obtain the wished results
Ana Garza
Monterrey Mexico
This is the method I use. It provides the best looking output I have
found so far. This is used in VB6.
Editcopy, in my expericence, will cause a memory leak on win9x
systems. I was never able to pin down the problem so that it was 100%
reproducable, but it happened enough that it caused me heartache.
This method has given me no problems (so far)
'-----------------------------------------------------------------
'Add these two items to the declarations sections of the form/module
Type RECTL
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function OleDraw Lib "ole32.dll" _
(ByVal pUnk As Object, ByVal dwAspect As Long, _
ByVal hdcDraw As Long, lprcBounds As RECTL) As Long
'--------------------------------------------------------------------
'Add this to the same form/module
'you may have to reconstruct some of these lines due to word wrapping
'of the newsreader.
Sub PrintChart()
Dim LngRet As Long
Dim RC As RECTL
On Error GoTo CantPrint
Screen.MousePointer = vbHourglass
'PrintInLandscape is a flag I use elsewhere in the
'program to allow the user to change the printout
If PrintInLandscape = True Then
Printer.Orientation = vbPRORLandscape
Else
Printer.Orientation = vbPRORPortrait
End If
DoEvents
Printer.ScaleMode = vbTwips
'Adds a little space to keep labels from cropping
RC.Top = 100
RC.Left = 100
RC.Right = (Printer.ScaleWidth / Printer.TwipsPerPixelX) -
200
RC.Bottom = (Printer.ScaleHeight / Printer.TwipsPerPixelY) -
200
'turn off any selections, so they don't show up on the printout
Form_Graph.Chart_Den.AllowSelections = False
Form_Graph.Chart_Den.Enabled = False
DoEvents
'printing a space ensures the enddoc will work
Printer.Print " "
LngRet = OleDraw(Form_Graph.Chart_Den.Object, 1, Printer.hDC,
RC)
Printer.EndDoc
DoEvents
Screen.MousePointer = vbDefault
Form_Graph.Chart_Den.AllowSelections = True
Form_Graph.Chart_Den.Enabled = True
Exit Sub
'you could probably do better than this....
MsgBox "Error " & Format$(Err) & " (" & Error$ & ") " & vbLf &
"While trying to print. Exiting Print Sub."
Screen.MousePointer = vbDefault
Form_Graph.Chart_Den.AllowSelections = True
Form_Graph.Chart_Den.Enabled = True
Exit Sub
'-------------------------------------------------------------
Then all to have to do is put a call to the Printchart sub in your
program
and change form_graph to the name of your form and chart_den to the
name of your chart control, of course.

Loading...