Hi, guys.
I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is below:
chartGenerator.vb class: -
Imports System.Drawing.Imaging
-
-
Public Class chartGenerator
-
-
Private myImage As Bitmap
-
Private g As Graphics
-
Private p() As Integer = {1000000, 600000, 2500000, 80000}
-
Private towns() As String = {"A", "B", "C", "D"}
-
-
Private myBrushes(4) As Brush
-
Private _width, _height As Integer
-
Private x_start, y_start As Decimal
-
-
-
Sub New(ByVal width As Integer, ByVal height As Integer)
-
-
_width = width
-
_height = height
-
x_start = _width / 10
-
y_start = _height / 10
-
-
' The Bitmap is 300 pixels wide and 200 pixels high.
-
myImage = New Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
-
-
myImage.MakeTransparent(Color.White)
-
-
' Get the graphics context for the bitmap.
-
g = Graphics.FromImage(myImage)
-
-
' Create the brushes for drawing
-
myBrushes(0) = New SolidBrush(Color.Red)
-
myBrushes(1) = New SolidBrush(Color.Blue)
-
myBrushes(2) = New SolidBrush(Color.Yellow)
-
-
myBrushes(3) = New SolidBrush(Color.Green)
-
End Sub
-
-
Function makeBarChart() As Bitmap
-
' Variables declaration
-
Dim i As Integer
-
Dim xInterval As Integer = _width / 5
-
Dim width As Integer = _width * 9 / 50
-
Dim height As Integer
-
Dim blackBrush As New SolidBrush(Color.Black)
-
-
For i = 0 To p.Length - 1
-
height = (p(i) \ 10000) ' divide by 10000 to adjust barchart to height of Bitmap
-
-
' Draws the bar chart using specific colours
-
g.FillRectangle(myBrushes(i), xInterval * i + 50, 280 - height, width, height)
-
-
' label the barcharts
-
g.DrawString(towns(i), New Font("Verdana", 12, FontStyle.Bold), Brushes.Black, xInterval * i + 50 + (width / 3), 280 - height - 25)
-
-
' Draw the scale
-
g.DrawString(height, New Font("Verdana", 8, FontStyle.Bold), Brushes.Black, 0, 280 - height)
-
-
' Draw the axes
-
g.DrawLine(Pens.Brown, 40, 10, 40, 290) ' y-axis
-
g.DrawLine(Pens.Brown, 20, 280, 490, 280) ' x-axis
-
Next
-
-
Return myImage
-
'myImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
-
'myImage.Dispose()
-
End Function
-
-
Function makePieChart() As Bitmap
-
' Variables declaration
-
Dim i As Integer
-
Dim total As Integer
-
Dim percentage As Double
-
Dim angleSoFar As Double = 0.0
-
-
' Caculates the total
-
For i = 0 To p.Length - 1
-
total += p(i)
-
Next
-
-
' Draws the pie chart
-
For i = 0 To p.Length - 1
-
percentage = p(i) / total * 360
-
-
g.FillPie(myBrushes(i), 25, 25, 250, 250, CInt(angleSoFar), CInt(percentage))
-
-
angleSoFar += percentage
-
-
' Draws the lengend
-
g.FillRectangle(myBrushes(i), 350, 25 + (i * 50), 25, 25)
-
-
' Label the towns
-
g.DrawString("Town " & towns(i), New Font("Verdana", 8, FontStyle.Bold), Brushes.Brown, 390, 25 + (i * 50) + 10)
-
Next
-
-
Return myImage
-
'myImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
-
'myImage.Dispose()
-
End Function
-
End Class
-
-
image.aspx.vb -
Imports System.Drawing.Imaging
-
Public Class image
-
Inherits System.Web.UI.Page
-
-
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
'Put user code to initialize the page here
-
Dim bitmap As Bitmap = CType(Session("image"), Bitmap)
-
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg)
-
bitmap.Dispose()
-
-
End Sub
-
-
End Class
-
-
testChart.aspx.vb -
Public Class testChart
-
Inherits System.Web.UI.Page
-
-
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
'Put user code to initialize the page here
-
-
-
-
End Sub
-
-
Private chart As New chartGenerator(500, 300)
-
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
-
Dim bitmap As Bitmap = chart.makeBarChart()
-
Session("image") = bitmap
-
Image1.ImageUrl = "image.aspx"
-
-
-
End Sub
-
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
-
Dim bitmap As Bitmap = chart.makePieChart
-
Session("image") = bitmap
-
Image1.ImageUrl = "image.aspx"
-
-
End Sub
-
End Class
-
-
Anyone got idea of what happen out there?
0 2768 Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
How can I draw any thing within "for" loop? I tried the
below but it doesn't draw anything. What should I do?
****
Code
****
Graphics g = this.CreateGraphics();
Bitmap bm=new Bitmap(1,1);...
|
by: Matthew Belk |
last post by:
I am trying to print some 2x6 labels on a SATO CL408e thermal label printer. The 2x6 labels are arranged in "landscape" mode with 2 labels per "sheet." When I attempt to print "x" copies of a 1...
|
by: John |
last post by:
I'm trying to use the DrawText() method to draw some very long string
text on the Panel with AutoScroll enabled. However, for some unknown
reasons, I could not trigger the ScrollBar to show up.
...
|
by: Bernt Fischer |
last post by:
Hello
I want to render a datagrid with transparent borders (cellspacing = 1) so
the underlying background shines through. Unfortunately, ASPNET renders the
<table> tag with a 'rules="all"...
|
by: Boki |
last post by:
Dear All,
I think you all knew my problem.
I don't know how to draw line @@ in VB.NET (2005 beta) , very sad.
Coudl you please help me?
Best regards,
Boki.
|
by: Simon Verona |
last post by:
If I have a combobox set enabled=false then by default it will have dark
grey text on a grey background. I want it to show as blue on white. I'm
trying code such as :
combobox.enabled=false...
|
by: Peter Proost |
last post by:
Hi group,
I've got this bit of code (see below) which draws a basketball field in a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the...
|
by: spifster |
last post by:
Hello all,
I am building a collapsable tree using Javascript with DOM in IE. In
order to make collapsed cells disappear I have been hiding the text.
The cells collapse but still leave borders...
|
by: rebeccatre |
last post by:
please help me with this,
<style>
#a, option.message {background-color: green; color: white;}
#b, option.message {background-color: yellow; color: black;}
</style>
<select id="thisselect">...
|
by: luke14free |
last post by:
Hello guys,
I've been searching for a method to hide the console (as c/c++ user would say) under windows, but i found nothing really helpful.
What I found is:
1) I need to rename file as pyw. But...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |