How can I draw a bar graph using netbeans?

Hello, I am quite new to java and netbeans. I have got the hang of placing controls on the forms and getting them to function.. Now I want to be able to draw a graph. Is there a way I can do this is net beans? Or is there a control that lets me draw lines into it, like the PictureBox in Visual Basic?
Thanks

Speedster239 wrote:
You need to get the grapics of the frame component in order to draw on it with java.awt.Graphics.
Use something like:
Graphics g = frame.getGraphics();
This is wrong. See the comment about subclassing JPanel. Demo:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class ExamplePanel extends JPanel implements ActionListener {
    private java.util.List<Shape> shapes = new ArrayList<Shape>();
    private Random rnd = new Random();
    public ExamplePanel() {
        new javax.swing.Timer(500, this).start();
    public void actionPerformed(ActionEvent evt) {
        int x = rnd.nextInt(getWidth());
        int y = rnd.nextInt(getHeight());
        shapes.add(new Rectangle(x-5, y-5, 10, 10));
        repaint();
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        for(Shape shape : shapes) {
            g2.draw(shape);
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable(){
            public void run() {
                ExamplePanel comp = new ExamplePanel();
                comp.setPreferredSize(new Dimension(400, 300));
                JFrame f = new JFrame();
                f.getContentPane().add(comp);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.pack();
                f.setLocationRelativeTo(null);
                f.setVisible(true);
}

Similar Messages

  • How can i make a bar graph in numbers to track trends

    I have a table with columns A-K. All the columns have needed data for other things.  I need to track trends of incorrect input by staff.  Column A has the date and column K has a 1 if incorrect or it's blank if correct.   I only need to use the month as I need to track total incorrect for the month to see if there is a downward or upward trend as training progresses.  (i need to create a line graph that shows the total incorrect per month)  I will be tracking for a long period of time so would be nice if the graph updated as I input more info into the table.

    Jan 1, 2014 12:00:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Meyers, Rebecka - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 2, 2014 7:33:59 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Meyers, Rebecka - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 3, 2014 7:56:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Skarda, David - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 3, 2014 4:17:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Skarda, David - Pediatric Surgery
    DIRTY
    540.0
    Jan 5, 2014 9:05:59 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Skarda, David - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 5, 2014 10:22:59 AM
    APPENDECTOMY (PEDS)
    Skarda, David - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 6, 2014 11:06:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Skarda, David - Pediatric Surgery
    CONTAMINATED
    540.1
    Jan 7, 2014 8:38:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 8, 2014 7:42:59 PM
    APPENDECTOMY (PEDS)
    Black, Richard - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 9, 2014 4:31:00 PM
    APPENDECTOMY (PEDS)#1
    Black, Richard - Pediatric Surgery
    CONTAMINATED
    541.0
    Jan 10, 2014 9:14:00 AM
    APPENDECTOMY (PEDS)#2
    Black, Richard - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.0
    1
    Jan 10, 2014 3:23:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)#3
    Barnhart, Douglas - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 12, 2014 11:09:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)#4
    Barnhart, Douglas - Pediatric Surgery
    CONTAMINATED
    540.0
    1
    Jan 12, 2014 3:52:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)#5
    Barnhart, Douglas - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 12, 2014 9:28:59 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)#6
    Barnhart, Douglas - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 13, 2014 5:47:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 13, 2014 7:19:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 14, 2014 12:52:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.0
    1
    Jan 16, 2014 7:33:00 AM
    APPENDECTOMY (PEDS)
    Black, Richard - Pediatric Surgery
    DIRTY
    540.9
    Jan 16, 2014 8:25:00 AM
    APPENDECTOMY (PEDS)
    Black, Richard - Pediatric Surgery
    DIRTY
    540.0
    Jan 16, 2014 10:51:00 AM
    APPENDECTOMY (PEDS)
    Black, Richard - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 17, 2014 7:58:59 AM
    APPENDECTOMY (PEDS)
    Barnhart, Douglas - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 18, 2014 4:49:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 19, 2014 8:19:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 20, 2014 7:30:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CLEAN-CONTAMINATED
    540.9
    1
    Jan 20, 2014 9:43:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 20, 2014 11:16:00 AM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    DIRTY
    540.0
    Jan 20, 2014 12:48:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Scaife, Eric - Pediatric Surgery
    NWCA
    540.9
    1
    Jan 20, 2014 9:48:59 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Rollins, Michael - Pediatric Surgery
    CONTAMINATED
    540.9
    Jan 22, 2014 12:08:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Barnhart, Douglas - Pediatric Surgery
    CLEAN
    540.9
    1
    Jan 22, 2014 5:38:00 PM
    APPENDECTOMY LAPAROSCOPY (PEDS)
    Rollins, Michael - Pediatric Surgery
    DIRTY
    540.0

  • How do I plot bar graph using MStudio.NE​T for VB

    I can not find the FillToBase property in waveformplot object using MStudio 7.0 for VB.NET. How can I plot the bar graph like that in Mstudio 6.0.

    The Measurement Studio .NET WaveformPlot does not currently have an equivalent for CWPlot's FillToBase property. In the meantime, though, you can use the WaveformPlot's custom drawing services to emulate this functionality. For example, if you dropped a new WaveformGraph on a form, you could copy and paste the following code to draw bar graphs on the WaveformPlot:
    Private Sub OnBeforeDrawPlot(ByVal sender As Object, ByVal e As BeforeDrawXYPlotEventArgs) Handles WaveformPlot1.BeforeDraw
    DrawBarGraph(e, 0, Color.BurlyWood, Color.Firebrick)
    End Sub
    Shared Sub DrawBarGraph(ByVal e As BeforeDrawXYPlotEventArgs, ByVal baseYValue As Double, ByVal outlineColor As Color, ByVal fillColor As Color)
    Dim plot As XYPlot = e.Plot
    Dim g As Graphics = e.Graphics
    If plot.HistoryCount > 0 Then
    ' Clip the data to just what will be drawn with the current axis ranges.
    Dim xData() As Double, yData() As Double
    plot.ClipData(xData, yData)
    ' Calculate the screen coordinates of a base y value and the clipped data.
    Dim baseY As Double = CType(plot.MapPoint(e.Bounds, 0, baseYValue).Y, Double)
    Dim points As PointF() = plot.MapData(e.Bounds, xData, yData, False)
    Dim outlinePen As Pen = Nothing
    Dim fillBrush As Brush = Nothing
    Try
    outlinePen = New Pen(outlineColor)
    fillBrush = New SolidBrush(fillColor)
    ' Iterate through the mapped points and calculate the bar, fill it, and outline it
    For i As Integer = 0 To points.Length - 2
    Dim currentPoint As PointF = points(i)
    Dim nextPoint As PointF = points(i + 1)
    Dim barX As Single = currentPoint.X
    Dim barY As Single = currentPoint.Y
    Dim barWidth As Single = nextPoint.X - currentPoint.X
    Dim barHeight As Single = baseY - currentPoint.Y
    g.FillRectangle(fillBrush, barX, barY, barWidth, barHeight)
    g.DrawRectangle(outlinePen, barX, barY, barWidth, barHeight)
    Next
    Finally
    If Not outlinePen Is Nothing Then
    outlinePen.Dispose()
    outlinePen = Nothing
    End If
    If Not fillBrush Is Nothing Then
    fillBrush.Dispose()
    fillBrush = Nothing
    End If
    End Try
    ' Cancel any further drawing since we completely handled the drawing of the plot.
    e.Cancel = True
    End If
    End Sub
    Hope this helps.
    - Elton

  • Help!How can i draw an image that do not need to be displayed?

    I want to draw an image and save it as an jpeg file.
    first I have to draw all the elements in an image object.I write a class inherit from Class Component,I want to use the method CreateImage,but I get null everytime.And i cannot use the method getGraphics of this object.Thus i can not draw the image.
    when i use an applet,it runs ok.I use panel and frame,and it fails.
    How can i draw an image without using applet,because my programme will be used on the server.
    Thank you.

    you could try this to create the hidden image
    try
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice gs = ge.getDefaultScreenDevice();
              GraphicsConfiguration gc = gs.getDefaultConfiguration();
              offImage = gc.createCompatibleImage(100, 100);
              offG = offImage.getGraphics();
          catch(Exception e)
              System.out.println(e.getMessage());
          }

  • How can I draw two differenct plots at the same graph?

    [I am beginner]
    I have two different set of data which have differenct x-axis values. How can I draw two data at the same plot?
    For example, one data set is
    x y
    1 3.5
    3 2.3
    5 1.3
    8 3.2
    The other
    1 2.3
    2.5 5.4
    4 2.5
    If I use m_graph.plotXvsY two times. But it draw only one graph at the same time.
    Please let me know. Thank you in advance.

    Do you really need the two sets of data on the same plot or is what you really care about is that the two sets of data are in the same graph? If it's the former, then there's not much that you can do since a plot can only contain one set of data. You can append to an existing set of data by calling the corresponding Chart (for example, ChartXvsY) method, but the result is that the plot's data will appear continuous.
    If it's the latter, the way to do this is to add multiple plots to the graph and plot each set of data in a separate plot. For example, go to the Plots tab in the graph's property pages, add another plot, then here's some sample code that demonstrates how to plot the sets of data from your example above:
    double xData1[] = { 1, 3, 5, 8 };
    double yData1[] = { 3.5, 2.3, 1.3, 3.2 };
    CNiReal64Vector xDataSet1(4, xData1), yDataSet1(4, yData1);
    m_graph.Plots.Item(1).PlotXvsY(xDataSet1, yDataSet1);
    double xData2[] = { 1, 2.5, 4 };
    double yData2[] = { 2.3, 5.4, 2.5 };
    CNiReal64Vector xDataSet2(3, xData2), yDataSet2(3, yData2);
    m_graph.Plots.Item(2).PlotXvsY(xDataSet2, yDataSet2);
    Hope this helps.
    - Elton

  • How to Draw a line Graph using x,y Cordinates in Java ?

    Hi,
    what r the easiest way to draw a line Graph using Java Code either applet.
    can u give me code sample. or any package where we can pass some parameter so that accoring to the paramter as i know jfreeChart.function() like some method is there from toold jChart.
    Is it possible.
    Regards,
    Prabhat

    There's a number of sample applications in one of the packages of freechart, one of which should do the trick.
    If you're doing applets I suggest you look at genjar from the sourceforge site. What that does is bundle classes from a set of library jars into one jar, selecting only classes that are referenced. That should simplify the transfer problem.
    To draw graphs, typically, you create a DefaultXYDataset object, add data points and then use the appropriate ChartFactory.createXXX methods to build a chart object. Then you wrap that in a ChartPanel to display.

  • How can I make a waveform graph store the entire wave, not just the current time period and how can I save the actual graph?

    I am taking temp readings with a 4 channel DAQ, sending them to a waveform graph and exporting the data to excel, how do I manipulate the graph to take a continuous reading as opposed to losing the previous GUI and how can I save the entire graph?
    Using LabVIEW 2011 operating on Windows 7 professional. 

    That is the nature of the chart -- everything not in the history is lost (it is a FIFO buffer of length=1024 samples by default).
    The scroll bar is probably grayed out because you're show all of the data.
    Attached is a program that will add 5 random points to a graph and prompt you for a file location where to save a JPG snapshot of the graph.  It's not particularly good programming style, but it has all of the elements/concepts you're after. 
    Attachments:
    graph.vi ‏14 KB

  • HT1338 Yesterday, I purchased Mountain Lion OSX and tried to download it but I don't think it worked.  How can I tell if I am using Mountain Lion and how do I get help if the download was unsuccessful?

    Yesterday, I purchased Mountain Lion OSX and tried to download it but I don't think the download worked.  How can I tell if I am using Mountain Lion and how do I get help if the download was unsuccessful?

    Click your Apple menu icon top left corner of your screen.
    From the drop down menu click About This Mac.
    If Mountain Lion is installed, it will say:  v10.8
    If not, launch the App Store. From the App Store menu bar click Store > Check for Unfinished Downloads
    FYI ..  for downloading Mountain Lion from the App Store, a high speed (broadband) internet connection is strongly recommended by Apple as noted here > iTUNES STORE - MAC APP STORE - TERMS AND CONDITIONS
    If you need to reinstall OS X or repair the the startup disk Mountain Lion Recovery, that requires broadband access to the internet via Wi-Fi or an Ethernet connection. OS X is downloaded over the internet form Apple when OS X Recovery is used for reinstallation.

  • How can I create side bars without cropping the image?

    I want to create side bars because I am projecting in an vertical panel, but if I crop the image them I only get the middle part of it.
    How can I create side bars in an way that I can still move the image inside?

    On a Video Track directly above the clip(s) you want to have behind the side bars, place a clip of Color (or whatever you want to use for your sidebars).
    Now go to the Effects Tab > Matte >Mask Shape and drag the Mask Shape filter to the Color clip you have placed on the timeline.
    Double click on the clip to open it in the viewer, and click on the Filters Tab.
    Click Invert Box, and adjust the shape to get the side bars you want.
    And now the clip(s) that are beneath this effect will have the side bars and be independent of it, so that you can move them around.
    MtD

  • How can i get the average graph?(DIAdem)

    hi,
    How can i get the average graph(2D-graph) of 10 measures?
    Can someone please help me?
    THX!!!

    Hello Charleen!
    If you want to do it programmatically have a look at the ChnAverage command in the help (see also StatBlockCalc for advanced calculations). Interactive you can use the statistic functions in the ANALYSIS device.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • How can we create such navigation buttons using Flash CS4?

    Hi,
    How can we create such navigation buttons using Flash CS4 is in the following website? Please help me with any such tutorial to make my custom navigation bar/buttons.
    http://city.reallusion.com/join.html
    Thanks.

    While the Note 4 is a reasonably large device it still falls into the phone layout bucket. We need this layout to function on very small screens some as low as 320 pixels high and 240 pixels wide. These sorts of devices don't have the space for a full toolbar.

  • ) how can we print the bar code in SAP_SCRIPTS?

    ) how can we print the bar code in SAP_SCRIPTS?

    hi Pavan,
    barcodes wil be generated in the printer itself, if you give <BC>&HD_GEN-MATERIAL_NUMBER&<> then you have a value for "Barcode" .
    Adding Your Own Bar Code:-
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/4a94fc51ea11d189570000e829fbbd/content.htm
    barcodes in SAP
    http://help.sap.com/saphelp_nw04/helpdata/en/68/4a0d5b74110d44b1b88d9b6aa1315b/content.htm
    Print Unique Indicator as a Barcode
    The printing of unique indicators of elements (reference numbers of records, case indicators, or document numbers) as barcodes is controlled by SAPscript forms.
    SAP delivers a common SAPscript form based on the SAP barcode type AUFNR for records, cases, documents and incoming post items.
    To create another SAP barcode type, you can copy the SAPscript form RMPS_BARCODE and then adjust it to your own requirements. Then you have to define the new form using the following attribute names in the table SCMGPARAM:
    From within a SAPscript form, a subroutine GET_BARCODE in the ABAP program QCJPERFO is called. Then the simple barcode contained there (‘First page’, ‘Next page’, ‘Last page’) is printed as local variable symbol.
    Definition in the SAPscript form:
    /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
    /: USING &PAGE&
    /: USING &NEXTPAGE&
    /: CHANGING &BARCODE&
    /: ENDPERFORM
    / &BARCODE&
    Coding of the calling ABAP program:
    REPORT QCJPERFO.
    FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
    OUT_PAR STRUCTURE ITCSY.
    DATA: PAGNUM LIKE SY-TABIX, "page number
    NEXTPAGE LIKE SY-TABIX. "number of next page
    READ TABLE IN_PAR WITH KEY ‘PAGE’.
    CHECK SY-SUBRC = 0.
    PAGNUM = IN_PAR-VALUE.
    READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.
    CHECK SY-SUBRC = 0.
    NEXTPAGE = IN_PAR-VALUE.
    READ TABLE OUT_PAR WITH KEY ‘BARCODE’.
    CHECK SY-SUBRC = 0.
    IF PAGNUM = 1.
    OUT_PAR-VALUE = ‘|’. "First page
    ELSE.
    OUT_PAR-VALUE = ‘||’. "Next page
    ENDIF.
    IF NEXTPAGE = 0.
    OUT_PAR-VALUE+2 = ‘L’. "Flag: last page
    ENDIF.
    MODIFY OUT_PAR INDEX SY-TABIX.
    ENDFORM.
    hope this helps you
    Regards,
    Jayant

  • How can I draw a line in Preview without the arrow head

    Hello all!
    How can I draw a line in Preview without the arrow head at the end of the line?

    Yes. Once you select the line bar a new entry will appear where you can select what type of line. Based on my experience whether or not it will change is iffy.

  • We have a large family, 5 kids and two adults all with iPads, iPhones, Mac Books, Servers....  How can we combine our purchases to use on all our devices.  We have two Apple ID's and sometimes buy multiple copies because of how we are limited...

    We have a large family, 5 kids and two adults all with iPads, iPhones, Mac Books, Servers....  How can we combine our purchases to use on all our devices.  We have two Apple ID's and sometimes buy multiple copies because of how we are limited...

    Hello Halfback71,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/ht5622
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
    If you are wondering how using multiple Apple IDs relate to iCloud, see Apple IDs and iCloud.
    Best of luck,
    Mario

  • How can i create multiple accounts but use the same itunes?

    how can i create multiple accounts but use the same itunes?

    Hi iCloud is Making Me Go Crazy,
    You will need to create a new Apple ID for your GameCenter and iCloud services.  You can continue to use the current Apple ID you share with your Mom for access to iTunes Store purchases if you wish. 
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Cheers,
    - Judy

Maybe you are looking for

  • Permanent error in BPE inbound processing

    Hi all, We have recently migrated are XI scenarios to a new server. In one of the file to rfc scenario whenver a file is processed i get the error in smq2: Permanent error in BPE inbound processing. The chances of BPM and mapping error  are less as t

  • Beat Mapping Logic 9 Problem

    Hi. I'm having difficulty getting beat mapping to work with Logic 9.1.6. I have tried to select the notes in my guide sequence but that yellow line all too often refuses to line up with the start of the relevant note. I tried copying all the beat not

  • Sql decode help

    I have the following 3 tables: Table A Id (Number) Id#2 (Number) Type (Number) Table B Id#2 (Number) Decription (Varchar2) Table C Id#2 (Number) Decription (Varchar2) I want to write a select statement that would return: Id from Table A, Description

  • Problem with Mail attachement

    Hi , Currently landscape is updated to Unicode, i'm getting blankspace after each character in the attachemnt. i have tested the same program on diffrent servers which is working properly. is this the unicode issue or help me out how to resolve the p

  • Trouble installing Photoshop Elements

    When I tryed to install I got an error message that told me to shut down the computer. When I tryed to install again it only wants to uninstall. What do I do next?? If I uninstall will the disk then be able to reinstall?