Re: Segments



Hi Rick
It is not clear how your DrawSegment subroutine works
I'm using the Pie API with a few COS as SIN functions thrown in. I tried the
Circle method at first but go the same problem that shows up in the code
sample you posted - the segment is the right size but in the wrong place. In
the sample I would need the start of the segment to be 25% clockwise around
the circle and end at 58% of the circle. The Pie will always be 100% filled
with up to 50 segments.
The Pie API finds the center of the elipse by using the RECT parameter
passed to it (I assume)

I wanted the end points of the segment so that I could draw a 3D looking Pie
chart, the idea being I could draw a little line down from the end points
(Provided they were between 25% and 75%), then draw an Arc and the fill that
little shape (what ever it's called) to make the pie chart have a thickness
look. trouble is the little lines dont start in the right place, very nearly
do, but not quite. All ways a few pixels out. The function code is below.


One trouble I have it that the chart only uses 10 colours for it's segments,
when drawing the chart it loops through the colours to use and when it gets
to 10 it changes the drawStyle of the property so that two segments that use
the same colour look different. Using this method the Point method does not
do the job. I suppose I could change the colour selection code to loop
through 50 colours, then it would work.

Thanks very much for your reply to Rick and Randy

Ivar

'My Draw Segment code
Private Function DrawSegment(R As RECT, StartPercent As Single, _
EndPercent As Single, TheColour As Long, TheHDC As Long, _
Optional a3Dstep As Integer) As Long
If EndPercent - StartPercent < 0.01 Then Exit Function
Const pi = 3.14159265358979
Dim CPoint As POINTAPI
Dim Point As POINTAPI
Dim StartPoint As POINTAPI
Dim EndPoint As POINTAPI
Dim InnerPoint As POINTAPI
Dim OuterPoint As POINTAPI
Dim TheRadius As Integer
Dim SC As Single
TheRadius = (R.Right - R.Left) / 2
CPoint.x = ((R.Right - R.Left) / 2) + R.Left
CPoint.Y = ((R.Bottom - R.Top) / 2) + R.Top
SC = (StartPercent / 100)
SC = (SC * (2 * pi)) - (0.5 * pi)
StartPoint.x = Cos(SC) * TheRadius + CPoint.x
StartPoint.Y = Sin(SC) * TheRadius + CPoint.Y

SC = (EndPercent / 100)
SC = (SC * (2 * pi)) - (0.5 * pi)
EndPoint.x = Cos(SC) * TheRadius + CPoint.x
EndPoint.Y = Sin(SC) * TheRadius + CPoint.Y
If (EndPoint.x = StartPoint.x) And EndPercent < 100 Then
Exit Function
End If

Me.FillColor = TheColour
Me.ForeColor = TheColour
Pie TheHDC, R.Left, R.Top, R.Right, R.Bottom, _
EndPoint.x, EndPoint.Y, StartPoint.x, StartPoint.Y
'Put Black Spot in center of elipse
SetPixel TheHDC, CPoint.x, CPoint.Y, vbBlack
' My code never gets past here because I gave up on the 3D bit
If a3Dstep < 2 Then Exit Function
If EndPercent <= 25 Then Exit Function
If StartPercent >= 75 Then Exit Function

If EndPoint.Y < CPoint.Y Then
EndPoint.Y = CPoint.Y
MoveToEx TheHDC, R.Left, CPoint.Y, Point
LineTo TheHDC, R.Left, CPoint.Y + a3Dstep
End If
If StartPoint.Y < CPoint.Y Then
StartPoint.Y = CPoint.Y
MoveToEx TheHDC, R.Right, CPoint.Y, Point
LineTo TheHDC, R.Right, CPoint.Y + a3Dstep
End If

Arc TheHDC, R.Left, R.Top + a3Dstep, R.Right, R.Bottom + a3Dstep, _
EndPoint.x, EndPoint.Y + a3Dstep, StartPoint.x, StartPoint.Y + a3Dstep

If StartPercent > 25 And StartPercent < 75 Then
MoveToEx TheHDC, StartPoint.x, StartPoint.Y, Point
LineTo TheHDC, StartPoint.x, StartPoint.Y + a3Dstep
End If
If EndPercent > 25 And EndPercent < 75 Then
MoveToEx TheHDC, EndPoint.x, EndPoint.Y, Point
LineTo TheHDC, EndPoint.x, EndPoint.Y + a3Dstep
End If
End Function


.



Relevant Pages

  • Pie & Mash
    ... the should be Pi and Maths :-) ... I am looking for a function that draws a segment of a circle. ... Dim X1 As Integer ...
    (comp.lang.basic.visual.misc)
  • Re: how can i change the interior colors of pies?
    ... The problem with using the Interior object of the Datalabels Object is ... that it changes the color for the entire pie. ... >> Dim aryValues ... >> Call AddChart(objCharts, objConstants, aryValues, aryTimes, ...
    (microsoft.public.office.developer.web.components)
  • RE: how can i change the interior colors of pies?
    ... Your code already set the pie value via SeriesCollection.SetData ... > Dim aryValues ... > Dim objChart ... > Set objConstants = objCharts.Constants ...
    (microsoft.public.office.developer.web.components)
  • Re: how can i change the interior colors of pies?
    ... > The problem with using the Interior object of the Datalabels Object is> that it changes the color for the entire pie. ... >>> Dim aryValues ... >>> Dim objChart ... >>> Set objConstants = objCharts.Constants ...
    (microsoft.public.office.developer.web.components)
  • Re: String extrahieren
    ... Ich lese eine txt- Datei in einen String ... solche Segment würde ich gerne auf einfache Art und Weise ... Dim strDate As String ... Dim lngI As Long ...
    (microsoft.public.de.excel)