Page 1 of 1

multiple pies - legend problem

Posted: Sat Sep 03, 2005 2:12 pm
by 9528213
I've got multiples pies (in other word series) on a chart (more than 1 series). When this is the case the legend is of "no value" since there is no way to tell which series are which pie? Is there a way to mark each PIE with series legend?

More info on the subject

Posted: Sat Sep 03, 2005 2:59 pm
by 9528213
I've attempted the following:

Y = 1
While y < NumberOfseries

TChart.Canvas.Brush.Color = RGB(255, 255, 255)
TChart.Canvas.Rectangle 90, 90, 200, 120
TChart.Canvas.Font.Bold = True
TChart.Canvas.TextOut TChart.Series(y - 1).asPie.XCenter, TChart.Series(y - 1).asPie.yCenter, "SERIES LEGEND IS.."
y = y + 1
wend

but the TChart.Series(y - 1).asPie.XCenter and TChart.Series(y - 1).asPie.YCenter are 0 so it does not work.

<B>Any other way to establish center of pies (x and y)?</B>


btw: if I do a

TChart.Canvas.Brush.Color = RGB(255, 255, 255)
TChart.Canvas.Rectangle 90, 90, 200, 120
TChart.Canvas.Font.Bold = True
TChart.Canvas.TextOut 100, 100, "THIS IS A TEST"

nothing is printed. I've got the latest version (7.0..)

any ideas how I can accomplish this?

Posted: Mon Sep 05, 2005 11:11 am
by narcis
Hi Bjørn,

You need to do something like the code below. Using TChart's OnAfterDraw event and retrieve XCenter and YCenter values to a variable before the TextOut statement.

Code: Select all

Private Sub Form_Load()
  With TChart1
    .Legend.Visible = False
    For i = 0 To 3
      .AddSeries scPie
      .Series(i).FillSampleValues 7
      .Series(i).Marks.Style = smsValue
    Next i
  End With
End Sub

Private Sub TChart1_OnAfterDraw()
    Dim XCenter, YCenter As Integer
    With TChart1
      For SeriesIndex = 0 To TChart1.SeriesCount - 1
          XCenter = .Series(SeriesIndex).asPie.XCenter
          YCenter = .Series(SeriesIndex).asPie.YCenter
          .Canvas.TextOut XCenter, YCenter, "Series" + CStr(SeriesIndex)
      Next SeriesIndex
    End With
End Sub

Private Sub TChart1_OnSeriesBeforeDrawValues(ByVal SeriesIndex As Long)
  'Place the new location of the Chart before painting the Series
  With TChart1
    Select Case SeriesIndex
      Case 0: .ChartRect 0, 0, .Canvas.Width / 2, .Canvas.Height / 2
      Case 1: .ChartRect .Canvas.Width / 2, 0, .Canvas.Width, .Canvas.Height / 2
      Case 2: .ChartRect 0, .Canvas.Height / 2, .Canvas.Width / 2, .Canvas.Height
      Case 3: .ChartRect .Canvas.Width / 2, .Canvas.Height / 2, .Canvas.Width, .Canvas.Height
    End Select
  End With
End Sub

on after draw?

Posted: Mon Sep 05, 2005 11:20 am
by 9528213
Is it possible to use the onAfter draw when the project is a .DLL project (with no visible interface?)... (I just generate a JPEG in my application).
The Teechart is late bound... :?:

Posted: Mon Sep 05, 2005 11:37 am
by narcis
Hi Bjørn,

Yes, TeeChart is late bound.

You can use OnAfterDraw event even you don't use a visible interface.

Posted: Tue Sep 06, 2005 12:55 pm
by 9528213
Hola, narcis!

How?

My app is a COM+ .dll which runs as a component in component services.

I use Teechart like this:

Dim TChart As Object
' create the ole automated object...
Set TChart = CreateObject("TeeChart.TChart")

TChart.Visible = False
'
' and do the other bits that makes the graph and creates the file
'
' When I take the code you showed me (which works fine on a project with a form) i get "variable not defined" (its the "With Tchart" clause - see below.
'
Private Sub TChart_OnAfterDraw()
Dim XCenter, YCenter As Integer
With TChart
For SeriesIndex = 0 To TChart.SeriesCount - 1
XCenter = .Series(SeriesIndex).asPie.XCenter
YCenter = .Series(SeriesIndex).asPie.YCenter
.Canvas.TextOut XCenter, YCenter, "Series" + CStr(SeriesIndex)
Next SeriesIndex
End With
End Sub

I am doing this in VB6..

-

Then I move the "Dim TChart As Object" from the actual sub to the global dim part of the class. The compile error goes away so it seems fine. To debug the component - i use logging to event log and the TChart_OnAfterDraw() is not called - so nothing happens. Can this work? I have no reference other than the Dim tChart as Object - ??

regards
bjørn

Posted: Sun Sep 11, 2005 10:19 pm
by Pep
Hi Bjørn,

you should be able to do this by using the following code :

Code: Select all

Option Explicit
Dim SeriesIndex As Integer
Private WithEvents TChart1 As TeeChart.TChart

Private Sub Form_Load()
Dim i As Integer
  Set TChart1 = CreateObject("TeeChart.TChart")
  With TChart1
    .Legend.Visible = False
    For i = 0 To 3
      .AddSeries scPie
      .Series(i).FillSampleValues 7
      .Series(i).Marks.Style = smsValue
    Next i
  End With
  TChart1.Environment.InternalRepaint
  TChart1.Export.asJPEG.SaveToFile "C:\chart.jpg"
End Sub

Private Sub TChart1_OnAfterDraw()
    Dim XCenter, YCenter As Integer
    With TChart1
      .Canvas.Font.Color = vbWhite
      For SeriesIndex = 0 To TChart1.SeriesCount - 1
          XCenter = .Series(SeriesIndex).asPie.XCenter
          YCenter = .Series(SeriesIndex).asPie.YCenter
          .Canvas.TextOut XCenter, YCenter, "Series" + CStr(SeriesIndex)
      Next SeriesIndex
    End With
End Sub

Private Sub TChart1_OnSeriesBeforeDrawValues(ByVal SeriesIndex As Long)
  'Place the new location of the Chart before painting the Series
  With TChart1
    Select Case SeriesIndex
      Case 0: .ChartRect 0, 0, .Canvas.Width / 2, .Canvas.Height / 2
      Case 1: .ChartRect .Canvas.Width / 2, 0, .Canvas.Width, .Canvas.Height / 2
      Case 2: .ChartRect 0, .Canvas.Height / 2, .Canvas.Width / 2, .Canvas.Height
      Case 3: .ChartRect .Canvas.Width / 2, .Canvas.Height / 2, .Canvas.Width, .Canvas.Height
    End Select
  End With
End Sub