943,778 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 631
  • Java RSS
Aug 20th, 2008
0

Barchart

Expand Post »
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.

Java Syntax (Toggle Plain Text)
  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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
newtechie is offline Offline
33 posts
since Jul 2008
Aug 20th, 2008
0

Re: Barchart

            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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Aug 20th, 2008
0

Re: Barchart

i changed the code and it works now
Quote ...
EndLabel[0] = String.valueOf(value[0]);
EndLabel[1] = String.valueOf(value[1]);
EndLabel[2] = String.valueOf(value[2]);
EndLabel[3] = String.valueOf(value[3]);
Reputation Points: 10
Solved Threads: 0
Light Poster
newtechie is offline Offline
33 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Stacks Help
Next Thread in Java Forum Timeline: java Thread





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC