Simple Bar Graph

What I'm trying to do is make a simple bar graph, with multiple bars of different colors and do this using an array. I create a new bar, set its size and color, and then create another bar, set its size, color and i've also moved it over 10 pixels so its not ontop of the original bar. And I'm using an array for the ractangle shap, and fillrect to fill it.
My problem comes when I add the object to the pane ( frame.getContentPane().add(blue); )
It only adds the last one, it doesn't add the blue bar. does getContentPane repaint the screen or something, so that the previous one doesn't show? Or am I missing something?
Thanks for any input,
Bar Class
import javax.swing.JPanel;
import java.awt.*;
public class Bar extends JPanel
   private int[] xBar = {25, 25, 30, 30};
   private int[] yBar = {350, 100, 100, 350};
     private Color fillColor;
   public Bar()
      setBackground(Color.black);
     public void setSize(int height)
          yBar[1] = height * 10;
          yBar[2] = height * 10;     
     public void changeColor(Color colour)
          fillColor = colour;
     public void moveOver(){
          for(int i = 0; i < xBar.length;i++)
               xBar= xBar[i] + 10;
     // Draws the bar
public void paintComponent(Graphics gc)
super.paintComponent(gc);
gc.setColor(fillColor);
gc.fillPolygon(xBar, yBar, xBar.length); // draw bar
BarChart classimport javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
public class BarChart
// Creates the main frame of the program.
public static void main(String[] args)
JFrame frame = new JFrame("Bar Chart");
          Bar red = new Bar();
          Bar blue = new Bar();
          red.setSize(9);
          red.changeColor(Color.RED);
          blue.moveOver();
          blue.setSize(5);
          blue.changeColor(Color.BLUE);
frame.getContentPane().add(blue);
frame.getContentPane().add(red);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
          frame.setSize(400,400);

Ok, I've recreated the whole thing. And it seems to work well, my only problem now is that the graph seems to move on the x-coordinate randomly each time I recompile and run it. Any idea's on why it may do this? I had a friend look at it, and he said it seems to be calling the draw method multiple times, but I cant figure out how, or why it would even do that. So my question is, why is the graph shifting across the screen each time I compile it and run it?
import javax.swing.JFrame;
import java.io.*;
public class BarGraphDriver
     public static void main(String[] args)
          int[] input = {5, 60, 20, 100};//Set height of each bar in the graph (number between 0 and 10
          JFrame frame = new JFrame("Bar Graph");
          BarPanel panel = new BarPanel(input);
      frame.getContentPane().add(panel);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setVisible(true);     
          frame.setSize(600, 450);
import javax.swing.JPanel;
import java.awt.*;
public class BarPanel extends JPanel
     Bar graph;
   //  Sets up the panel characteristics.
   public BarPanel(int[] values)
          JPanel panel = new JPanel();
          panel.setLayout(null);     
          graph = new Bar(values);     
      setBackground(Color.black);
   //  Draws the bar
     public void paintComponent(Graphics gc)
      super.paintComponent(gc);
          graph.draw(gc);
import javax.swing.JPanel;
import java.awt.*;
public class Bar extends JPanel
   private int[] xBar = {10, 10, 60, 60};
   private int[] yBar = {300, 100, 100, 300};
     private int data[];
     private int origData[];
   public Bar( int initVal[] )
          data = new int[initVal.length];
          origData = new int[initVal.length];
          for(int i=0; i<initVal.length; i++)
               origData[i] = initVal;          
               data[i] = Math.abs(initVal[i] - 300);
public void draw(Graphics gc)
          gc.setColor(Color.RED);
          gc.drawLine(10, 301, 600, 301);//horizontal redline
          gc.drawLine(10, 301, 10, 10);//vertical redline
          for(int h = 0; h<data.length; h++)
               gc.setColor(Color.GRAY);
               gc.drawLine(10, data[h] + 1, 600, data[h] + 1);//horizontal redline
          for (int i=0; i<data.length; i++) //countes each bar
               for (int j=0; j<xBar.length; j++)
                    xBar[j] = xBar[j] + 60;          
               if (data[i] >= 1 || data[i] < yBar.length)
                    for(int k = 1; k < 3; k++){
                         yBar[k] = data[i];
               gc.setColor(Color.BLUE);
          gc.fillPolygon(xBar, yBar, yBar.length); // draw bar
               int xText = xBar[0];
               int yText = data[i] - 10;               
               gc.setColor(Color.WHITE);
               gc.drawString(" " + origData[i], xText, yText);     
Edited by: mark2685 on Oct 31, 2008 12:10 PM
Edited by: mark2685 on Oct 31, 2008 12:14 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • OBIEE 11g - change bar graph result to "rectangle" instead of "gradient"

    Hi, I'm a big believe in Stephen Few's theory that anything that adds extra ink and/or causes visual distraction is poor design for presenting information. I've already figured out how to remove the shadow effect from all graphs (by setting visualEffects="NONE" in the dvt-graph-skin.xml).
    I've noticed that simple bar graphs default to using a "gradient" fill (a.k.a. extra visual distraction), instead of just being a flat rectangle. I can change this on a graph by graph basis by setting the graph data style to "rectangle", but I have to do this every time. Is there a simple way to change the default to be "rectangle" instead of "gradient"?
    Thanks!
    Scott

    Not yet, and I've been too busy with some SEV 1 issues to goof around with it. I also need to open a ticket about default pivot table formatting - i.e. removing the background colors under the non-data areas, and they also seem to have some sort of gradient fill at the bottom. I'll let you know if I hear anything.
    Thx,
    Scott

  • How it is possible to bar graph. please give me the steps

    Hi ,
    Simple Bar Graph - Show the Actual as a bar on a monthly frequency,Target can be shown as a line.If the bar height exceeds that of the line, please show the bar in red; if it is lower than the line, please color it in green

    Use a stacked bar line combo. Create one column which only give a result if value < line value, create one column which only gives result if value >= line value.Put them in stacked bar.
    regards
    John
    http://www.obiee101.blogspot.com/

  • Pages '09 Bar Graph Color Help!

    Hi everyone.
    I am trying to make a chart in pages 09 and I have a wee bit of a problem.
    Lets say I make a bar graph, a simple one with 4 bars. What do I do if I want to change the color of just one bar? If I want the first bar to be red and the rest to be green for example. I already tried dragging the color onto one bar individually but all the bars are still changing with it.
    Thanks a million
    NeoXY

    Pages uses a single colour for each series of data. Each series is listed in a single column.
    Try moving the datum you want to show in a different colour one column to the right, leaving its cell in the 'regular' column empty.
    Select the original column(s) and the extra one, then choose the stacked bar graph (second item) from the Charts button's popup menu.
    Regards,
    Barry

  • DVT: Master-Detail Bar Graph

    Hi,
    JDev Version: 11.1.1.5.0
    I am using ADF DVT Bar Graphs to show the details of Master-Detail Tables. I found one useful sample at: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/057-dvt-master-detail-172847.pdf by Frank. This example contains Master as a Bar Graph and on clicking a particular Bar refreshes the detail table with corresponding detail content.
    I would like to have a similar behavior but the detail table should be another Bar Graph instead of a table. Can some one let me know or share some example to show how to have master-detail relationship with two bar graphs?
    Thanks in advance
    Rathnam

    Hi,
    creating an m-d begavior is quite simple:
    1) drag the parent collection (e.g. Departments) as a bar graph to a page
    2) Select the checkbox to set the selected pie as the current row
    3) drag and drop the dependent collection (e.g. Employees) as another graph
    4) either set changeEventPolicy=ppr in the PageDef file for the Employee Iterator or
    set the PartialTriggers property of the detail graph component to point to the parent
    Frank

  • Simple Bar Chart

    Post Author: millerka
    CA Forum: Charts and Graphs
    I hope someone can help i am trying to create a simple bar chart (well at least it is simple in excel) I have generated averages using formulas for a series of data and these formulas are in my GF1 i simply would like to create a chart of these few values in the report footer - that is it ..but i'm not sure what i should reference in "change of"? i am assuming i need an advance report ? in excel i would  simply refernce these values  and viola!
    any help would be greatly appreciated.

    Post Author: kushaljn
    CA Forum: Charts and Graphs
    It should be simple.
    Lets say you have X - Axis with values (AA, BB, CC etc). and Y-Axis bars with values (10, 15, 25)
    You will have to give onchange of the X-Axis. and in the bottom (Show Values) you will have to chose Y Axis (SUM/Avg/Max) what ever you desire.
    If you simply want to show the values without the summary operation, create a Formula field and insert it under Show Values. You will have to check the Don't summarize values.

  • Group bar graph

    Hello
    Is there a simple method to display data on bar graph where various Y-values for given X are staying like neighbors
    but not like one Y above another Y (I've seen on http://forums.ni.com/ni/board/message?board.id=170​&message.id=315293&query.id=2383347#M315293) ?
    I made a lot of manipulation on set up on a legend (Common plots, etc) without success.
    The only idea I have is to artificially offset X for all Y-values like this (X11,Y1), (X12, Y2) etc... and then plot it.
    I'm sure there is a easier way to get my expectation.
    I enclose a simple view how I want to get.
    Best regards
    Konrad
    Attachments:
    GroupBarGraph.jpg ‏21 KB

    srikrishnaNF
    What you mean bar plot width or where to find it ?
    I have LB 8.5.1, there is only Line Width for given plot and bar style ?
    I can modyfie bars only in simple way as I showed below in the file, but this is not what i expect.
    It is easy and first bar graph in Exel.
    KNRD
    Attachments:
    bar graph.JPG ‏40 KB

  • TabularData for DVT Stack bar Graph

    Dear All,
    I used tabulardata to supply value fro my stack bar graph component and I used the code below
    public class Stackbar
      public List getTabularData()
        ArrayList list = new ArrayList();
        String[] rowLabels = new String[]
          { "Dry Goods", "Wet Goods", "Misc Goods" };
        String[] colLabels = new String[]
          { "May 2009", "June 2009", "July 2009" };
        Double[][] values = new Double[][]
            { 50000d, 122000d, 175000d },
            { 90000d, 110000d, 150000d },
            { 65000d, 50000d, 95000d }};
        for (int c = 0; c < colLabels.length; c++)
          for (int r = 0; r < rowLabels.length; r++)
            list.add(new Object[]
                { colLabels[c], rowLabels[r], new Double(values[r][c]) });
        return list;
    }JSF is simple
    <dvt:barGraph id="barGraph1" subType="BAR_VERT_STACK2Y" shortDesc="Sample bar"
                              tabularData="#{viewScope.stackBarBean.tabularData}">
                  <dvt:background>
                    <dvt:specialEffects/>
                  </dvt:background>
                  <dvt:graphPlotArea/>
                  <dvt:seriesSet>
                    <dvt:series/>
                  </dvt:seriesSet>
                  <dvt:o1Axis/>
                  <dvt:y1Axis/>
                  <dvt:y2Axis/>
                  <dvt:legendArea automaticPlacement="AP_NEVER"/>
                </dvt:barGraph>But I am not able to have a stack bar graph and the data isnt stacking..
    Kindly see the image here http://imageshack.us/photo/my-images/831/stackbar.jpg/
    My playground code can be downloaded here...
    http://code.google.com/p/my-dev-projects/downloads/detail?name=PlayGround.zip&can=2&q=
    How do I formulate the tabular data values correctly so that I could achive the correct stack bar graph component
    Thanks.
    JDEV 11.1.1.6

    Well...found the solution myself...
    Kindly disregard please..thanks

  • Using the report generation toolkit, how do I make a bar graph verticle instead of horizontle?

    The attached vi is similar to what I am using, and it produces an Excel bar chart. I would really like to create the same chart, only vertically instead of horizontly. I have tried all kinds of things that don't work. Is there a way to do this that does work. I want a result similar to rotating the produced chart 90 degrees CCW.
    Thank you!
    Attachments:
    Chart Test.vi ‏20 KB

    you want to use a xy-graph.
    you can right click the plot legend to make a bar graph vertical.
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    bargraph2.jpg ‏91 KB

  • BO 4.0 webi: Conditional formatting on a bar graph

    Hi,
    Is it possible to fiormat a Bar graph conditionally in BO 4.0(SAP BO BI: web intelligence)..
    I want to create a bar graph that displays bar in Green color if the value of bar is greater than target set and Red if it is less than target, which is not doable with BO xi3.1 version.
    Please let me know if this can be doable with latest version of BO 4.0 webi.
    Thanks in advance..

    Hi Bharath,
    One workaround in 3.1 I have found is to use a stacked bar chart and then create two variables out of the measure you want to be green if over a certain amount and make the formula:
    =[Measure Object] Where([Measure Object] >= 10,000)
    and the 2nd variable formula for red:
    =[Measure Object] Where ([Measure Object] <10,000)
    Then place these two measure variables on top of each other where the measure values go. Then go into the color palette and make a custom palette with the first two colors green and red see if that gives you what you are looking for.
    Thanks

  • How to use a single variable in multiple schedules in bar graph

    Hello Experts,
    I am usiing a variable X in different schedules for creating a bar graph.This variable X is used in all schedules with different restrictions.For that reason I have to use X and follow some space after X to use it in another schedule. Is there any method to use X again base on schedule name? For example: If schedule1 then X where key=1000 and if schedule2 then X where key=2000.

    Hi,
    You can create a variable with the same name but use this in a small case...
    All the Best,
    Madhu....

  • Single Line and Stacked Bar Graph Representation

    Data to be plotted on graph is as follows
    Year and Month               Study               Planned Subject               Study-Site ID #               # Enrolled          
    2001 / 03          AMXN 9374               50     US-001               1          
    2001 / 04               AMXN 9374               50               FR-101               1          
    2001 / 04               AMXN 9374               50               SP-301               1          
    2001 / 04               AMXN 9374               50               US-001               2          
    2001 / 05               AMXN 9374               50               FR-101               1          
    2001 / 05               AMXN 9374               50               US-001               1          
    2001 / 06               AMXN 9374               50               FR-101               2          
    2001 / 06               AMXN 9374               50               SP-301               2          
    2001 / 06               AMXN 9374               50               US-001               1          
    I want to display the above data in line stacked bar graph format where the
    #Enrolled will be in Stacked Bar by Study -Site ( Y axis)
    Planned Subject should represent a single line at 50 ( Y axis)
    Group by Year and Month ( X- Axis)
    Study excluded ( Study will be selected from dashboard prompt)
    I'm getting the stacked view of Study Site ID correctly but I want Single Line for Planned Subject .
    Currently I'm getting multiple line .
    Eg for 2001/03 I'm getting line at 50 in yellow colour
    for 2001/04 I'm getting a line at 150 in different color since it has 3 Study-Site ID's But the desired output is Single Line at 50
    As per 11g doc this is not possible because there is some upgradation in the nature of the graph
    " Stacked line-bar graphs in which 2 or more measures are shown as lines on the same axis and are not stacked in 10g are stacked in 11g."
    Refer - http://docs.oracle.com/cd/E21764_01/bi.1111/e16452/apndx_ui_chngs.htm
    Is there any workaround for it ?

    Did you found any workaround for it ? I am too looking for same scenerio.

  • How to get bar graph in word in labwindow/CVI ?

    how to get bar graph in word in labwindow/CVI ?

    ashwinic9,
    spawning your question over more and more threads (the present one, this one and this other one) won't give you a faster answer; instead, it will irritate forum users! 
    Especially if you have at your disposal a fast way to perform a test. I pointed you some days ago to word report example, that writes a table to a word document: did you tried changing the graph into a bar graph and generating the report? I have done it for you and the result is OK, as you can see in the attached document.
    Now, since the example works well, there must be something in your particular situation that prevents the graph to be shown; that is: you must add some more data on your actual problem and maybe a small example that exposes the problem.
    But please: keep active only this discussion and let the other threads die! 
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?
    Attachments:
    wordreport.doc ‏38 KB

  • Creating a popup on mouse over in bar graph

    Hi,
    I want to create a popup using mouse over event on bar graph but I didn't find corresponding property in the property inspector. Is it possible to display a popup on mouse over in bar graph?
    At present I am able to create a popup in the backing bean based on click event. I want to align it to the bar in the graph which was clicked. But now, it is being aligned to the bar graph as a whole(like above the graph , below the graph) when I use "RichPopup.PopupHints.HintTypes.HINT_ALIGN_ID, source". Is there a way to align it to the particular bar?
    Any help is greatly appreciated
    Thank you,
    KK

    Hi,
    don't think you can align it to an area within a component. The align id property expects a component reference. Note that mouse over on a bar graph doesn't select the bar, which means that the data in the binding layer is not set to current (just in case that the data in the popup is meant to be dependent)
    Frank

  • How to create static line in line bar graph in obiee 11g?

    Hello,
    I have requirement where user wants to see a line in bar graph.
    Now the line is just static line, we dont have data field available to draw the line in graph.
    is there a way to create a static line in chart and show it in Line bar ombo graph??
    Thanks in advance..

    e.g. i created the static line '10' in fx and now using this column as line in line bar report , but its not displaying the line at measure of '10' in chart.
    Drag the column to measures section of graph (Line - Vertical Axis) to change this static value create an edit box prompt and pass the value to the column using Presentation Variable (as said by Fernando)
    Thanks,
    Saichand

Maybe you are looking for

  • Can I set up a data-driven menu box to have a default value?

    I'm working on building a little webpage that lets user's update one column. So, for this column.. I have setup a drop-down box giving choices (from a table). I'd like for the box's "default" selected value to be the one that is already choosen in th

  • Pdf default size

    hi all I'm displaying a pdf in wda application . The size of the pdf page is diffrent in diffrent system . When i run the application on my system it is coming as 54% page size by default where as when I'm executing the same application on other syst

  • Configure a intel i915 (Solved)

    I need help to configure a intel i915 chipset, I installed the 3ddesktop package, and the command "3ddesk" gives me this message: Xlib:  extension "GLX" missing on display ":0.0". Xlib:  extension "GLX" missing on display ":0.0". Xlib:  extension "GL

  • Condition Category - Pricing

    Hello, Why is that when we chose the condition category Q (Costing) for a condition type (say EK01 - a statistical condition type), we are unable to assign it to any access sequence. How do we do pricing in this case? Thanks Venkat

  • T400 cannot wake up or exit standby (suspend)

    When my T400 system enters standby mode, I am unable to "wake" it up.  The crescent moon light indicates on the bottom of the screen but when I press Fn F4, the system will not respond.  Closing and opening the lid does not work.  The only thing that