JFreeChart

Hi,
I have a line chart that iv created using jfreechart. The graph has six lines.when the graph comes up, there are no lines on it.This is delibrate. Iv also made six check boxes. The problem i have is that when the check boxes are checked, the lines are supposed to apear, each line corresponding to the boxes that has been checked. But the lines are'nt appearing when the boxes are checked. Please can someone help. Thank you for your help.

Here is the code iv written this is actually part of a bigger program
</code>
package seti;
public class Entropygraph extends JPanel implements ActionListener, ItemListener {
     JButton home;
     JButton back;
     JCheckBox Malay_Binary;
     JCheckBox English_Binary;
     JCheckBox Vizmusic_Binary;
     JCheckBox Polish_Binary;
     JCheckBox Welsh_Binary;
     JCheckBox Arecibo74b;
     boolean entdata = false;
     String entdata2;
     String entdata3 ;
     String entdata4 ;
     String entdata5 ;
     String entdata6 ;
     public Entropygraph() {
          super((new BorderLayout(40, 40)));
          JPanel topHandPanel = new JPanel();
          GridLayout gridLayout = new GridLayout(5, 100, 0, 10);
          topHandPanel.setLayout(gridLayout);
          topHandPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
          topHandPanel.setBackground(new Color(153, 205, 143));
          Malay_Binary = new JCheckBox("Malay");
     Malay_Binary.setMnemonic(KeyEvent.VK_C);
     Malay_Binary.setSelected(false);
     English_Binary = new JCheckBox("English");
     English_Binary.setMnemonic(KeyEvent.VK_G);
     English_Binary.setSelected(false);
     Vizmusic_Binary = new JCheckBox("Vismusic");
     Vizmusic_Binary.setMnemonic(KeyEvent.VK_M);
     Vizmusic_Binary.setSelected(false);
          Polish_Binary = new JCheckBox("Polish");
     Polish_Binary.setMnemonic(KeyEvent.VK_N);
     Polish_Binary.setSelected(false);
          Welsh_Binary = new JCheckBox("Welsh");
          Welsh_Binary.setMnemonic(KeyEvent.VK_B);
          Welsh_Binary.setSelected(false);
          Arecibo74b = new JCheckBox("Arecibo74b");
          Arecibo74b.setMnemonic(KeyEvent.VK_V);
          Arecibo74b.setSelected(false);
          home = new JButton("Home Page");
          back = new JButton("Back");
          topHandPanel.add(Malay_Binary);
          topHandPanel.add(English_Binary);
          topHandPanel.add(Vizmusic_Binary);
          topHandPanel.add(Polish_Binary);
          topHandPanel.add(Welsh_Binary);
          topHandPanel.add(Arecibo74b);
          topHandPanel.add(home);     
          topHandPanel.add(back);
          add(topHandPanel, BorderLayout.NORTH);
          final CategoryDataset edata = createDataset();
          final JFreeChart echart = createChart(edata);
          final ChartPanel chartPanel = new ChartPanel(echart);
          chartPanel.setLayout(new BorderLayout());
          chartPanel.setPreferredSize(new Dimension(1000, 450));
          add(chartPanel);
          setBorder(BorderFactory.createEmptyBorder(80, 40, 40, 40));
               //Register a listener for the check boxes.
          Malay_Binary.addItemListener(this);
          English_Binary.addItemListener(this);
          Vizmusic_Binary.addItemListener(this);
          Polish_Binary.addItemListener(this);
          Welsh_Binary.addItemListener(this);
          Arecibo74b.addItemListener(this);
          home.addActionListener(this);
          back.addActionListener(this);
     public void actionPerformed(ActionEvent ae) {
          MainPanel panel = (MainPanel) getParent();          
          if (home.equals(ae.getSource())) {
               panel.hideAll();
               panel.pageWelcome.setVisible(true);               
          } else if (back.equals(ae.getSource())) {
               panel.hideAll();
               panel.pageRead.setVisible(true);
     public void itemStateChanged(ItemEvent e) {
Object source = e.getItemSelectable();
// if (source == Malay_Binary) {
     //entdata = ;
//Now that we know which button was pushed, find out
//whether it was selected or de-selected.
// if (e.getStateChange() == ItemEvent.SELECTED) {          
     public CategoryDataset createDataset() {
          final String entdata = "Malay-Binary";
          final String entdata2 = "English-Binary";
          final String entdata3 = "Vizmusic-Binary";
          final String entdata4 = "Polish-Binary";
          final String entdata5 = "Welsh-Binary";
          final String entdata6 = "Arecibo74b";
          final String n0 = "0";
          final String n1 = "1";
          final String n2 = "2";
          final String n3 = "3";
          final String n4 = "4";
          final String n5 = "5";
          final String n6 = "6";
          final String n7 = "7";
          final String n8 = "8";
          final String n9 = "9";
          final String n10 = "10";
          final String n11 = "11";
          final String n12 = "12";
          final String n13 = "13";
          final String n14 = "14";
          final String n15 = "15";
          final DefaultCategoryDataset edata = new DefaultCategoryDataset();
          //This is all the data that is used to create
          //the Malay-Binary line chart.
// the data set has been removed so the code will fit on this post
          // This is all the data that is used to create
          // the English-Binary line chart
          // the data set has been removed so the code will fit on this post
          // This is all the data that is used to create
          // the Vizmusic-Binary line chart
     // the data set has been removed so the code will fit on this post
          // This is all the data that is used to create
          // the Polish-Binary line chart
// the data set has been removed so the code will fit on this post
          // This is all the data that is used to create
          // the Welsh-Binary line chart
     // the data set has been removed so the code will fit on this post
          // This is all the data that is used to create
          // the arecibo74b line chart
// the data set has been removed so the code will fit on this post
          return edata;
     private JFreeChart createChart(final CategoryDataset edata) {
          // create the chart...
          final JFreeChart chart = ChartFactory
                    .createLineChart(
                              "Visual Representation of the Entropy Calculation of the Incoming Digital signal",// chart
                              // title
                              "Bit Chunk Length", // x-axis label
                              "Entropic Values", // y-axis label
                              edata, // data
                              PlotOrientation.VERTICAL, // line graph position
                              true, // include legend
                              true, // this is for the tool tips
                              false
          chart.setBackgroundPaint(Color.white);
          final CategoryPlot plot = (CategoryPlot) chart.getPlot();
          plot.setBackgroundPaint(Color.black);
          plot.setRangeGridlinePaint(Color.green);
          final NumberAxis eaxis = (NumberAxis) plot.getRangeAxis();
          eaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
          eaxis.setAutoRangeIncludesZero(true);
          final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot
                    .getRenderer();
          renderer.setSeriesVisible(1, true);
          renderer.setSeriesStroke(0, new BasicStroke(3.0f,
                    BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND, 3.0f,
          new float[] { 1.0f, 1.0f }, 0.0f));
          renderer.setSeriesStroke(0, new BasicStroke(3.0f,
                    BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND, 5.0f,
                    new float[] { 1.0f, 1.0f }, 0.0f));
          renderer.setSeriesStroke(0, new BasicStroke(3.0f,
                    BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND, 7.0f,
                    new float[] { 1.0f, 1.0f }, 0.0f));
          renderer.setSeriesStroke(0, new BasicStroke(3.0f,
                    BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND, 9.0f,
                    new float[] { 1.0f, 1.0f }, 0.0f));
          renderer.setSeriesStroke(0, new BasicStroke(3.0f,
                    BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND, 11.0f,
                    new float[] { 1.0f, 1.0f }, 0.0f));
          renderer.setSeriesStroke(0, new BasicStroke(3.0f,
                    BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND, 13.0f,
                    new float[] { 1.0f, 1.0f }, 0.0f));
          return chart;
<code>

Similar Messages

  • Netbeans: adding to jPanel via code after init (jFreeChart)

    This will be my second post. Many thanks to those who replied to my first questions.
    I am using netbeans 5.5
    I am attempting to run the following jFreeChart demo but in netbeans.
    Original demo located here: http://www.java2s.com/Code/Java/Chart/JFreeChartPieChartDemo7.htm
    Instead of programically creating the jPanel like the demo does, i would like to do it using the netbeans GUI and then add the code to create the jFreeChart.
    In netbeans i create a new project, create a new jFrame and place a new jPanel on the form (keeping the variable name jPanel1) as illustrated below:
    * MainForm.java
    * Created on June 28, 2007, 1:48 PM
    package mypkg;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.chart.plot.PiePlot3D;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    * @author  me
    public class MainForm extends javax.swing.JFrame {
        /** Creates new form MainForm */
        public MainForm() {
            initComponents();
        /** Netbeans Auto-Generated Code goes here which I have omitted */                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainForm().setVisible(true);
        private void CreateChart() {
            DefaultPieDataset dataset = new DefaultPieDataset();
            dataset.setValue("Section 1", 23.3);
            dataset.setValue("Section 2", 56.5);
            dataset.setValue("Section 3", 43.3);
            dataset.setValue("Section 4", 11.1);
            JFreeChart chart3 = ChartFactory.createPieChart3D("Chart 3", dataset, false, false, false);
            PiePlot3D plot3 = (PiePlot3D) chart3.getPlot();
            plot3.setForegroundAlpha(0.6f);
            plot3.setCircular(true);
            jPanel1.add(new ChartPanel(chart3));
            jPanel1.validate();
        // Variables declaration - do not modify                    
        private javax.swing.JPanel jPanel1;
        // End of variables declaration                  
    }I then attempted to call the CreateChart() function in several places (in the MainForm() function, in the pre and post creation code properties of the jPanel's properties dialog in netbeans (as well as pre and post init in the same screen)) and nothing seems to work. the program compiles and the jFrame comes up but the chart does not show.
    If i run the example at the above noted link it runs fine in netbeans if i copy and paste the code directly, it just doesnt work when i try to get it to work through the netbeans GUI builder and the jPanel i create through it.
    Can any more advanced netbeans/java users lend me a hand or point me in the right direction?
    NOTE: in the code pasted above, i am only trying to run one of the four chart demo's listed in the original source in the link.
    NOTE2: in the code pasted above it doesnt show me calling CreateChart() from anywhere, im hoping to get some advice on how to proceed from here.
    Message was edited by:
    amadman

    Here is the netbeans generated code that i had omitted in the post above:
    private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            CreateChart(); //this is one of the many places i tried sticking the function
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 546, Short.MAX_VALUE)
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 398, Short.MAX_VALUE)
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
            pack();
        }// </editor-fold>   I believe this is what you mentioned looking for, or close to it:
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);any thoughts?

  • Problem to print a JPanel containing jfreeChart

    I need help
    I am developping an application that should display and print reports with histograms.
    I make the histogram with Jfreechart and put it on a JPanel. the report is a Vector of JPanel.
    1. When i print only the panel containing the JFreechart, the panel is printed but the range axis label
    of JFreechart is inverted.
    2. When i print all the report, nothing appears on the page of the panel containing JFreechart.
    here is my printing code:
    //code
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (pageIndex >= docToBePrinted.size()) {
    return (NO_SUCH_PAGE);
    } else {
    componentToBePrinted = docToBePrinted.get(pageIndex);
    //componentToBePrinted.repaint();
    Dimension dim = componentToBePrinted.getSize();
    double scaleX = pageFormat.getImageableWidth() / dim.width;
    double scaleY = pageFormat.getImageableHeight() / dim.height;
    double scale = Math.min(scaleX, scaleY);
    Graphics2D g2D = (Graphics2D) g;
    // g2D.translate(0, 0);
    g2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    g2D.scale(scale, scale);
    g2D.setPaintMode();
    disableDoubleBuffering(componentToBePrinted);
    componentToBePrinted.print(g2D);
    g2D.dispose();
    //componentToBePrinted.printAll(g2D);
    enableDoubleBuffering(componentToBePrinted);
    //componentToBePrinted.
    return (PAGE_EXISTS);
    //end of code
    "docToBePrinted" is the report
    Could anyone help me please !

    I have the same problem. Similarly to another entry here, be very careful about how many times you reattempt it. I did it several times, hoping it would work out a kink, and it was on an expensive order, now there are over $2000 of "temporary authorizations" depleting my available credit on my card, and it's been that way for almost a week now.
    I am living overseas, and am unfortunately restricted to dial-up internet to upload this, and it either gets stuck at 64kb/8Mb or just jumps right to 8/8Mb, when there is nothing wrong with the my internet connection.
    I emailed Apple in response to the order cancellation email, and stated that perhaps it was the army firewall I'm behind, asking for the site the program connects to in an attempt to unblock the site if it's inadvertently getting blocked on my end. When they replied they said it's a technical issue and that I can call Apple to talk with someone, where they will determine how much the call will cost. That's outrageous to have something brand new, and have to pay for them to help you on an issue that truly may be as simple as giving out a website.
    In response to an earlier reply, I am using iPhoto 5.0.4, and I just purchased my G5 back in October. Is there a later version to iLife that I'm not finding?
    If anyone finds help with this issue, I would greatly appreciate some tips!
    Thanks so much,
    Dave

  • Exception while adding a chrtpanel(component of JFreeChart) to JTextPane.

    hi,
    Please help for solving the following exception while adding a chrtpanel(component of JFreeChart) to JTextPane
    java.lang.ArrayIndexOutOfBoundsException: No such child: 0
         at java.awt.Container.getComponent(Container.java:237)
         at javax.swing.text.ComponentView$Invalidator.cacheChildSizes(ComponentView.jav
    a:399)
         at javax.swing.text.ComponentView$Invalidator.doLayout(ComponentView.java:383)
         at java.awt.Container.validateTree(Container.java:1092)
         at java.awt.Container.validate(Container.java:1067)
         at javax.swing.text.ComponentView$Invalidator.validateIfNecessary(ComponentView
    .java:394)
         at javax.swing.text.ComponentView$Invalidator.getPreferredSize(ComponentView.ja
    va:427)
         at javax.swing.text.ComponentView.getPreferredSpan(ComponentView.java:119)
         at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:679)
         at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:214)
         at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
         at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
         at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:881)
         at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
         at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
         at javax.swing.text.BoxView.layout(BoxView.java:682)
         at javax.swing.text.BoxView.setSize(BoxView.java:379)
         at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1599)
         at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:801)
         at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
         at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1212)
         at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)
         at java.awt.Container.layout(Container.java:1020)
         at java.awt.Container.doLayout(Container.java:1010)
         at java.awt.Container.validateTree(Container.java:1092)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validate(Container.java:1067)
         at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQu
    eueUtilities.java:116)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
    va:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
    :151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

    I tried with the following link
    http://www.onjava.com/pub/a/onjava/2004/03/10/blackmamba.html?page=2
    one place this one is getting solved. Some other places atill the exeception is present.

  • Setting colors for item labels in JFreeChart (WaferMapRenderer)

    Hi,
    first of all, sorry for posting a JFreeChart related posting on this forum, but I didn't get a solution right now (I even didn't find anything useful on the JFreeChart website/forum). Here's my question...
    I'm trying to set the color for item labels in the legend but with no success.
    Here's a code example:
    final JFreeChart chart = ChartFactory.createWaferMapChart(
        "Wafer Map Demo",         // title
        dataset,                  // wafermapdataset
        PlotOrientation.VERTICAL, // vertical = notchdown
        true,                     // legend          
        true,                    // tooltips
        false
    WaferMapPlot plot = (WaferMapPlot) chart.getPlot();
    WaferMapRenderer renderer = new WaferMapRenderer();
    renderer.setSeriesItemLabelPaint(0, Color.red);
    renderer.setSeriesItemLabelPaint(1, Color.blue);
    plot.setRenderer(renderer);The default behavior of the WaferMapRenderer is also strange because the item label as well as the item marker is painted black so you cannot distinguish different fields of the wafer map. Is this a bug or am I doing something wrong (or missing somehting)?
    Any help would be greatly appreciated.
    Thanks and best regards,
    - Stephan

    Your folder action script doesn't work because of one simple error:
    set label index of every item of entire contents of processFolder to 7
    Nowhere in your script is 'processFolder' defined, so AppleScript has no idea what you're trying to do.
    Given that you (correctly) iterate through added_items, the correct format would be:
    on adding folder items to this_folder after receiving added_items
      repeat with item_ in added_items
        tell application "Finder"
          set label index of item_ to 7
        end tell
      end repeat
    end adding folder items to
    In other words, this changes the label index of each item just added.
    That should work provided you're dropping files into this folder. If you're dropping folders then this would set the label index of the folder itself, but not necessarily the items within that folder. For that you'd need to add a check to see if item_ was a folder and add code to handle folders.
    Also note that this kind of folder action will only work on the folder itself - that is, if you have folder A that contains subfolder B, then dropping a file into subfolder B won't trigger the script and won't change that item's label. To do that you'd have to attach your folder action to subfolder B.

  • JFreeChart Line Chart points

    Hi coders, I have implemented a line chart from the JFreeChart and have got it working nearly how i want. The only problem i have now is that there are 2series using a line and 1 series using points, i was wondering if anyone knew how i could change the colour of the individual series and also the type of point or line they may have.
    public ChartPanel allAlgorithm()
                   final XYDataset alldataset = createDatasetLine();
                 final JFreeChart lineGraph1 = createChart(alldataset);
                 panel6 = new ChartPanel(lineGraph1);
                   return panel6;
              * Creates a sample dataset.
              * @return a sample dataset.
             private XYDataset createDatasetLine() {
                 XYSeries series0 = new XYSeries("Straight Comaprison");
                  XYSeries series1 = new XYSeries("Minimum Edit Distance");
                 XYSeries series2 = new XYSeries("Longest Common Sequence");
                 int users = 1;
                 resultsArray = results.getResultSet();
                   //assign the results data to the ArrayList
                   int totalFile = resultsArray.length;;
                   //a for loop to returnt he usernames from the ArrayList and also to
                   //return the data from the 2D Array
                  for (int i = 0; i < resultsArray.length; i++){
                       String x = StraComp[0];
                   String y = MinEdit[i][0];
                   String z = Lcs[i][0];
                             //System.out.println("Total File Size"+totalFile);
                             if(x.equals("XXXX")){
                                  //do nothing
                             }else{
                                  //changes the value to a double
                                  double dbX = Double.parseDouble(x);
                                  double percetX = (totalFile/dbX) * 100;
                                  if(percetX >= 100){
                                       percetX = 100;
                                  series0.add(percetX, users);
                             if(y.equals("XXXX")){
                                  //do nothing
                             }else{
                                  //changes the value to a double
                                  double dbY = Double.parseDouble(y);
                                  double percetY = (totalFile/dbY) * 100;
                                  if(percetY >= 100){
                                  percetY = 100;
                                  series1.add(percetY, users);
                             if(z.equals("XXXX")){
                                  //do nothing
                             }else{
                                  //changes the value to a double
                                  double dbZ = Double.parseDouble(z);      
                                  double percetZ = (totalFile/dbZ) * 100;
                                  if(percetZ >= 100){
                                       percetZ = 100;
                                  series2.add(percetZ, users);
                             users++;
         XYSeriesCollection alldataset = new XYSeriesCollection();
         alldataset.addSeries(series0);
         alldataset.addSeries(series1);
         alldataset.addSeries(series2);
         return alldataset;
         * Creates a chart.
         * @param dataset the data for the chart.
         * @return a chart.
         private JFreeChart createChart(final XYDataset alldataset) {
         // create the chart...
         final JFreeChart chart = ChartFactory.createXYLineChart(
         "All Algorithms Together",     // chart title
         "Number of Lines", // x axis label
         "Users", // y axis label
         alldataset,      // data
         PlotOrientation.VERTICAL,
         true, // include legend
         true, // tooltips
         false // urls
         chart.setBackgroundPaint(Color.white);
         // get a reference to the plot for further customisation...
         final XYPlot plot = chart.getXYPlot();
         plot.setBackgroundPaint(Color.lightGray);
         plot.setDomainGridlinePaint(Color.white);
         plot.setRangeGridlinePaint(Color.white);
         final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
         renderer.setSeriesLinesVisible(0, false);
         renderer.setSeriesShapesVisible(1, false);
         plot.setRenderer(renderer);
         // change the auto tick unit selection to integer units only...
         final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
         return chart;

    I would try posting to the JFreeChart forum. They would probably have the best knowledge and maybe someone there may have done it before.
    http://www.jfree.org/phpBB2/index.php
    Darren

  • JFreechart and JSP, DefaultCategoryDataset is not identified

    Hi,
    Im using JFreechart in my application. Im just using a simple cahrt 2 check. If it works fine then i wil b apple to develop mi entire application. But i face the following problem. I placed al the jar files of JFreechart in root/webinf/lib/ but then DefaultCategoryDataset is not being identified. Can anyone please guide me whats the problem is?
    I hv enclosed the coding and the error with this mail.
    <%@page contentType="text/html;charset=big5"%>
    <%@page import="org.jfree.data.*"%>
    <%@page import="org.jfree.chart.*"%>
    <%@page import="java.io.*"%>
    <FORM METHOD="POST" name="chartform" action="Chart.jsp">
    <%
    DefaultCategoryDataset myDataSet=new DefaultCategoryDataset();
    myDataSet.setValue("apple",100);
    myDataSet.setValue("pear",200);
    myDataSet.setValue("grape",300);
    myDataSet.setValue("bannana",400);
    myDataSet.setValue("orange",500);
    JFreeChart chart=ChartFactory.createPieChart3D("fruit production chart",myDataSet,true,true,true);
    chart.setBackgroundPaint(java.awt.Color.white);
    chart.setBorderVisible(false);
    %>
    <img src="servlet/showChart" border=0>
    <Center><Input type="Submit" value="Generate..."/></Center>
    </FORM>
    </BODY>
    </HTML>
    -----------showChart code------------------
    import java.io.*;
    import javax.servlet.*;
    import org.jfree.data.*;
    import org.jfree.chart.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    public class showChart extends HttpServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    ChartRenderingInfo thisImageMapInfo=new ChartRenderingInfo();
    HttpSession thisSession = request.getSession();
    response.setContentType("image/jpeg");
    JFreeChart thisChart=(JFreeChart)thisSession.getAttribute("chart");
    ChartUtilities.writeChartAsJPEG(response.getOutputStream(),100,thisChart,400,300,thisImageMapInfo);
    I have placed both the files in same folder. and complied the class. Is it enuf or whats the procedure to connect JSP and its correspondibg servlet.
    ----------------error--------------------------
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 15 in the jsp file: /Teresa/Chart.jsp
    Generated servlet error:
    DefaultCategoryDataset cannot be resolved or is not a type
    An error occurred at line: 15 in the jsp file: /Teresa/Chart.jsp
    Generated servlet error:
    DefaultCategoryDataset cannot be resolved or is not a type
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    any help is appreciated...thanks in advance
    Regards,
    Carry.

    sorry, I path name i hv specified is having some typo
    error
    but the jar files are in right path as said by u
    anything else to help me...yes, you havent imported the package
    <%@page import="org.jfree.data.category.*"%>Importing org.jfree.data.* doesnt import the sub-packages :)
    cheers,
    ram.

  • JFreechart objekt in JSP HELP:((

    Hello,
    I have created a JFreeChart object which represents a line chart. Now I want to display this line chart in my jsp site? could anybody explain me how I can solve this problem?
    thanks in advance
    PS: I don't want to use CeWolf.:(

    Hello,
    I have created a JFreeChart object which represents a line chart. Now I want to display this line chart in my jsp site? could anybody explain me how I can solve this problem?
    thanks in advance
    PS: I don't want to use CeWolf.:(

  • Problem in displaying text inside the item label - JFREECHART

    Hi All,
    I dont know whether this is the right place or not to post the queries related to jfreechart here .
    I am facing a problem in displaying the text inside the item label in jfreeChart. I am trying to print the text in 2 lines one below the other at the top of each bar in waterfall chart.
    Please find the code below in next post. The problem i am facing is it is neglecting the new line character . If any one knows how to display the text one below the other please help me out .
    Thanks in advance .
    Regards,
    Diw

    i am facing the problem in pasting the complete code as its exceeds the message text limitiation, please find the link below for the code .
    http://www.java-forums.org/java-2d/12087-problem-displaying-text-inside-item-label-jfreechart.html#post36648
    Early response will be appreciated . Thanks in advance
    Regards,
    Diw
    Edited by: Diw on Sep 30, 2008 11:15 AM
    Edited by: Diw on Sep 30, 2008 11:16 AM

  • Date/Time on X-Axis with JFreeChart

    Hi guys,
    I've asked this question on the JFreeChart forums, but got no response.
    If anyone has any experience with JFreeChart, help would be most appreaciated.
    I am drawing a XY Line Chart to display CPU usage retrieved from a database. The user can search with specific dates/times (eg: from: 24/2/2005 to: 16/4/2005) - and then these results would be graphed.
    My question is, how do I use dates/times on the X-axis using JFreeChart?
    The results I am getting from the DB would be a time-stamp and CPU usage.
    Here is my current code, but it wont work with a time-stamp:
    public static class ChartTest   {
        public ChartTest()
            // create a dataset...FOR LOOP
            XYSeries dataSet = new XYSeries("CPU Usage");
            TimeSeries closing = new TimeSeries( "Closing Value", Day.class );
         for(int h=0; h < newArray[0].length; h++)
            for(int i=0; i < newArray.length; i++)
               dataSet.add(newArray[i][h], newArray[i][h++]);
            XYDataset xyDataset = new XYSeriesCollection(dataSet);
            // create a chart...
            JFreeChart lineGraph = ChartFactory.createXYLineChart
                        ("Mitch's CPU Usage Test",  // Title
                          "Time",           // X-Axis label
                          "CPU Load",           // Y-Axis label
                          xyDataset,          // Dataset
                          PlotOrientation.VERTICAL,        //Plot orientation
                          true,                //show legend
                          true,                // Show tooltips
                          false               //url show
            // create and display a frame...
            ChartFrame frame = new ChartFrame("CPU Usage Test", lineGraph);
            frame.pack();
            frame.setVisible(true);
        }

    The JFreeChard demo should give you the idea
    package demo;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.text.SimpleDateFormat;
    import javax.swing.JPanel;
    import org.jfree.chart.*;
    import org.jfree.chart.axis.DateAxis;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.time.*;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.*;
    public class TimeSeriesDemo1 extends ApplicationFrame
        public TimeSeriesDemo1(String s)
            super(s);
            XYDataset xydataset = createDataset();
            JFreeChart jfreechart = createChart(xydataset);
            ChartPanel chartpanel = new ChartPanel(jfreechart, false);
            chartpanel.setPreferredSize(new Dimension(500, 270));
            chartpanel.setMouseZoomable(true, false);
            setContentPane(chartpanel);
        private static JFreeChart createChart(XYDataset xydataset)
            JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, true, true, false);
            jfreechart.setBackgroundPaint(Color.white);
            XYPlot xyplot = (XYPlot)jfreechart.getPlot();
            xyplot.setBackgroundPaint(Color.lightGray);
            xyplot.setDomainGridlinePaint(Color.white);
            xyplot.setRangeGridlinePaint(Color.white);
            xyplot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
            xyplot.setDomainCrosshairVisible(true);
            xyplot.setRangeCrosshairVisible(true);
            org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
            if(xyitemrenderer instanceof XYLineAndShapeRenderer)
                XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
                xylineandshaperenderer.setDefaultShapesVisible(true);
                xylineandshaperenderer.setDefaultShapesFilled(true);
            DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
            dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
            return jfreechart;
        private static XYDataset createDataset()
            TimeSeries timeseries = new TimeSeries("L&G European Index Trust", org.jfree.data.time.Month.class);
            timeseries.add(new Month(2, 2001), 181.8);
            timeseries.add(new Month(3, 2001), 167.3);
            timeseries.add(new Month(4, 2001), 153.8);
            timeseries.add(new Month(5, 2001), 167.6);
            timeseries.add(new Month(6, 2001), 158.8);
            timeseries.add(new Month(7, 2001), 148.3);
            timeseries.add(new Month(8, 2001), 153.9);
            timeseries.add(new Month(9, 2001), 142.7);
            timeseries.add(new Month(10, 2001), 123.2);
            timeseries.add(new Month(11, 2001), 131.8);
            timeseries.add(new Month(12, 2001), 139.6);
            timeseries.add(new Month(1, 2002), 142.9);
            timeseries.add(new Month(2, 2002), 138.7);
            timeseries.add(new Month(3, 2002), 137.3);
            timeseries.add(new Month(4, 2002), 143.9);
            timeseries.add(new Month(5, 2002), 139.8);
            timeseries.add(new Month(6, 2002), 137.0);
            timeseries.add(new Month(7, 2002), 132.8);
            TimeSeries timeseries1 = new TimeSeries("L&G UK Index Trust", org.jfree.data.time.Month.class);
            timeseries1.add(new Month(2, 2001), 129.6);
            timeseries1.add(new Month(3, 2001), 123.2);
            timeseries1.add(new Month(4, 2001), 117.2);
            timeseries1.add(new Month(5, 2001), 124.1);
            timeseries1.add(new Month(6, 2001), 122.6);
            timeseries1.add(new Month(7, 2001), 119.2);
            timeseries1.add(new Month(8, 2001), 116.5);
            timeseries1.add(new Month(9, 2001), 112.7);
            timeseries1.add(new Month(10, 2001), 101.5);
            timeseries1.add(new Month(11, 2001), 106.1);
            timeseries1.add(new Month(12, 2001), 110.3);
            timeseries1.add(new Month(1, 2002), 111.7);
            timeseries1.add(new Month(2, 2002), 111.0);
            timeseries1.add(new Month(3, 2002), 109.6);
            timeseries1.add(new Month(4, 2002), 113.2D);
            timeseries1.add(new Month(5, 2002), 111.6);
            timeseries1.add(new Month(6, 2002), 108.8);
            timeseries1.add(new Month(7, 2002), 101.6);
            TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
            timeseriescollection.addSeries(timeseries);
            timeseriescollection.addSeries(timeseries1);
            timeseriescollection.setDomainIsPointsInTime(true);
            return timeseriescollection;
        public static JPanel createDemoPanel()
            JFreeChart jfreechart = createChart(createDataset());
            return new ChartPanel(jfreechart);
        public static void main(String args[])
            TimeSeriesDemo1 timeseriesdemo1 = new TimeSeriesDemo1("Time Series Demo 1");
            timeseriesdemo1.pack();
            RefineryUtilities.centerFrameOnScreen(timeseriesdemo1);
            timeseriesdemo1.setVisible(true);
    }

  • Where is the file? ( ussing jfreechart )

    Hi, I have a servlet that generates a chart and I need to save this lika a .jpg
    The servlet runs but I don�t know where the .jpg file is.
    I�m working into a remote server (Debian with tomcat)
    My code is:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.jfree.data.*;
    import org.jfree.chart.*;
    import org.jfree.chart.plot.*;
    import org.jfree.data.xy.*;
    //import org.jfree.chart.servlet.*;
    import java.awt.image.*;
    * @author  Roberto Canales
    * @version
    public class ejemploGraficasServlet extends HttpServlet
    public JFreeChart crearChart()
       XYSeries series = new XYSeries("Evolucion Sesiones");
       series.add(1, 23);
       series.add(2, 34);
       series.add(3, 51);
       series.add(4, 67);
       series.add(5, 89);
       series.add(6, 121);
       series.add(7, 137);
       XYDataset juegoDatos= new XYSeriesCollection(series);
       JFreeChart chart =
        ChartFactory.createXYLineChart("Sesiones en Adictos al Trabajo", 
         "Meses", "Sesiones", juegoDatos,        
         PlotOrientation.VERTICAL,
         true,true,true);
       return chart;
    int getParamEntero(HttpServletRequest request,String pNombre, int pDefecto)
       String param = request.getParameter(pNombre);
       if (param == null || param.compareTo("") == 0)
         return pDefecto;
       return Integer.parseInt(param);
    /** Processes requests for both HTTP GET and POST methods.
    * @param request servlet request
    * @param response servlet response
    protected void processRequest(HttpServletRequest request,
       HttpServletResponse response)throws ServletException, IOException {
      response.setContentType("image/jpeg");
      OutputStream salida = response.getOutputStream();
      JFreeChart grafica = crearChart();
      int ancho = getParamEntero(request,"ancho",400);
      int alto = getParamEntero(request,"alto",300);
      ChartUtilities.writeChartAsJPEG(salida,grafica,ancho,alto);
      ChartUtilities.saveChartAsJPEG(new File("./chart.jpg"), grafica, ancho, alto);
      salida.close();
    /** Handles the HTTP GET method.
    * @param request servlet request
    * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            processRequest(request, response);
    }somebody can help me? where is my file??
    Thanks

    the files I want to save, only the Admin generates its. And later the Admin must be able to send to other users.
    I have the servlet into ..../WEB-INF/classses/ but the file is not here, if I put this into the servlet:
    ChartUtilities.writeChartAsJPEG(salida,grafica,ancho,alto);
    String url = ChartUtilities.saveChartAsPNG(grafica, ancho, alto,null);The file is saved into /usr/local/tomcat/temp/ like jfreechart-onetime-xxxxx.png
    Thanks

  • Problem with jFreeChart

    Hi
    I am trying to bring up jFreeChart and have unsuccesfully trying to run the following
    "hello world" chart example:
    // ChartTest.java - 05/10/04
    // Test jFreeChart
    package mypackage;
    import org.jfree.data.*;
    import org.jfree.chart.*;
    public class ChartTest {
         public static void main(String[] args) {
              // create a dataset...
              DefaultPieDataset dataset = new DefaultPieDataset();
              dataset.setValue("Category 1", 43.2);
              dataset.setValue("Category 2", 27.9);
              dataset.setValue("Category 3", 79.5);
              // create a chart...
              JFreeChart chart = ChartFactory.createPieChart
                   ("Sample Pie Chart", // chart title
                   dataset,
                   true,
                   false,
                   false);
              // write image to the file system
              try {
              ChartUtilities.saveChartAsJPEG(new java.io.File("C:Distros.jpg"),
              chart, 500, 300);
              catch (java.io.IOException exc) {
                   System.err.println("Error writing image to file");
    mypackage contains
    Chart.Test.class
    ChartTest.java
    jcommon-0.9.3.jar
    jfreechart-0.9.18.jar
    I also have
    jcommon-0.9.3.jar
    jfreechart-0.9.18.jar
    in my
    C:\SunJava\jdk1.3.1_09\jre\lib\ext
    to eliminate the need to specify a class path
    The Problem.......
    Program compiles with no errors
    Execution generates
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at org.jfree.chart.plot.PiePlot.<clinit>(PiePlot.java:309)
    at org.jfree.chart.ChartFactory.createPieChart(ChartFactory.java:201)
    at mypackage.ChartTest.main(ChartTest.java:22)
    Web browsing talked about possibly needing to specify a class path in a manifest file
    I am unclear to why I require an apache class link for this example.
    Browsing the class structure for ChartFactory.createPieChart (where the error occurs)
    did not reveal any connection to apache.
    Do I need a later version of the JDK (need the current one to interface with a Dallas Tini server.
    Has anyone seen or resolved this issue.
    Thanks

    Hi Gabriele
    Thank you for the reply and problem resolution.
    I now have my "Hello World" pie chart and can now generate real plots.
    I knew about the requirement for the log4j file, did a search for it, but
    did not find the source (did not look hard enough).
    Per your reply, I now have a log4j.1.2.8.jar.
    I did have another gotcha before I could produce the chart.
    My initial run generated:
    log4j:WARN No appenders could be found for logger (org.jfree.chart.JFreeChart).
    log4j:WARN Please initialize the log4j system properly.
    I then did some web browing on the error and found that I needed to add the following to
    my code:
    org.apache.log4j.BasicConfigurator.configure();
    End result........ Pie chart.
    The only remaining problem is that the file was not generated in C:PieChart,jpg,
    but in C:\TRiLOGI\TL%/apps\jFreeChart\PieChart.jpg. This was one directory up
    from mypackage.
    I will have to look more into the class:
    ChartUtilities.saveChartAsJPEG(new java.io.File("C:PieChart.jpg"), ............)
    Thanks again

  • Where to put extracted jfreechart folder

    Hi,
    I had extracted jfreechart zip file but when I m compiling my java class , compiler gives errors like "package org.jfree.chart.ChrtFactory" does not exist and for other packages also.
    Please tell me how to map it to jar files?
    Please reply me as soon as possible.
    Thanks & Regards
    Ashish

    When you extract the files from the archive, a file readme.txt was created in the root of unpacked folder. Did you read that file entirely?
    If yes, please describe in more steps what you did. In this way, I'll be able to give you a more specific answer.
    Good luck!

  • Using jfreechart with oracle forms 11g

    Hi everybody,
    I'm using jfreechart with oracle forms 11g to continue having graphs in my application since i'm migrating from forms 6i. I've already got it working and it's great. Just have one problem left. I don't know how to change the axis labels. In Bar charts, it comes with "Values" in y axis and "Category" in x axis by default. I wanted to change that or make it dissapear. Anyone knows how to?

    I've never used the jFreeChart, but according to their website you can use the "setLabel" method to set the label for an axis. Check out Axis (JFreeChart Class Library) for more information.
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to add some parameters to jfreechart?

    hello to everyone
    i am developing one application in which there ia dataseries and i have to generate the chart.i have used jfreechart
    and the chart i have already created but my problem is i want to show some parameters in the chart like the maximum ,average values of the y- axis.can anybody tell me how to add these values to the chart and how to change their location so that the plot and the parameters don't overlap.
    plzzzzzzzzzzzz help

    Use FM BKK_ADD_WORKINGDAY
      IMPORTING
         VALUE(I_DATE) TYPE  SY-DATUM = <b>30.10.2007</b> (Specify date)
         VALUE(I_DAYS) TYPE  I = <b>50</b> (Days that u want to add)
         VALUE(I_CALENDAR1) TYPE  TFACD-IDENT OPTIONAL
         VALUE(I_CALENDAR2) TYPE  TFACD-IDENT OPTIONAL
      EXPORTING
         VALUE(E_DATE) TYPE  SY-DATUM  = <b>19.12.2007</b>
         VALUE(E_RETURN) TYPE  SY-SUBRC = 0
    Best Regards,
    Vibha
    *Please mark all the helpful answers
    Message was edited by: Vibha Deshmukh

  • Tutorial to use  JFreeChart in Java Application

    Dear Friends,
    Can anyone Please help me to provide a complete tutorial on using JFreeChart in Java Applicaion.That is, How can I use JFreeChart in Java Application.
    Thank u.

    http://www.jfree.org/jfreechart/devguide.html

Maybe you are looking for

  • Appletv won't launch

    I bought a new appletv yesterday and HDMI cable for use with a sony bravia tv set. As I set it up the light on the appletv flashes initially and then stays on. I switch on the tv set but appletv doesn't launch - my tv just works as normal. I've unplu

  • Unsupported Location (Ordering Photo Book in iPhoto iOS)

    Anyone know why I cannot order a photo book through the latest version of iPhoto (v2.0) for iOS on my iPad 3?.  Is the service not live yet? When I try to input my address it tells me I am in an Unsupported Location and deliveries cannot be made to t

  • I want to toggle Movie Symbols with List boxes

    For some reason I cant seem to use remove.clip to turn off a movie symbol. I dont think I am setting this up correctly, it is an easy task I am trying to acomplish. basically I have 3 movie symbols of hair and 3 radio buttons I want to attatch them t

  • Iphone and itunes on Microsoft 32bit system fail...HELP

    i just got my iphone 4s and when i tried to sync it to my itune, my iphone froze. I then tried to update my itunes before trying to hook it up again, and it would not let me. Then i deleted itunes from my 32bit comp and tried to download it, but fail

  • Where is Rescue and Recovery 4.50 for Windows 7 and why was it removed from the support site?

    When Rescue and Recovery 4.51 was released a few weeks ago, all references to the previous version were replaced. Unfortunately, the new release is not supported on the R series machines nor on the earlier T series machines, so for those machines, th