Bar Graph Formatting

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 5
Reputation: meanace is an unknown quantity at this point 
Solved Threads: 0
meanace meanace is offline Offline
Newbie Poster

Bar Graph Formatting

 
0
  #1
Sep 17th, 2009
Hi there.
I am producing a bar graph which uses values from a array.
I have tried many different ways of getting a fixed size bar graph.
Currently it prints the graph correctly with bars both above and below the x axis it also prints the reverse if the user inputted value is negative.
The problem i have is that at the moment if the user enters a large value say 100 the graph step down 100 lines to the x axis making the graph over 100 lines big (as negative bar graph is also included).
I have tried to use an equation inside the main for loop however it plays up with the graph.
Thanks for your sugesstions.

double array1[61];
double val1;
int q;
double input;

double array1[61];
double val1;
int q;
double input;

  1. for (val1 = 50; val1 >= 0; val1--)
  2. {
  3. cout << setw(6) << input--;
  4.  
  5. for (q = 0; q <= 60; q++)
  6. {
  7. if (array1[q] >= val1)
  8. {
  9. cout << "#";
  10. }
  11. else
  12. {
  13. cout << " ";
  14. }
  15. }
  16. cout << endl;
  17. }
  18.  
  19.  
  20.  
  21. for (val1 = 0; val1 >= -50; val1--)
  22. {
  23. cout << setw(6) << input--;
  24.  
  25. for (q = 0; q <= 60; q++)
  26. {
  27. if (array1[q] >= val1)
  28. {
  29. cout << " ";
  30. }
  31. else
  32. {
  33. cout << "#";
  34. }
  35. }
  36. cout << endl;
  37. }
  38.  
  39. cout << endl;
  40.  
  41. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Bar Graph Formatting

 
0
  #2
Sep 18th, 2009
Do you want to?

- clip extreme values, say if ( x > 25 ) x = 25 ?
- scale the graph (max=100), so px = x * 25 / max
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 5
Reputation: meanace is an unknown quantity at this point 
Solved Threads: 0
meanace meanace is offline Offline
Newbie Poster

Re: Bar Graph Formatting

 
0
  #3
Sep 18th, 2009
Hi
Id like to scale the graph so that if the user inputs a value the graph is shown at a reasonable size which works with both negative and positive inputted values.
Thank you.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Bar Graph Formatting

 
0
  #4
Sep 18th, 2009
OK, so start by calculating the input ranges, then you can create scale factors to map the input range to the output range.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 5
Reputation: meanace is an unknown quantity at this point 
Solved Threads: 0
meanace meanace is offline Offline
Newbie Poster

Re: Bar Graph Formatting

 
0
  #5
Sep 21st, 2009
Ive tried to make an equation in the for loop which decreases at a even scale but the graph plays up.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC