0

This is my code.

public static Component create_Chart(double[] xValues2, double[] yValues2) throws IOException
   {
       JInternalFrame iFrame = new JInternalFrame(
             WordsInArray.fc.getSelectedFile().toString(),true,true,true,true);
         iFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         iFrame.setSize(600, 200);

         double[] xVal=new double[xValues.length];

         for(int i=0;i<=xValues.length-1;i+=2)
         {
             xVal[i]=xValues[i];
             System.out.println(xVal[i]);
         }
         double[] yVal=XYValues.get_yValues();
        for(int i=1;i<=yValues.length;i+=2)
        {
            //i++;
             System.out.println(yVal[i]);
        }

       try{
         XYSeries series=new XYSeries("Sample");
         //series.add(xVal,yVal);      
         for(int i=0;i<=xValues.length-1;i++)
         {
           series.add(xVal[i],yVal[i]);   
          }

        XYDataset xyDataset = new XYSeriesCollection(series);

        JFreeChart chart = ChartFactory.createXYLineChart
                ("","Wave number", "Intensity",
                 xyDataset, PlotOrientation.VERTICAL, false, true, false);

         chart.getPlot().setBackgroundPaint( Color.WHITE);
         JPanel chartPanel = new ChartPanel(chart);

         iFrame.add(chartPanel);
         iFrame.pack();
         iFrame.setVisible(true);
   }
       catch(Exception e)
       {
           e.printStackTrace();
       }
       return iFrame;
   }

I am not able to get the graph in the JInternalFrame. Did I missed anything in adding the values for the chart? Please let me know how to add array values to add().

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    If this is not a duplicate, please [edit] your question to include a [mcve] that shows your revised approach. – trashgod Aug 22 '17 at 09:40
  • 1
    I went ahead and ran your code using the arguments instead of class variables and it renders correctly. Watch out for the data you are using or do as the comment above. – DPM Aug 22 '17 at 09:45

0 Answers0