Results 1 to 8 of 8
  1. #1
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Generation of JFreeChart from CSV File

    I have created a utility to read data from csv files and generate JFreeChart for it. But now i want this utility to be command line so that i just need to paas the type of chart i want and it gets created. Can anybody please help me in doing so?
    Thanks in Advance.
    This is my code :
    import java.awt.Color;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;

    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartUtilities;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot3D;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.data.general.PieDataset;

    public class Mychart {


    private PieDataset createPieDataSet(String dataFileName) throws IOException {
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    BufferedReader bReader =new BufferedReader(new FileReader(dataFileName));
    String s;
    while ((s=bReader.readLine())!=null){
    String datavalue [] = s.split(",");
    String category = datavalue[0];
    String value = datavalue [1];
    pieDataset.setValue(category, Double.parseDouble(value));
    }
    bReader.close();

    return pieDataset;
    }

    private JFreeChart create3DPieChart(PieDataset dataset) {


    JFreeChart chart = ChartFactory.createPieChart3D(
    "Pie Chart", dataset, true, true, true);

    PiePlot3D p = (PiePlot3D) chart.getPlot();
    p.setForegroundAlpha(0.5f);
    p.setBackgroundAlpha(0.2f);

    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setTextAntiAlias(true);

    return chart;

    }

    public void saveChart(JFreeChart chart, String fileLocation) {
    String fileName = fileLocation;
    try {

    ChartUtilities.saveChartAsJPEG(new File(fileName), chart, 800, 600);
    } catch (IOException e) {
    e.printStackTrace();
    System.err.println("Problem occurred creating chart.");
    }
    }

    public static void main(String[] args) throws Exception {
    Mychart chartCreator = new Mychart();

    String dataFileLocation="sp.csv";

    /** Create a PieDataSet* */
    PieDataset pieDataset = chartCreator.createPieDataSet(dataFileLocation);

    /** Create 3D Pie Chart based on this dataset* */
    JFreeChart chart = chartCreator.create3DPieChart(pieDataset);

    /** Define a file location to save this chart */
    String fileLocation = "demo.png";

    /** Save the chart to the file system* */
    chartCreator.saveChart(chart, fileLocation);

    System.out.println("3D Pie Chart has been created successfully");
    System.out.println("Chart has been saved to: " + fileLocation);
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default Re: Generation of JFreeChart from CSV File

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default Re: Generation of JFreeChart from CSV File

    Quote Originally Posted by chaudhary3031@gmail.com View Post
    This is my code :
    You're Kushal?
    Kushal's Java Blog | Software Engineering Blog creating 3d pie chart in java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: Generation of JFreeChart from CSV File

    Quote Originally Posted by DarrylBurke View Post
    Yeah i mean to say that this is something i am using to generate jfreechart.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default Re: Generation of JFreeChart from CSV File

    You said
    This is my code :
    Learn to give credit where credit is due, and to not claim other people's work as your own.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: Generation of JFreeChart from CSV File

    Quote Originally Posted by DarrylBurke View Post
    You said

    Learn to give credit where credit is due, and to not claim other people's work as your own.

    db
    Yeah Its his code.I did not want to take his credit.I was just saying that this is something i have used to generate pie chart.can you please help me in generation of other charts?

  7. #7
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: Generation of JFreeChart from CSV File

    Learn not to give advises when you dont have any solution to the problem..

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default Re: Generation of JFreeChart from CSV File

    Yeah, that kind of snarky comment will have members falling over themselves to try to help you. Not.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2012, 01:53 PM
  2. Replies: 1
    Last Post: 02-22-2012, 06:22 PM
  3. War file generation
    By rummy in forum New To Java
    Replies: 1
    Last Post: 02-08-2010, 12:57 PM
  4. Xml File generation - xstream
    By sathishscjp in forum Advanced Java
    Replies: 2
    Last Post: 08-03-2009, 07:55 PM
  5. War file generation
    By vislawath.jawaharlal in forum Threads and Synchronization
    Replies: 0
    Last Post: 04-07-2009, 01:12 PM

Posting Permissions

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