KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is it possible to change the bar color? I have coded a simple program for counting. 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. Currently, all bar color is in red. So, I would like to ask, is it possible to change the bar color? If yes, can someone give me some guide to realize? Thanks in advance! attached is my coding: <%@page contentType="text/html"%> <%@page import="java.io.*" %> <%@page import="java.sql.*" %> <%@page import="org.jfree.data.category.*" %> <%@page import="org.jfree.chart.*" %> <%@page import="org.jfree.chart.plot.*" %> <html> <body> <% 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 File
Tags (comma-separated)
Save Edits
Cancel