title: How to graph data using java?
body: <p>I have to Implement the readFile method to open the input file, read in the input variables (except for the title) in the order shown in the File Format section of this document, and close the file. program should read the number of data elements from the input file, then dynamically allocate all label and data arrays for all the charts. These sizes must also be used for the loops that read labels or data elements from the file.No other variables (except strings) should be initialized, and the arrays must be declared but not allocated It says there is an error for <strong>pieLabels[i] = input.next();</strong> and I am not sure what the problem is. Am I doing the FOR loop wrong? or is it not supposed to be a FOR loop?</p>
  
  <p>this is the file i have to read from </p>
  
  <p>5</p>
  
  <p>8</p>
  
  <p>6</p>
  
  <p>Nokia       12.2</p>
  
  <p>Apple       15.6</p>
  
  <p>Google      23.7</p>
  
  <p>Samsung     16.4</p>
  
  <p>Motorola    32.1</p>
  
  <p>74.0</p>
  
  <p>35.0</p>
  
  <p>63.0</p>
  
  <p>43.6</p>
  
  <p>47.7</p>
  
  <p>27.0</p>
  
  <p>13.3</p>
  
  <p>41.0</p>
  
  <p>55.0</p>
  
  <p>44.7</p>
  
  <p>34.0</p>
  
  <p>48.1</p>
  
  <p>62.0</p>
  
  <p>32.4</p>
  
  <p>34.5</p>
  
  <p>45.0</p>
  
  <p>35.0 5.0  17.0 25.0 32.7 12.4</p>
  
  <p>32.3 41.0 20.6 1.0  13.9 17.5</p>
  
  <p>26.5 11.2 3.9  14.9 33.0 41.4</p>
  
  <p>The first entry in the data file is the number of data items in the pie chart, followed by the same number of labels and doubles (so 5). Next is the number of data items in the bar chart, followed by two series of data that each have the same number of doubles (so 8). Next is the number of data items in the line graph, followed by three series of data that each have the same number of doubles (so 6).</p>
  
  <pre><code>static String pieTitle = "Pie Chart";
  static int pieCount;
  static String[] pieLabels;
  static double[] pieData;
  
  
  // Bar chart data
  static String barTitle = "Bar Chart";
  static int barCount;
  static double[] barData0;
  static double[] barData1;
  
  // Line graph data
  static String lineTitle = "Line Graph";
  static int lineCount;
  static double[] lineData0;
  static double[] lineData1;
  static double[] lineData2;
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      readFile(args[0]);
      displayCharts();
  }
  private static void readFile(String inputFile) 
  {
       try {
  
              // Open input stream
              Scanner input = new Scanner(new File(inputFile));
  
              // Read pie chart data
              pieCount = input.nextInt();
              for (int i = 0; i &lt; pieCount; i++)
                  pieLabels[i] = input.next();
              for (int i = 0; i &lt; pieCount; i++)
                  pieData[i] = input.nextDouble();
  
              // Read pie chart data
              barCount = input.nextInt();
              for (int i =  0; i &lt; barCount; i++)
                  barData0[i] = input.nextDouble();
              for (int i = 0; i &lt; barCount; i++)
                  barData1[i] = input.nextDouble();
  
              // Read line graph data
              lineCount = input.nextInt();
              for (int i = 0; i &lt; lineCount; i++)
                  lineData0[i] = input.nextDouble();
              for (int i = 0; i &lt; lineCount; i++)
                  lineData1[i] = input.nextDouble();
              for (int i = 0; i &lt; lineCount; i++)
                  lineData2[i] = input.nextDouble();
              input.close();
  
          } catch (IOException e) {
              System.out.println("Cannot read file: " + inputFile);
              System.exit(0);
          }
  }
  </code></pre>