Click here to Skip to main content
15,892,161 members
Articles / Containers / Virtual Machine

ASP.NET Report Kit Grasshoper (Race to Linux)

Rate me:
Please Sign up or sign in to vote.
2.38/5 (5 votes)
2 Oct 20057 min read 38K   19  
Porting and deploying the report starter kit to Linux (RH7.3/Tomcat5.0.28/Grasshoper1.61)
<html><head><link rel=stylesheet href=style.css></head><body><div class=SourcePanel style='font-size:12'><pre style='background-color:white'>
<font color= "blue">Imports</font> System
<font color= "blue">Imports</font> System.Collections
<font color= "blue">Imports</font> System.Drawing
<font color= "blue">Imports</font> System.Drawing.Imaging
<font color= "blue">Imports</font> System.Drawing.Drawing2D
<font color= "blue"></font>
<font color= "blue">Namespace</font> ASPNET.StarterKit.Chart
<font color= "blue"></font>
<font color= "green">    '*********************************************************************</font>
<font color= "green">    '</font>
<font color= "green">    ' PieChart Class</font>
<font color= "green">    '</font>
<font color= "green">    ' This class uses GDI+ to render Pie Chart.</font>
<font color= "green">    '</font>
<font color= "green">    '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    Public Class</font> PieChart
<font color= "blue">        Inherits</font> Chart
<font color= "blue">        Private </font>_bufferSpace <font color= "blue">As </font>Integer = 125
<font color= "blue">        Private </font>_chartItems <font color= "blue">As </font>ArrayList
<font color= "blue">        Private </font>_perimeter <font color= "blue">As </font>Integer
<font color= "blue">        Private </font>_backgroundColor <font color= "blue">As </font>Color
<font color= "blue">        Private </font>_borderColor <font color= "blue">As </font>Color
<font color= "blue">        Private </font>_total <font color= "blue">As </font>Single
<font color= "blue">        Private </font>_legendWidth <font color= "blue">As </font>Integer
<font color= "blue">        Private </font>_legendHeight <font color= "blue">As </font>Integer
<font color= "blue">        Private </font>_legendFontHeight <font color= "blue">As </font>Integer
<font color= "blue">        Private </font>_legendFontStyle <font color= "blue">As </font>String
<font color= "blue">        Private </font>_legendFontSize <font color= "blue">As </font>Single
<font color= "blue"></font>
<font color= "blue">        Public Sub</font> New()
<font color= "blue">            </font>_chartItems <font color= "blue"></font>= New ArrayList()
<font color= "blue">            </font>_perimeter <font color= "blue"></font>= 250
<font color= "blue">            </font>_backgroundColor <font color= "blue"></font>= Color.White
<font color= "blue">            </font>_borderColor <font color= "blue"></font>= Color.FromArgb(63, 63, 63)
<font color= "blue">            </font>_legendFontSize <font color= "blue"></font>= 8
<font color= "blue">            </font>_legendFontStyle <font color= "blue"></font>= "Verdana"
<font color= "blue">        End Sub</font><font color= "green"> 'New</font>
<font color= "blue"></font>
<font color= "blue">        Public Sub</font> New(ByVal bgColor As Color)
<font color= "blue">            </font>_chartItems <font color= "blue"></font>= New ArrayList()
<font color= "blue">            </font>_perimeter <font color= "blue"></font>= 250
<font color= "blue">            </font>_backgroundColor <font color= "blue"></font>= bgColor
<font color= "blue">            </font>_borderColor <font color= "blue"></font>= Color.FromArgb(63, 63, 63)
<font color= "blue">            </font>_legendFontSize <font color= "blue"></font>= 8
<font color= "blue">            </font>_legendFontStyle <font color= "blue"></font>= "Verdana"
<font color= "blue">        End Sub</font><font color= "green"> 'New</font>
<font color= "blue"></font>
<font color= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' This method collects all data points and calculate all the necessary dimensions </font>
<font color= "green">        ' to draw the chart.  It is the first method called before invoking the Draw() method.</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Public Sub</font> CollectDataPoints(ByVal xValues() As String, ByVal yValues() As String)
<font color= "blue">            </font>_total <font color= "blue"></font>= 0.0F
<font color= "blue"></font>
<font color= "blue">            Dim </font>i <font color= "blue">As </font>Integer
<font color= "blue">            For</font> i = 0 To xValues.Length - 1
<font color= "blue">                Dim </font>ftemp <font color= "blue">As </font>Single = Convert.ToSingle(yValues(i))
<font color= "blue">                </font>_chartItems.Add(New ChartItem(xValues(i), xValues.ToString(), ftemp, 0, 0, Color.AliceBlue))
<font color= "blue">                </font>_total <font color= "blue"></font>+= ftemp
<font color= "blue">            Next</font> i
<font color= "blue"></font>
<font color= "blue">            Dim </font>nextStartPos <font color= "blue">As </font>Single = 0.0F
<font color= "blue">            Dim </font>counter <font color= "blue">As </font>Integer = 0
<font color= "blue">            Dim </font>item <font color= "blue">As </font>ChartItem
<font color= "blue">            For Each</font> item In _chartItems
<font color= "blue">                </font>item.StartPos = nextStartPos
<font color= "blue">                </font>item.SweepSize = item.Value / _total * 360
<font color= "blue">                </font>nextStartPos <font color= "blue"></font>= item.StartPos + item.SweepSize
<font color= "blue">                </font>counter <font color= "blue"></font>= counter + 1
<font color= "blue">                </font>item.ItemColor = GetColor(counter)
<font color= "blue">            Next</font>
<font color= "blue">            </font>CalculateLegendWidthHeight()
<font color= "blue">        End Sub</font><font color= "green"> 'CollectDataPoints</font>
<font color= "blue"></font>
<font color= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        ' This method returns a bitmap to the calling function.  This is the method</font>
<font color= "green">        ' that actually draws the pie chart and the legend with it.</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Public Overrides Function</font> Draw() As Bitmap
<font color= "blue">            Dim </font>perimeter <font color= "blue">As </font>Integer = _perimeter
<font color= "blue">            Dim </font>pieRect <font color= "blue">As </font>New Rectangle(0, 0, perimeter, perimeter - 1)
<font color= "blue">            Dim </font>bmp <font color= "blue">As </font>New Bitmap(perimeter + _legendWidth, perimeter)
<font color= "blue">            Dim </font>grp <font color= "blue">As </font>Graphics = Graphics.FromImage(bmp)
<font color= "blue"></font>
<font color= "green">            'Paint Back ground</font>
<font color= "blue">            </font>grp.FillRectangle(New SolidBrush(_backgroundColor), 0, 0, perimeter + _legendWidth, perimeter)
<font color= "blue"></font>
<font color= "green">            'Align text to the right</font>
<font color= "blue">            Dim </font>sf <font color= "blue">As </font>New StringFormat()
<font color= "blue">            </font>sf.Alignment = StringAlignment.Far
<font color= "blue"></font>
<font color= "green">            'Draw all wedges and legends</font>
<font color= "blue">            Dim </font>i <font color= "blue">As </font>Integer
<font color= "blue">            For</font> i = 0 To _chartItems.Count - 1
<font color= "blue">                Dim </font>item <font color= "blue">As </font>ChartItem = CType(_chartItems(i), ChartItem)
<font color= "blue">                Dim </font>brs <font color= "blue">As </font>New SolidBrush(item.ItemColor)
<font color= "blue">                </font>grp.FillPie(brs, pieRect, item.StartPos, item.SweepSize)
<font color= "blue">                </font>grp.FillRectangle(brs, perimeter + _bufferSpace, i * _legendFontHeight + 15, 10, 10)
<font color= "blue">                </font>grp.DrawString(item.Label, New Font(_legendFontStyle, _legendFontSize), New SolidBrush(Color.Black), perimeter + _bufferSpace + 20, i * _legendFontHeight + 13)
<font color= "blue"></font>
<font color= "blue">                </font>grp.DrawString(item.Value.ToString("C"), New Font(_legendFontStyle, _legendFontSize), New SolidBrush(Color.Black), perimeter + _bufferSpace + 200, i * _legendFontHeight + 13, sf)
<font color= "blue">            Next</font> i
<font color= "blue"></font>
<font color= "green">            'draws the border around Pie</font>
<font color= "blue">            </font>grp.DrawEllipse(New Pen(_borderColor, 2), pieRect)
<font color= "blue"></font>
<font color= "green">            'draw border around legend</font>
<font color= "blue">            </font>grp.DrawRectangle(New Pen(_borderColor, 1), perimeter + _bufferSpace - 10, 10, 220, _chartItems.Count * _legendFontHeight + 25)
<font color= "blue"></font>
<font color= "green">            'Draw Total under legend</font>
<font color= "blue">            </font>grp.DrawString("Total", New Font(_legendFontStyle, _legendFontSize, FontStyle.Bold), New SolidBrush(Color.Black), perimeter + _bufferSpace + 30, (_chartItems.Count + 1) * _legendFontHeight, sf)
<font color= "blue">            </font>grp.DrawString(_total.ToString("C"), New Font(_legendFontStyle, _legendFontSize, FontStyle.Bold), New SolidBrush(Color.Black), perimeter + _bufferSpace + 200, (_chartItems.Count + 1) * _legendFontHeight, sf)
<font color= "blue"></font>
<font color= "blue">            </font>grp.SmoothingMode = SmoothingMode.AntiAlias
<font color= "blue">            </font>grp.Dispose()
<font color= "blue">            </font>Return <font color= "blue"></font>bmp
<font color= "blue"></font><font color= "blue">        End Function</font><font color= "blue"></font><font color= "green"> 'Draw</font>
<font color= "blue"></font>
<font color= "green">        '*********************************************************************</font>
<font color= "green">        '</font>
<font color= "green">        '    This method calculates the space required to draw the chart legend.</font>
<font color= "green">        '</font>
<font color= "green">        '*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        Private Sub</font> CalculateLegendWidthHeight()
<font color= "blue">            Dim </font>fontLegend <font color= "blue">As </font>New Font(_legendFontStyle, _legendFontSize)
<font color= "blue">            </font>_legendFontHeight <font color= "blue"></font>= fontLegend.Height + 5
<font color= "blue">            </font>_legendHeight <font color= "blue"></font>= fontLegend.Height * (_chartItems.Count + 1)
<font color= "blue"></font><font color= "blue">            If </font>_legendHeight > _perimeter <font color= "blue">Then</font>
<font color= "blue">                </font>_perimeter <font color= "blue"></font>= _legendHeight
<font color= "blue"></font><font color= "blue">            End If</font><font color= "blue"></font>
<font color= "blue">            </font>_legendWidth <font color= "blue"></font>= _perimeter + _bufferSpace
<font color= "blue">        End Sub</font><font color= "green"> 'CalculateLegendWidthHeight</font>
<font color= "blue"></font><font color= "blue">    End Class</font><font color= "blue"></font><font color= "green"> 'PieChart</font>
<font color= "blue"></font><font color= "blue">End Namespace</font><font color= "blue"></font><font color= "green"> 'ASPNET.StarterKit.Chart</font>
</pre>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
I love to code! Working in C# is my passion, visit my github

Comments and Discussions