Plot line, bar and pie chart

Anyone can let me know where can i learn or tutorial on how to plot line, bar and pie chart by using java2D... (no third-party software)....
thanks in advance.

Here's a pie chart app I made for an earlier question:
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;
public class PieChart {
  public static void main(String[] args) {
    int[] data = {
      18, 95, 102, 87
    PieCharter pie = new PieCharter();
    pie.enterData(data);
    JFrame f = new JFrame("Pie Chart");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(pie);
    f.setSize(400,300);
    f.setLocation(300,300);
    f.setVisible(true);
class PieCharter extends JPanel {
  int[] data, percents;
  int dataTotal;
  final int
    PAD = 25,
    R_PAD = 5;
  public PieCharter() {
    setBackground(Color.white);
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
    Font font = new Font("lucida sans unicode", Font.PLAIN, 16);
    g2.setFont(font);
    FontRenderContext frc = g2.getFontRenderContext();
    int width = getWidth();
    int height = getHeight();
    int cx = width/2;
    int cy = height/2;
    int dia = (int)Math.min(width, height) - 2*PAD;
    g2.draw(new Ellipse2D.Double((width - dia)/2, (height - dia)/2, dia, dia));
    // draw zero datum
    double radians = 0;
    int x = cx + (int)((dia/2) * Math.cos(radians));
    int y = cy - (int)((dia/2) * Math.sin(radians));
    g2.draw(new Line2D.Double(cx, cy, x, y));
    String s;
    int dataWidth, dataHeight, deltaR, rXInc, rYInc;
    for(int i = 0; i < data.length; i++) {
      radians += 2*Math.PI * data/dataTotal;
x = cx + (int)((dia/2) * Math.cos(radians));
y = cy - (int)((dia/2) * Math.sin(radians));
g2.draw(new Line2D.Double(cx, cy, x, y));
s = String.valueOf(percents[i]) + "%";
dataWidth = (int)font.getStringBounds(s, frc).getWidth();
dataHeight = (int)font.getLineMetrics(s, frc).getAscent();
deltaR = (int)Math.sqrt(dataWidth*dataWidth + dataHeight*dataHeight)/2 + R_PAD;
rXInc = (int)(deltaR * Math.cos(radians));
rYInc = (int)(deltaR * Math.sin(radians));
x += rXInc;
y -= rYInc;
x -= dataWidth/2;
y += dataHeight/2;
g2.drawString(s, x, y);
s = String.valueOf(data[i]);
dataWidth = (int)font.getStringBounds(s, frc).getWidth();
dataHeight = (int)font.getLineMetrics(s, frc).getAscent();
x = cx + (int)((dia/4) * Math.cos(radians - 2*Math.PI * data[i]/(2*dataTotal)));
y = cy - (int)((dia/4) * Math.sin(radians - 2*Math.PI * data[i]/(2*dataTotal)));
x -= dataWidth/2;
y += dataHeight/2;
g2.drawString(s, x, y);
private void prepareData() {
for(int i = 0; i < data.length; i++)
dataTotal += data[i];
percents = new int[data.length];
int dataPlus = 0;
for(int i = 0; i < data.length; i++) {
dataPlus += data[i];
percents[i] = Math.round(100 * dataPlus/dataTotal);
public void enterData(int[] data) {
this.data = data;
prepareData();
repaint();

Similar Messages

  • Bar and Pie chart  display with values

    Hi All...
    I want implement the my swing application Bar and Pie chart functionality with vales, If both are disply same veues.
    Thanx to Advance
    Arjun

    www.jfree.org

  • Drilldown bar and pie charts

    I am looking for charts with drilldown feature. I need to drilldown to another chart or a report.
    can you please point me to any articles doing this from scratch? I looked the sample packaged application with charts but it does not have drilldown links,.

    For all charts, the first column "link" is what you're interested in
    The syntax for the select statement of a chart is:
    SELECT link, label, value FROM   ...
    Where:
    link is a URL. This URL will be called if the user clicks on the that point on the resulting chart.
    http://docs.oracle.com/cd/E11882_01/appdev.112/e11945/bar_chart.htm#BEHGDBBE
    unfortunately no examples here, but check inline help for expected SQL in charts. Just define a URL for your drill down destination.

  • Bar Chart and Pie Chart

    Hi!
    In My application i want to create few bar and pie chart.
    If is there any code for generating bar and pie chart,
    pl send me.
    If third party software is available tell me the details of it.

    Sure, this functionality would be nice to have right
    out of the box, but when you think about it: should
    Sun be distributing a reporting SDK and promoting bad
    practices anyhow? Implementing your reporting in
    disparate and distributed manners is just plain messy
    and definitely translates to a bad practice. Turning
    to a centralized reporting mechanism, driven by a
    reporting server that can handle the needs for 80% of
    your requirements is a helluva lot more thoughtful and
    mindful than implementing separate mini reporting
    engines encapsulated within each and every application
    that you deploy.Elegantly stated! On a practical point, my company built an Enterprised based reporting solution on top of Java technology within the windows environment (please be kind). Specifically we used Java, ASP and Javascript (no VBScript), and delivered the information using the Microsoft IE 4 and 5.
    However, since Microsoft chose to elminate Java from it's current browser (IE6), we have to throw two years of coding away. We are now in the process of moving backward (technically speaking) to a desktop reporting model using Java (no browser technology) that accesses an Enterprise database, or embedded Java database. None of our customers are using Netscape, so that was never an option. Microsoft's and Sun's inablity to cooperate almost decimated our company's product line (and it still may).
    So I agree with you that an Enterprise server based reporting solution is the best architecture, and yet here I am running away from it after a two year struggle with competing standards. Sometimes the best solution loses for reasons that are simply not technical in nature.

  • Bar of Pie Chart and Age Population Chart ?

    Hi,
    I've got the last version of numbers and I'am asked for an assignement to do a Bar of Pie Chart and an Age Population Chart.
    I tried everything and searched on the internet but couldn't manage to find what I'm looking for.
    Could anyone explain how to do those ?
    Thanks

    Hi Vic,
    So "Bar of Pie" wasn't a typo! Looks like Jerry (and I) had a different interpretation of what you were trying to do.
    What you have there is two separate charts, using two separate (but related) sets of Data.
    The Pie chart uses the data listed on the table to the left below—individual numbers for the pets whose count is three or greater, and a grouped count for the others.
    The Stacked Bar chart uses a separate data set, listed on the second table—the individual counts for those pets represented fewer than three times each.
    Here's a variation.
    Charts are using the default colours as assigned by Numbers.
    See the Numbers '09 User Guide for details on reformatting the charts.
    Regards,
    Barry

  • Bar chart and pie chart in same screen at a time

    hi experts,
    I am trying to display the bar chart and pie chart in two separate containers in same screen .I wrote code for this in PBO of screen by using the function module  GFW_PRES_SHOW , but it is showing one chart at a time which is lastly executed in the PBO.
    I need to display two charts in two container at a time by calling the same function modules two times first time for bar chart second time for pie chart by changing the  parameter 
    presentation_type      = 1 for bar chart
    presentation_type      = 31 for pie chart.
    please help me in this regard asap.
    Thanks,
    K.Rajesh.

    Hi..
    Instead of using the FMs .. you should use the Object oriented approach for the same.
    Brief steps:
    You should have 2 control areas and 2 containers.
    Define different instances of 2 controls and attach them to the 2 containers.
    Call individual methods to display the controls in PBO.
    This should show both at a time. It is really simple.
    As an example you can go to SE38. From the (sap) menu go to Environment -> Examples -> Control Examples.
    Here you will see lot of examples.
    Regards,
    Varun.

  • Crating bar graphs and pie charts

    hi every body
    in my application there is a need of bar graphs and pie charts can any body help me how to draw them

    try http://www.jfree.org/jfreechart/

  • ActiveX and pie chart problem

    I am trying to create a bar of pie chart in Excel 2003. I am able to insert my data and create the chart, but I need to set the "SplitValue" to 6. I was able to find the property for doing this but I get an error when I run the vi (see attached).  Any thoughts?
    Solved!
    Go to Solution.
    Attachments:
    ActiveX Error.PNG ‏45 KB

    I think your problem is that you don't have "Index" wired for the ChartGroups property. Thus, it may be returning a collection of chart groups, but you are typecasting it to a single chart group.

  • ITS and Pie Charts

    We need to display charts (bar and pie) in a Web report/application running on SAP 4.6 and ITS (no WebAS, no BSP, no Portal). We need those charts to be real-time (not saved as a static image). The charts are user-specific. How would you do it?
    I have few ideas:
    1. Build bar charts with HTML tables or image blocks. No pie charts are possible.
    2. Generate PDFs using Sapscript/Smartforms and call PDF from the Web page. Questions: Can you have charts in this solution? Can you generate those PDFs on the fly?
    3. Use Adobe SVG for client side charts (SVG viewer is required)
    4. Use ActiveX or Java Applets
    Thank you for advice.

    Kai,
    It's a great suggestion to use IGS. But I am still not sure how this would work. Yes, I can use classes in the ABAP dialog program to call IGS. But how do I pass the images to ITS?
    I see few possible scenarios. Am I close?
    1. Responding to a call from ABAP, IGS is generating a GIF image and saves it in a location accessible from the Web (e.g. ITS WGate or IGS server). IGS is returning a reference for the image name/location to the ABAP dialog program. The reference is passed to ITS HTML template.
    2. Responding to a call from ABAP, IGS is returning a bitstream of the image back to the calling program. There should be a way to save it as GIF in ABAP and post the GIF image to WGate as a MIME object. Also, if I can save it a GIF in SAP, I can alternatively build a smartform that would use that newly generated GIF and convert the document into a PDF an then display the PDF with a text and charts on the Web.
    3. You call IGS directly from ITS, not the ABAP. You pass parameters to IGS telling what chart do you need and what data to use. IGS returns a GIF image back to ITS.
    Can please provide some clarity here.
    Thank you,
    Andre Polakoff

  • Is Apple allow core plot framework to draw Pie chart in iPhone application?

    Is Apple allow core plot framework to draw Pie chart in iPhone application?
    http://code.google.com/p/core-plot/wiki/AppsUsingCorePlot

    Wrong forum. Ask in the developer's forum.

  • Copying Graphs and Pie Charts generated in Analysis View to Email item using Excel VBA Macro Code

    Hi
    I am currently working on an exce VBA macro code that would help me take snapshots of the Graphs and Pie charts generated in QC for a particular application and copy the same to an email item using excel VBA macro code.
    I was able to write the code to create an email item. But I have no clue of how i can take snapshot of the graphs in Analysis View using excel VBA
    Any help would be highly appreciated.
    Thanks in Advance
    Regards
    Amit

    useramit,
    You are in the consumer end products forum.  You will also want to ask your question over at the Enterprise Business Community.
    Click the plus sign (+) next to Discussion Boards to drop down all the options for servers, networking and any other professionally related problems.
    http://h30499.www3.hp.com/

  • How to create bar and pie graph from a backing bean in ADF

    HI,
    my requirement is to populate a line and pie graph based on a collection in a backing bean.
    I got the solution for the bar graph with setTabularData(list data) method in one of the thread.
    For bar graph,
    i constructed the list for the setTabularData(list) method but it is not working with the line and pie graph.Coul'd you explain why?..
    Is it different for the line and pie graph.I don't want to use adf bindings.
    thanks in advance.
    Anil.G

    HI,
    my requirement is to populate a line and pie graph based on a collection in a backing bean.
    I got the solution for the bar graph with setTabularData(list data) method in one of the thread.
    For bar graph,
    i constructed the list for the setTabularData(list) method but it is not working with the line and pie graph.Coul'd you explain why?..
    Is it different for the line and pie graph.I don't want to use adf bindings.
    thanks in advance.
    Anil.G

  • Table sorter and pie chart in sapui5

    Hi ,
       I have one combobox and table(i have table columns city , state, country, zone).... on change of combobox value(combobox values are city , state...) i want to sort table and display pie chart according to  sorted table values.
    Can anyone help me on this....
    Regards,
    Sathish.

    Hi Sathish,
    You can refer below link, it will help you to build your own custom solution. It has everything you need.
    Custom sorter and filter in SAPUI5 Table
    Regards,
    Shankar

  • SMART FORM AND PIE CHART

    thanks for ur reply ,
    my req. to get a picture of pie chart in Smart Form .
    am doing
    1) write a pie chat program using the dynamic data .
    2) convert into bmp and upload into se78
    3) read the pic in smart form .
    is there any other better way
    can u mention the class n method
    its urgent
      Am getting short dump  
    DATA : D TYPE GFW_EXP_DATA,
                 R TYPE SYMSGNO.
          DATA: S TYPE STRING,
          N TYPE I, gp_inst type ref to cl_gui_gp_pres.
             CALL METHOD GP_INST->IF_GRAPHIC_PROXY~EXPORT
                            EXPORTING
                              FORMAT         =
    IF_GRAPHIC_PROXY=>co_format_bmp
                              WIDTH          = 50
                              HEIGHT         = 200
                             NAME           =
                            IMPORTING
                              CONTENT_TYPE   = S
                              CONTENT_LENGTH = N
                               CONTENT        = D
                               RETVAL         = R
    A RAISE statement in the program "SAPLCNDP " raised the exception
    condition "DP_ERROR_GET_DATA".                                  
    Since the exception was not intercepted by a superior program   
    in the hierarchy, processing was terminated.                    
    cheers
    senthil

    Hi Kai,
    Thanks a lot for your reply. The note 584593 has already been implemented.
    Program is calling the following statement.
    elseif format = if_graphic_proxy=>co_format_bmp. 
       call method adapt_classref->call_method        
         exporting method  = 'SaveImage'              
                   p1      =  1 " save as bmp         
                   p2      = name                     
                   p_count = 2.                       
    endif.                                           
    But it's not creating the file.
    I would really appreciate your help. Let me know if you have any suggestions.
    Thanks.
    B. Shah

  • SVG and pie charts

    Can anyone please give me the code for creating pie charts in svg from xml.
    Thanks

    Search this forum about "SVG" and you will find, amongst other SVG topics, the following link: http://technet.oracle.com:89/ubb/Forum11/HTML/003993.html
    succes

Maybe you are looking for

  • StandardEmitterMBean only in JDK1.6

    Since I am using JDK1.5, there doesn't seem to be a way to mimic StandardEmitterMBean. Based on http://blogs.sun.com/jmxetc/entry/javax_management_standardmbean_when_and I am currently doing the following: * where {@code IFoo} is my MBean interface F

  • T400 WWAN Adapter Issue

    I've successfully utilized WWAN capability on a T400 for a long time. So, now it's not working all of a sudden??? Device Manager says "Device Working Properly", radio is visible along with Wi-Fi and Bluetooth. Just doesn't show Broadband connections

  • Legacy file vault - new machine.

    This will probably be a stupid question - please bear with me - 59 year old, largely self taught regarding tech stuff. I have a 2007 macbook pro with legacy filevault enabled. I realised after I had installed Lion that there was a new version of file

  • Help! Optical drive bay enclousure bent

    Hi I am trying to install a SSD in my 2010 Mac Pro but while trying to pull out the metal optical case it got bent some. My CD player will not come out when pressing the eject button. It's not aligned and the entire metal enclosure case is extremely

  • LV7-style icon editor in LV2011

    Onece (two minutes ago) I tried to open Icon Editor double clicking icon of a VI. Suddenly "Old" Icon Editor (known from LabVIEW 7 and other old versions) was opened and ready to edit the icon. The computer has only LabVIEW 2011 installed. 1. I admit