multiple pies - legend problem

TeeChart for ActiveX, COM and ASP
Post Reply
Bjørn
Newbie
Newbie
Posts: 5
Joined: Thu Sep 01, 2005 4:00 am
Location: Norway

multiple pies - legend problem

Post by Bjørn » Sat Sep 03, 2005 2:12 pm

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?

Bjørn
Newbie
Newbie
Posts: 5
Joined: Thu Sep 01, 2005 4:00 am
Location: Norway

More info on the subject

Post by Bjørn » Sat Sep 03, 2005 2:59 pm

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?

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

Post by Narcís » Mon Sep 05, 2005 11:11 am

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
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

Bjørn
Newbie
Newbie
Posts: 5
Joined: Thu Sep 01, 2005 4:00 am
Location: Norway

on after draw?

Post by Bjørn » Mon Sep 05, 2005 11:20 am

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... :?:

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

Post by Narcís » Mon Sep 05, 2005 11:37 am

Hi Bjørn,

Yes, TeeChart is late bound.

You can use OnAfterDraw event even you don't use a visible interface.
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

Bjørn
Newbie
Newbie
Posts: 5
Joined: Thu Sep 01, 2005 4:00 am
Location: Norway

Post by Bjørn » Tue Sep 06, 2005 12:55 pm

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

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

Post by Pep » Sun Sep 11, 2005 10:19 pm

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

Post Reply