Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1085575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:42:22+00:00 2026-05-16T22:42:22+00:00

I have a tree structure that represents an org chart and I need to

  • 0

I have a tree structure that represents an org chart and I need to output the tree in PDF form. I have looked at Prefuse, JFreeChart, yFiles and JGraph but all seem to require that I write some logic. Has anyone done this before? Can anyone recommend a good library to use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:42:22+00:00Added an answer on May 16, 2026 at 10:42 pm

    You can use Jfree Chart to generate a graph/tree. I have used JFree Chat ,it is very simple.you have to put data in 2 d array pass it to method.

    /**
     * A simple demonstration application showing how to create a bar chart.
     * http://opengeekz.com
     */
    public class CreateBarChart  {
    
           String aFileName="image1.jpg";
           int width=250;
           int height=200;
           double quality=100;
           JFreeChart chart=null;
    
    /**
     * Create bar chart for given data
     * @param aFileName file name of image.
     * @param width Width of image.
     * @param height Height of image.
     * @param quality Quality of image file .
     */
       public CreateBarChart(String aFileName,int width,int height,double quality)
       {
           this.aFileName=aFileName;
            this.width=width;
           this.height=height;
           this.quality=quality;
       }
       public CreateBarChart()
       {
    
       }
    
       /**
        * Accept 2D array for graph row denotes x axis,column denotes y axis.
        * @param barchartdata 2D array for x axis, and y axis.
        * @return CategoryDataset
        */
    
        private static CategoryDataset createDataset(String barchartdata[][]) {
    
            // row keys...
            String series1 = "";
            // column keys...
    
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            for(int i=barchartdata.length-1;i>=0;i--)
            {
                if(barchartdata[i][0]==null)
                {
                    break;
                }
                else
                {
                    String value_str=barchartdata[i][0];
                    value_str=value_str.replaceAll("#","");
                    float value=0;
                    value=Integer.parseInt(value_str);
                    dataset.addValue(value, series1,barchartdata[i][1]);
                }
    
            }
            // create the dataset...
            return dataset;
    
        }
    /**
     *
     * @param barchartdata 2D array for x axis, and y axis.
     * @return JFreeChart object for data.
     */
        public  JFreeChart createChart(String barchartdata[][]) {
            CategoryDataset dataset = createDataset(barchartdata);
            chart = ChartFactory.createBarChart3D(
                "",         // chart title
                "",               // domain axis label
                "",                  // range axis label
                dataset,                  // data
                PlotOrientation.VERTICAL, // orientation
                false,                     // include legend
                false,                     // tooltips?
                false                     // URLs?
            );
    
            // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    
            // set the background color for the chart...
            chart.setBackgroundPaint(Color.white);
            chart.setPadding(RectangleInsets.ZERO_INSETS);
            // get a reference to the plot for further customisation...
            CategoryPlot plot = chart.getCategoryPlot();
            plot.setBackgroundPaint(Color.WHITE);
            plot.setDomainGridlinePaint(Color.white);
            plot.setDomainGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.white);
            plot.getDomainAxis().setCategoryMargin(0.0f);
    
            // set the range axis to display integers only...
            final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    
            // disable bar outlines...
            BarRenderer renderer = (BarRenderer) plot.getRenderer();
            renderer.setDrawBarOutline(true);
    
    
            // set up gradient paints for series...
            GradientPaint gp0 = new GradientPaint(
                0.0f, 0.0f,new Color(0,118,112),
                100.0f,100.0f,new Color(0,118,112)
            );
    
            renderer.setSeriesPaint(0, gp0);
    
            CategoryAxis domainAxis = plot.getDomainAxis();
            domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI /5.0)
            );
            // OPTIONAL CUSTOMISATION COMPLETED.
            try{
            saveToFile(chart, aFileName);
            }catch(Exception ex){ex.printStackTrace();}
            return chart;
    
    
        }
    /**
     * Save generated chart in jpg file.
     * @param chart Object of JFreeChart class
     * @param aFileName file name where jpg image to be saved.
     * @throws FileNotFoundException
     * @throws IOException
     */
         private  void saveToFile(JFreeChart chart,String aFileName)throws FileNotFoundException, IOException
        {
        BufferedImage img = draw(chart,width,height);
        FileOutputStream fos = new FileOutputStream(aFileName);
        JPEGImageEncoder encoder2 =JPEGCodec.createJPEGEncoder(fos);
        JPEGEncodeParam param2 = encoder2.getDefaultJPEGEncodeParam(img);
        param2.setQuality((float) quality, true);
        encoder2.encode(img,param2);
        fos.close();
        } // saveToFile
    
         /**
          * Draw bar chat for JFreeChart object
          * @param chart JFreeChart Object
          * @param width Width of image
          * @param height Height of Image
          * @return Object of Buffered Image class
          */
        private static BufferedImage draw(JFreeChart chart, int width, int height)
        {
        BufferedImage img =
        new BufferedImage(width , height,
        BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = img.createGraphics();
        try{
        chart.draw(g2, new Rectangle2D.Double(0, 0, width, height));
        g2.dispose();
        }catch(Exception ex){ex.printStackTrace();}
        return img;
        } // end draw
    
    /**
     *
     * @param args
     * @throws FileNotFoundException
     * @throws IOException
     */
        public static void main(String[] args) throws FileNotFoundException, IOException {
    
            CreateBarChart demo = new CreateBarChart("f:/image.jpg",250,300,100);
            String data[][]=new String[2][2];
            data[0][0]="30";
            data[0][1]="jan";
            data[1][0]="20";
            data[1][1]="feb";
            demo.createChart(data);
            demo.saveToFile(demo.chart,"iamge.jpg");
    
        }
    
    }
    

    This is a simple example of Jfree chart.
    You can use iText for Pdf Generation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.