<% Response.ContentType = "image/gif" Response.Expires = 0 Response.AddHeader "pragma","no-cache" Set g = CreateObject("shotgraph.image") Const pi = 3.141592 ' Image size Dim x_size, y_size x_size = 320 y_size = 240 ' Colors of slices Dim colors colors = Array("102#255#201","255#102#201","201#201#255","101#154#99") 'Offset of cut slice Const cut_offset = 10 ' First # of seria colors ' #0 -- used for common background ' #1 -- used for text and lines color ' #2 -- used for text background ' #3 -- used for legend background Const first_color = 4 ' Color of text background Const text_bg = "255#255#204" ' Color of common background Const common_bg = "240#240#240" ' Color of legend background Const legend_bg = "255#255#255" Dim data(),i,cut_number ' Fill the array variable with data For i=1 to Request.QueryString("seria").Count ReDim preserve data(i-1) data(i-1) = Abs(Request.QueryString("seria")(i)*1) Next cut_number = Request.QueryString("cut")*1 g.CreateImage x_size,y_size,8 ' Drawing color: black g.SetColor 1,0,0,0 g.SetDrawColor 1 ' Background color ParseColor 0,common_bg g.SetBgColor 0 ' Fill the whole image area g.Rectangle 0,0,x_size-1,y_size-1 ParseColor 2,text_bg ParseColor 3,legend_bg For i=0 to UBound(colors) ParseColor i+first_color,colors(i) Next DrawPie 5,5,y_size-5,y_size-5,data,cut_number DrawLegend y_size+3,10,data ' Draws empty rectangle bound the whole image g.CreateBrush "BS_NULL",1,1 g.Rectangle 0,0,x_size-1,y_size-1 Response.BinaryWrite g.GifImage(-1,0,"") ' END OF OPERATION '''''''''''''''''''''''''''''''''''''''''''''''''''''' ' DrawPie ' Draws several slices ' x1,y1,x2,y2 -- coordinates of bounding rectangle ' data -- array of values ' cutnumber -- the number of cut slice ' ' This subroutine calculates the angle of every slice '''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub DrawPie(ByVal x1,ByVal y1,ByVal x2,ByVal y2,data,cutnumber) Dim sum,astart,percent,spercent g.SetTextColor 1 g.SetBkColor 2 sum = 0 For i=0 to UBound(data) sum = sum + data(i) Next if sum <= 0 then Exit Sub astart = 0 For i=0 to UBound(data) g.SetBgColor i+2 ang = data(i)*(pi*2)/sum g.SetBgColor first_color+i DrawSlice x1,y1,x2,y2,astart,ang,(cutnumber=i) astart = astart + ang Next astart = 0 spercent = 0 For i=0 to UBound(data) percent = Round(100*data(i)/sum) ' Bind percents summa to 100 to avoid math round errors if i0.01 then PlaceLabel x1,y1,x2,y2,astart+ang/2,percent & "%",(cutnumber=i) astart = astart + ang Next End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' ' DrawSlice ' Draws a single slice ' x1,y1,x2,y2 -- coordinates of bounding rectangle ' startangle -- the angle in radians where the slice is started ' angle -- size of slice in radians ' cut -- boolean value showing whether the slice is cut ' ' This subroutine calculates the necessary values for Pie method of ShotGraph '''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub DrawSlice(ByVal x1,ByVal y1,ByVal x2,ByVal y2,startangle,angle,cut) Dim r,xcenter,ycenter,scale if angle<0.01 then Exit Sub if cut then x1 = x1 + cut_offset*Sin(angle/2+startangle) x2 = x2 + cut_offset*Sin(angle/2+startangle) y1 = y1 - cut_offset*Cos(angle/2+startangle) y2 = y2 - cut_offset*Cos(angle/2+startangle) end if r = (x2-x1) + (y2-y1) xcenter = (x2+x1)\2 ycenter = (y2+y1)\2 scale = (x2-x1+1)/(y2-y1+1) if (angle+startangle) > (pi*2) then angle = pi*2 - startangle g.Pie x1,y1,x2,y2,xcenter+r*Sin(angle+startangle),ycenter-r*Cos(angle+startangle),xcenter+r*Sin(startangle),ycenter-r*Cos(startangle) End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' ' PlaceLabel ' Draws a text label on the slice ' x1,y1,x2,y2 -- coordinates of bounding rectangle ' angle -- angle where to draw label ' text -- string to draw ' cut -- boolean value showing whether the slice is cut '''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub PlaceLabel(ByVal x1,ByVal y1,ByVal x2,ByVal y2,angle,text,cut) Dim xcenter,ycenter,scale if angle<0.01 then Exit Sub if cut then x1 = x1 + cut_offset*Sin(angle) x2 = x2 + cut_offset*Sin(angle) y1 = y1 - cut_offset*Cos(angle) y2 = y2 - cut_offset*Cos(angle) end if xcenter = (x2+x1)\2 ycenter = (y2+y1)\2 scale = (x2-x1+1)/(y2-y1+1) if (angle) > (pi*2) then angle = pi*2 g.SetTextAlign "TA_CENTER","TA_BASELINE" g.TextOut xcenter+(x2-x1)/3*Sin(angle),ycenter-(y2-y1)/3*Cos(angle),text End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' ' DrawLegend ' Draws a legend of chart ' xstart,ystart -- top left point of legend ' data -- array of values ' ' This subroutine iterates the data array and draws ' a small rectangle filled with necessary color and a ' text string with data value on every iteration. '''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub DrawLegend(xstart,ystart,data) Dim xt,yt,ysize,y g.GetTextDimensions "Values",xt,yt ysize = yt*(UBound(data)+1)*2 + yt*2 g.SetDrawColor 1 g.SetBgColor 3 ' Bounding rectangle g.Rectangle xstart,ystart,xstart+xt*3\2,ystart+ysize g.SetTextAlign "TA_LEFT","TA_TOP" g.SetBkMode "TRANSPARENT" g.TextOut xstart+10,ystart,"Values" y=ystart + yt*2 For i=0 to UBound(data) g.SetBgColor first_color+i g.Rectangle xstart+10,y,xstart+10+yt,y+yt g.TextOut xstart+10+yt+5,y,data(i) y = y + yt*2 Next End Sub Sub ParseColor(num,str) Dim a a=Split(str,"#") g.SetColor num,a(0),a(1),a(2) End Sub %>