title: How to create a bar chart in JFreeChart?
body: <p>I've managed to create a simple XYLineChart but now I need to do this with bars, not with lines. Meaning that if Y value is below zero the bar would be inverted.</p>
  
  <pre><code>public static void plotmain(double [] ya, int [] xa) {
      dataset = new XYSeriesCollection();
      XYSeries data = new XYSeries("");
  
      for (int i = 0 ; i &lt; ya.length ; i++) {
          data.add(xa[i], ya[i]);
      }
      dataset.addSeries(data);
      showGraph();
  }
  
  private static void showGraph() {
      final JFreeChart chart = createChart(dataset);
      final ChartPanel chartPanel = new ChartPanel(chart);
      chartPanel.setPreferredSize(new java.awt.Dimension(resx, resy));
      final ApplicationFrame frame = new ApplicationFrame("");
      frame.setContentPane(chartPanel);
      frame.pack();
      frame.setVisible(true);
  }
  
  private static JFreeChart createChart(final XYDataset dataset) {
      final JFreeChart chart = ChartFactory.createXYLineChart(
          "", // chart title
          "", // x axis label
          "", // y axis label
          dataset, // data
          PlotOrientation.VERTICAL,
          true, // include legend
          true, // tooltips
          false // urls
      );
      XYPlot plot = (XYPlot) chart.getPlot();
      XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
      renderer.setSeriesLinesVisible(0, true);
      renderer.setSeriesShapesVisible(0, false);
      renderer.setSeriesPaint(0, Color.blue);
      plot.setRenderer(renderer);
      return chart;
  }
  </code></pre>