1. ## Bar chart

How can i have Graphical view of let's say 4 different values as bar chart in J2ME. for example i have values 5000, 6900, 9050 and 10620. Then how can i create different color bars against these values. As i don't have even idea about creating bars so one can set scale but please let me know all that.

2. ## Re: Bar chart

For creating bar charts, you need to paint lines and color filled rectangles on the Canvas.

In the paint method of your Canvas, when yo want to draw the graph:
PHP Code:
``` // Ox,Oy are origin's, Wx & Hy are total width & height of the graph         g.setColor(192,192,192); // Grey         g.fillRect(Ox,Oy-Hy,Wx,Hy);            g.setColor(fgR,fgG,fgB);         g.drawLine(Ox,Oy,Wx+Ox,Oy); // x-axis         g.drawLine(Ox,Oy-Hy,Ox,Oy); // y-axis // use setColor(which you want) and use fillRect(to draw diff bars) // your values like 5000,6000,9050,10620 should be scaled down with ref. to Hy - say /100, and they become 50,60,90,106 if Hy is around 200  ```
thanks,
~Amitabh

3. ## Re: Bar chart

i don't understand the significance of the following lines in drawing the bars.

g.drawLine(Ox,Oy,Wx+Ox,Oy); // x-axis
g.drawLine(Ox,Oy-Hy,Ox,Oy); // y-axis

secondly please tell me what is the role of plus and minus in these co-ordinates: Wx+Ox and Oy-Hy.

4. ## Re: Bar chart

These lines were for the graph axis -- the x & y asix for the bar graph. Line is drawn from 1 point to another point, so we draw x axis from 0,0 to Width,0 --> a horizontal line. which is same as drawLine(Ox,Oy, Wx+Ox, Oy) drawing horizontal line from Orgin of graph.

thanks,
~Amitabh

5. ## Re: Bar chart

i praticed your suggested bar graphs and i learnt a lot. i face one problem i.e. these rectangles are drawn upside down. for example if i draw the rectangle as g.fillRect(20,250,10,30); , 10 is the width and 30 is the height but the direction of length is upside down. what if i want to reverse it. i mean i want to draw the line downside up. i tried g.fillRect(20,250,10,-30); but there is not display on the emulator.

6. ## Re: Bar chart

Height can't be negative, rect's are drawn upside down so putin some maths and try this:

g.fillRect(20,280,10,30); // instead of 250 and you will get the bar at the right place.

g.fillRect (20,250+barhieght,10, barheight);

thanks,
~Amitabh

7. ## Re: Bar chart

i am not getting the point. i want my application to draw bars from bottom up. if you please tell me the techinque of math you are talking about.

8. ## Re: Bar chart

The canvas Top|Left is defined as 0,0.

So can you tell me the base line of your Graph (Y), on which you want to draw your bar's.

Example: My Screen Size id 240x320, my base line X-axis is from (0,300 to 240,300) i.e. Y of graph baseline is 300.

Now I want to paint 2 bar's one of 100 and other of 50 height on this base line.

I will do it like this: g.fillRect (20,300-barhieght,10, barheight); where bar height for 1 will be 50 for other will be 100.

i.e. g.fillRect(20,250,10, 50);
g.fillRect(20,200,10, 100);

It makes no diff. if the bar's are drawn buttoms up or upside down... if the maths is correct the final result will be OK on the screen once the bar's are visible.

thanks,
~Amitabh

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•