Barchart

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 28
Reputation: newtechie is an unknown quantity at this point 
Solved Threads: 0
newtechie newtechie is offline Offline
Light Poster

Barchart

 
0
  #1
Aug 20th, 2008
i have a problem in getting the required display in barchart

my intended display is

year91 -------------- 110

but i get a display as

year91 -------------- year91

can anyone please let me know what is wrong in my html file or java code.

  1. import java.awt.*;
  2. import java.applet.*;
  3. public class BarChart extends Applet
  4. {
  5. int n =0;
  6. String label[];
  7. int value[];
  8. String EndLabel[];
  9. @Override
  10. public void init()
  11. {
  12. try
  13. {
  14. n= Integer.parseInt(getParameter("columns"));
  15. label = new String[n];
  16. value = new int[n];
  17. EndLabel = new String[n];
  18.  
  19. label[0] = getParameter("label1");
  20. label[1] = getParameter("label2");
  21. label[2] = getParameter("label3");
  22. label[3] = getParameter("label4");
  23.  
  24. value[0] = Integer.parseInt(getParameter("c1"));
  25. value[1] = Integer.parseInt(getParameter("c2"));
  26. value[2] = Integer.parseInt(getParameter("c3"));
  27. value[3] = Integer.parseInt(getParameter("c4"));
  28.  
  29. EndLabel[0] = getParameter("Label1");
  30. EndLabel[1] = getParameter("Label2");
  31. EndLabel[2] = getParameter("Label3");
  32. EndLabel[3] = getParameter("Label4");
  33. }
  34. catch(NumberFormatException e)
  35. {
  36. }
  37. }
  38. @Override
  39. public void paint(Graphics g)
  40. {
  41. for(int i=0;i<n;i++)
  42. {
  43. g.setColor(Color.red);
  44. g.drawString(label[i], 20, i*50+30);
  45. g.fillRect(60, i*50+10, value[i], 40);
  46. g.drawString( EndLabel[i],60+value[i]+10, i*50+30);
  47.  
  48. }
  49. }
  50. }
  51.  
  52. <HTML>
  53. <APPLET
  54. CODE= BarChart.class
  55. WIDTH=300
  56. HEIGHT=250>
  57. <PARAM NAME ="columns" VALUE ="4">
  58. <PARAM NAME ="c1" VALUE ="110" >
  59. <PARAM NAME ="c2" VALUE ="150">
  60. <PARAM NAME ="c3" VALUE ="100">
  61. <PARAM NAME ="c4" VALUE ="170">
  62. <PARAM NAME ="label1" VALUE ="year91">
  63. <PARAM NAME ="label2" VALUE ="year92">
  64. <PARAM NAME ="label3" VALUE ="year93">
  65. <PARAM NAME ="label4" VALUE ="year94">
  66. <PARAM NAME=EndLabel1 VALUE="110">
  67. <PARAM NAME=EndLabel2 VALUE="150">
  68. <PARAM NAME=EndLabel3 VALUE="100">
  69. <PARAM NAME=EndLabel4 VALUE="170">
  70. </APPLET>
  71.  
  72. </HTML>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Barchart

 
0
  #2
Aug 20th, 2008
            EndLabel[0] = getParameter("Label1");
            EndLabel[1] = getParameter("Label2");
            EndLabel[2] = getParameter("Label3");
           EndLabel[3] = getParameter("Label4");

<PARAM NAME="EndLabel1" VALUE="110">
<PARAM NAME="EndLabel2" VALUE="150">
<PARAM NAME="EndLabel3" VALUE="100">
<PARAM NAME="EndLabel4" VALUE="170">

You have getParameter looking for the parameter that goes with "Label1", etc. rather than "EndLabel1", etc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 28
Reputation: newtechie is an unknown quantity at this point 
Solved Threads: 0
newtechie newtechie is offline Offline
Light Poster

Re: Barchart

 
0
  #3
Aug 20th, 2008
i changed the code and it works now
EndLabel[0] = String.valueOf(value[0]);
EndLabel[1] = String.valueOf(value[1]);
EndLabel[2] = String.valueOf(value[2]);
EndLabel[3] = String.valueOf(value[3]);
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 524 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC