title: Jfreechart: Is it possible to change the bar color?
body: <p>Is it possible to change the bar color?</p>
  
  <p>I have coded a simple program for counting.</p>
  
  <p>I want to implement one more thing: if the count number is greater than 200, use blue color to draw the bar. If not, use yellow color to do so.</p>
  
  <p>Currently, all bar color is in red.</p>
  
  <p>So, I would like to ask, is it possible to change the bar color?</p>
  
  <p>If yes, can someone give me some guide to realize?</p>
  
  <p>Thanks in advance!</p>
  
  <p>attached is my coding:</p>
  
  <pre><code>&lt;%@page contentType="text/html"%&gt;
  &lt;%@page import="java.io.*" %&gt;
  &lt;%@page import="java.sql.*" %&gt;
  &lt;%@page import="org.jfree.data.category.*" %&gt;
  &lt;%@page import="org.jfree.chart.*" %&gt;
  &lt;%@page import="org.jfree.chart.plot.*" %&gt;
  
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;%
         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
         try
          {
  
              Class.forName("com.mysql.jdbc.Driver");
              java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/delivery","root","root");
              Statement sta = con.createStatement();
              ResultSet res = sta.executeQuery("SELECT inventory, subject from statistics");
              int count;
              String subject;
  
              while (res.next())
              {
                  count = res.getInt("inventory");
                  subject = res.getString("subject");
                  dataset.addValue(count,"enrollment count statistics", subject);  
              }
          }
          catch (Exception e) { 
              System.err.println(e.getMessage());
          }   
  
          JFreeChart bar = ChartFactory.createBarChart("Enrollment Chart", "subject","Count",dataset, PlotOrientation.HORIZONTAL,true, false, false);   
          //BarRenderer renderer = (BarRenderer) bar.getCategoryPlot().getRenderer();
  
          String fileName = "/bar.png";
          String file = application.getRealPath("/") + fileName;
  
          try
          {
              FileOutputStream fileOut = new FileOutputStream(file);
              ChartUtilities.writeChartAsPNG(fileOut, bar, 300, 300);
          }
          catch (IOException e)
          {
               out.print(e);
          }
  
  
  %&gt;
  &lt;img src="/delivery/bar.png" alt="subject Bar Chart" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>