Fix the size of the JFreeChart by default when it is plot

A discussion forum for JSFreeChart (a 2D chart library written in JavaScript).
Locked
Divya Shrungar
Posts: 1
Joined: Wed Jan 03, 2018 7:28 am
antibot: No, of course not.

Fix the size of the JFreeChart by default when it is plot

Post by Divya Shrungar » Wed Jan 03, 2018 7:39 am

I have an internal pane inside a desktop pane, and I have a chart panel inside the JInertnalFrame. When I run the application, I am getting plot in not like I want, I am able to plot the graph but I have to resize that using mouse. I want to plot the graph and the plot should be according to the chartpanel.How to do that? I am reading the data to plot from a text file.

Code: Select all

public JInternalFrame OpenOption(JFileChooser path) throws FileNotFoundException
    {
        String p=path.toString();
        File f=path.getSelectedFile();

        JInternalFrame iFrame=new JInternalFrame(f.getAbsolutePath(),true,true,true,true);
        iFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         iFrame.setSize(900, 500);

         Scanner scan=new Scanner(path.getSelectedFile()).useDelimiter("\\s*(=>|,|;|\\s)\\s*");
         XYSeries series = new XYSeries(path.getSelectedFile());
            while (scan.useDelimiter("\\s*(=>|,|;|\\s)\\s*").hasNextDouble()) 
            { 
                series.add(scan.useDelimiter("\\s*(=>|,|;|\\s)\\s*").nextDouble(),scan.useDelimiter("\\s*(=>|,|;|\\s)\\s*").nextDouble()); 
            } 
            scan.close();

            XYDataset xyDataset = new XYSeriesCollection(series);

            JFreeChart chart = ChartFactory.createXYLineChart
                    ("","Wave number cm"+'\u2212'+'\u00B9',"Intensity",
                     xyDataset, PlotOrientation.VERTICAL, false, true, false);

             chart.getPlot().setBackgroundPaint( Color.WHITE);
             XYPlot plot = (XYPlot) chart.getPlot();
                plot.setDomainGridlinePaint(new Color(0xC0,0xC0,0xC0));
                plot.setRangeGridlinePaint(new Color(0xC0,0xC0,0xC0));
                plot.setRangeZeroBaselineVisible(true);
                plot.setDomainZeroBaselineVisible(true);
                plot.configureRangeAxes();


                System.out.println(plot.isRangeZeroBaselineVisible());
                //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                plot.getDomainAxis().setRange(plot.getDomainAxis().getRange().getLowerBound() - 0.10,
                           plot.getDomainAxis().getRange().getUpperBound() + 0.10);

             //JPanel chartPanel = new ChartPanel(chart);
             ChartPanel chartPan = new ChartPanel(chart);
             chartPan.setFillZoomRectangle(true);
             chartPan.setMouseWheelEnabled(true);
             //chartPanel.setPreferredSize(new Dimension(500, 270));
             chartPan.setBounds(100,100,640,480);
             chartPan.setMinimumDrawWidth( 0 );
             chartPan.setMinimumDrawHeight( 0 );
             chartPan.setMaximumDrawWidth( 1920 );
             chartPan.setMaximumDrawHeight( 1200 );
             chartPan.restoreAutoBounds();
             iFrame.add(chartPan);
             iFrame.pack();
             iFrame.setVisible(true);



             return iFrame;

    }

Locked