473,672 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Bar Graphs

Help. I am trying to create a web page in C# to display a row of data
with bar graphs (an image 1px). I get the max value of the row and use
the following formula to size the height of the image, but the bar
graphs are not sizing correctly. Can anyone provide me with a solution
or any ideas.

rowValue / maxRowValue * maxBarHeight

Nov 11 '06 #1
6 4983
Are rowValue and maxRowValue both integer values? You need to make sure at
least on of those values is a floating point number otherwise you are just
going to end up with 0's.

When you say not being sized correctly, what exactly do you mean?

Mark.
--
http://www.markdawson.org
"ro************ **@anheuser-busch.com" wrote:
Help. I am trying to create a web page in C# to display a row of data
with bar graphs (an image 1px). I get the max value of the row and use
the following formula to size the height of the image, but the bar
graphs are not sizing correctly. Can anyone provide me with a solution
or any ideas.

rowValue / maxRowValue * maxBarHeight

Nov 11 '06 #2
ro************* *@anheuser-busch.com wrote:
Help. I am trying to create a web page in C# to display a row of data
with bar graphs (an image 1px). I get the max value of the row and use
the following formula to size the height of the image, but the bar
graphs are not sizing correctly. Can anyone provide me with a solution
or any ideas.

rowValue / maxRowValue * maxBarHeight
Try this:

(rowValue / maxRowValue) * maxBarHeight

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 11 '06 #3
In this case that would not make a difference since \ has a higher order of
precedence than * and will be evaluated first.

Mark
--
http://www.markdawson.org
"Tom Spink" wrote:
ro************* *@anheuser-busch.com wrote:
Help. I am trying to create a web page in C# to display a row of data
with bar graphs (an image 1px). I get the max value of the row and use
the following formula to size the height of the image, but the bar
graphs are not sizing correctly. Can anyone provide me with a solution
or any ideas.

rowValue / maxRowValue * maxBarHeight

Try this:

(rowValue / maxRowValue) * maxBarHeight

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 11 '06 #4
Here is my current code. The bars are showing a blank image if the
value is the same as the maxvalue which makes since since 60/60 = 0.
The maxHieght is a constant of 120. The other graphs don't size
correctly to the data value 4 value / 60 maxValue * 120 = 8 but the
image is close to the top of the cell. Image width is a constant of
30.

private void PaintPlacements (DataTable dtPlacements)
{
DataRow[] rows = dtPlacements.Se lect();

double maxPlacements = Double.Parse(dt Placements.Comp ute

("Max(PLACEMENT S_NBR)", "").ToString()) ;
double maxPerformer = Double.Parse(dt Placements.Comp ute

("Max(BEST_PERF ORMER_NBR)", "").ToString()) ;
double[] maxValue = {maxPlacements, maxPerformer};
tblPlacements.R ows.Add(AddPlac ementGraphs(row s, maxValue,
ScorecardData.I mageWidth));
}

private TableRow AddPlacementGra phs(DataRow[] rows, double[] maxValue,
int barWidth)
{
double graphData;
double graphHeight;
TableRow tr = new TableRow();

foreach(DataRow row in rows)
{
TableCell tc = new TableCell();
graphData = Double.Parse(ro w["PLACEMENTS_NBR "].ToString());
graphHeight = (graphData / maxValue[0] *
ScorecardData.M aximumHeight);
tc.Text = "<img border=0 src=../images/spacer1.gif" +
" height=" + Math.Round(grap hHeight, 0) +
" width=" + barWidth + ">";
tc.BackColor = Color.FromName( "Blue");
tc.VerticalAlig n = VerticalAlign.T op;
tr.Cells.Add(tc );
tc = null;

tc = new TableCell();
graphData = Double.Parse(ro w["BEST_PERFORMER _NBR"].ToString());
graphHeight = (graphData / maxValue[1] *
ScorecardData.M aximumHeight);
tc.Text = "<img border=0 src=../images/spacer1.gif" +
" height=" + Math.Round(grap hHeight, 0) +
" width=" + barWidth + ">";
tc.BackColor = Color.FromName( "CornflowerBlue ");
tc.VerticalAlig n = VerticalAlign.T op;
tr.Cells.Add(tc );
tc = null;
}
return tr;
}


Mark R. Dawson wrote:
Are rowValue and maxRowValue both integer values? You need to make sure at
least on of those values is a floating point number otherwise you are just
going to end up with 0's.

When you say not being sized correctly, what exactly do you mean?

Mark.
--
http://www.markdawson.org
Nov 12 '06 #5
Hi Robert,
>The bars are showing a blank image if the
value is the same as the maxvalue which makes since since 60/60 = 0
I would hope 60\60 == 1 :-)

I am no web expert but I would think you want to align your images to the
bottom of the cell, you have:
tc.VerticalAlig n = VerticalAlign.T op;
which would align the images to the top of the cell which is okay if you
want an inverted graph, but you probably want to align them to the bottom?
--
http://www.markdawson.org
"ro************ **@anheuser-busch.com" wrote:
Here is my current code. The bars are showing a blank image if the
value is the same as the maxvalue which makes since since 60/60 = 0.
The maxHieght is a constant of 120. The other graphs don't size
correctly to the data value 4 value / 60 maxValue * 120 = 8 but the
image is close to the top of the cell. Image width is a constant of
30.

private void PaintPlacements (DataTable dtPlacements)
{
DataRow[] rows = dtPlacements.Se lect();

double maxPlacements = Double.Parse(dt Placements.Comp ute

("Max(PLACEMENT S_NBR)", "").ToString()) ;
double maxPerformer = Double.Parse(dt Placements.Comp ute

("Max(BEST_PERF ORMER_NBR)", "").ToString()) ;
double[] maxValue = {maxPlacements, maxPerformer};
tblPlacements.R ows.Add(AddPlac ementGraphs(row s, maxValue,
ScorecardData.I mageWidth));
}

private TableRow AddPlacementGra phs(DataRow[] rows, double[] maxValue,
int barWidth)
{
double graphData;
double graphHeight;
TableRow tr = new TableRow();

foreach(DataRow row in rows)
{
TableCell tc = new TableCell();
graphData = Double.Parse(ro w["PLACEMENTS_NBR "].ToString());
graphHeight = (graphData / maxValue[0] *
ScorecardData.M aximumHeight);
tc.Text = "<img border=0 src=../images/spacer1.gif" +
" height=" + Math.Round(grap hHeight, 0) +
" width=" + barWidth + ">";
tc.BackColor = Color.FromName( "Blue");
tc.VerticalAlig n = VerticalAlign.T op;
tr.Cells.Add(tc );
tc = null;

tc = new TableCell();
graphData = Double.Parse(ro w["BEST_PERFORMER _NBR"].ToString());
graphHeight = (graphData / maxValue[1] *
ScorecardData.M aximumHeight);
tc.Text = "<img border=0 src=../images/spacer1.gif" +
" height=" + Math.Round(grap hHeight, 0) +
" width=" + barWidth + ">";
tc.BackColor = Color.FromName( "CornflowerBlue ");
tc.VerticalAlig n = VerticalAlign.T op;
tr.Cells.Add(tc );
tc = null;
}
return tr;
}


Mark R. Dawson wrote:
Are rowValue and maxRowValue both integer values? You need to make sure at
least on of those values is a floating point number otherwise you are just
going to end up with 0's.

When you say not being sized correctly, what exactly do you mean?

Mark.
--
http://www.markdawson.org

Nov 12 '06 #6
or just use zedgraph....http://www.codeproject.com/csharp/zedgraph.asp
I've used it in under an hour from when I downloaded it - very nice
tool.

Nov 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1543
by: Luis P. Mendes | last post by:
I'm developing a program in Python, with no gui, and now I've reached a point where I would need to plot list of elements on a graph. How can I do it? preferably in a simple way? Luis
1
1350
by: Florian Lindner | last post by:
Hello, I'm looking for libraries to create graphs. I'm not talking about plotting a function like f(x)=x^2 just plotting a couple of values into a short, maybe interpolating them. Output should be something like JPEG. Thx, Florian
0
1263
by: Job Lot | last post by:
How can i create graphs using vb.net. any tips, links would be helpfull. thanx
4
15578
by: Coskun Cavusoglu | last post by:
Hi I need to build something that works like the following example http://www.realestateabc.com/calc_v22/calculator.html How can can I do this by using c# and web forms. It will be a part of a web based project so it has to work on the web. And the important is as the user slides the control the graph will change itself. How can I get c# to draw a graph on a website depending on the slide controls postion. thanks coskunc
1
4611
by: Mitch | last post by:
I am using Access to create an Excel spreadsheets with graphs related to rows on the sheet1 to the graph on sheet2. I am using the same data but different subsets of the data to make different spreadsheets for different groups. The spreadsheet formats are the same for each of the different groups. So I am using a loop to requery the data for the different groups and create a new spreadsheet for each group. The three graphs on sheet 2...
1
2238
by: ckpoll2 | last post by:
Hello, Is there any way to create graphs from data within Access without exporting it to Excel? Thanks, Charlie
2
1698
by: robert.q.johnson | last post by:
Help. I am trying to create a web page in C# to display two rows of data with bar graphs (an image 1px). I get the max value of the row and use the following formula to size the height of the image, but the bar graphs are not sizing correctly. Can anyone provide me with a solution or any ideas. rowValue / maxRowValue * maxBarHeight
6
1606
by: JanM | last post by:
Hi all, I working on a Q&A database in which several lists of questions are defined. On each question a number of answers can be given. A list of questions can be entered into the database via forms. So far so good. Out of these entered lists I want to make reports. The idea is to make for one type of list per question a bargraph where on the x-axis all the possible answers for the question are positioned as categories and on the y-axis...
4
1829
by: =?UTF-8?B?4KSw4KS14KWA4KSC4KSm4KSwIOCkoOCkvuCkleCl | last post by:
hello friends i am trying to dynamically create graphs in browsers(as in graph theory, something like this http://sawamuland.com/flash/graph.html , not like excel graphs) but i am unable to find any starting point. are there some tutorials/libraries to do the same ? i am ok to develop these in javascript/xhtml/flash/etc as long as this can be done dynamically.
0
8502
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8418
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8696
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7466
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6254
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4239
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2836
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.