List of usage examples for org.jfree.chart ChartFactory createBarChart
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:Interface.FoodCollectionSupervisor.TotalFoodDonation.java
private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed // TODO add your handling code here: Date toDate1 = jDateChooser1.getDate(); Date toDate2 = jDateChooser2.getDate(); if ((toDate1 == null) || (toDate2 == null)) { JOptionPane.showMessageDialog(null, "Invalid date..Kindly enter valid date."); return;//from ww w . j a v a 2s . co m } long fromDate = (jDateChooser1.getDate().getTime()) / (1000 * 60 * 60 * 24); long toDate = (jDateChooser2.getDate().getTime()) / (1000 * 60 * 60 * 24); int homeFoodType = 0; int cannedType = 0; int purchasedType = 0; for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) { long requestDate = (request.getRequestDate().getTime()) / (1000 * 60 * 60 * 24); if ((requestDate >= fromDate) && (requestDate <= toDate)) { if (!request.getStatus().equalsIgnoreCase("New Request")) { if (((FoodCollectionWorkRequest) request).getFood().getFoodType() .equalsIgnoreCase("Canned Food")) { cannedType++; } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType() .equalsIgnoreCase("Home made Food")) { homeFoodType++; } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType() .equalsIgnoreCase("Purchased Food")) { purchasedType++; } } } // else{ // // JOptionPane.showMessageDialog(null, "There are no records for this search criteria."); // } // } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(cannedType, "Number of food collected", "Canned Food"); dataset.setValue(purchasedType, "Number of food collected", "Purchased Food"); dataset.setValue(homeFoodType, "Number of food collected", "Home made Food"); JFreeChart chart = ChartFactory.createBarChart("Types of food collected", "Types of food", "Number of food collected", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Types of food collected", chart); frame.setVisible(true); frame.setSize(450, 350); }
From source file:net.vanosten.dings.swing.SummaryView.java
/** * Creates a sample chart./* www . ja v a 2s . c om*/ * * @param dataset the dataset. * * @return The chart. */ public void displayHorizontalBarChart(final CategoryDataset dataset, final String title, final String categoryTitle, final String valueTitle) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart(title // chart title , categoryTitle // domain axis label , valueTitle // range axis label , dataset // data , PlotOrientation.HORIZONTAL // orientation , true // include legend , true // tooltips? , false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); placeChart(chart); }
From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java
private static JFreeChart createBarChart(DefaultCategoryDataset dataset, String xLabel, String yLabel) { JFreeChart chart = ChartFactory.createBarChart("", // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // Plot orientation true, // include legend true, // tooltips false // urls );/*from w ww. j av a 2 s. c om*/ return chart; }
From source file:result.analysis.Chart.java
void BatchsubjectPerformance(String batch, String sem, String[] colleges, String code) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (String college : colleges) { db = mongoClient.getDB(college); analyz = new Analyze(db); for (int i = 11; i <= 13; i++) { String collection_name = "cs_" + i + "_" + sem + "_sem"; DBCollection collection = db.getCollection(collection_name); double passpercent[] = analyz.GetSubjectPassPercent(collection, code); // dataset.addValue(passpercent*100, "Pass %", Integer.toString(i)); dataset.addValue((passpercent[1] - passpercent[0]) / passpercent[1] * 100, college, Integer.toString(i)); }//from w w w . j a v a 2 s.c o m } JFreeChart barChart = ChartFactory.createBarChart("Fail % for " + code, "Batch", "Percentage", dataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame = new ChartFrame("Subject Performance of 20" + batch + " year " + sem + " Semester ", barChart); frame.setVisible(true); frame.setSize(500, 500); save_jpeg(barChart); }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * Build a JPanel with a histogram plot of a desmoJ histogram dataset * In the case histogram.getShowTimeSpansInReport() the data values are interpreted as * a timespan in a appropriate time unit. * @param histogram desmoJ histogram dataset * @return//from w ww . ja va 2s . c o m */ private JPanel getHistogramPlot(Histogram histogram) { JFreeChart chart; NumberFormat formatter = NumberFormat.getInstance(locale); HistogramDataSetAdapter dataSet = new HistogramDataSetAdapter(histogram, locale); String title = histogram.getName(); if (histogram.getDescription() != null) title = histogram.getDescription(); String xLabel = dataSet.getCategoryAxisLabel(); String yLabel = dataSet.getObservationAxisLabel(); chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataSet, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBaseItemLabelsVisible(true); StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", formatter); barrenderer.setBaseItemLabelGenerator(generator); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); //categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); categoryaxis.setMaximumCategoryLabelLines(4); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //numberaxis.setUpperMargin(0.1D); numberaxis.setNumberFormatOverride(formatter); return new ChartPanel(chart); }
From source file:edu.gmu.cs.sim.util.media.chart.BarChartGenerator.java
protected void buildChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("Untitled Chart", "Category", "Value", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setAntiAlias(true);/*ww w. j a va 2s . c o m*/ //chartPanel = new ScrollableChartPanel(chart, true); chartPanel = buildChartPanel(chart); //chartHolder.getViewport().setView(chartPanel); setChartPanel(chartPanel); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
From source file:userInterface.CustomerWorkArea.ViewChartJPanel.java
private void batteryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batteryBtnActionPerformed DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) { dataSet.setValue(carList.getBattery(), "Battery", carList.getTimestamp()); }/*from w w w .ja v a2s . c o m*/ JFreeChart chart = ChartFactory.createBarChart("Battery", "Timestamp", "Battery", dataSet, PlotOrientation.HORIZONTAL.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("BATTERY GRAPH", chart); frame.setVisible(true); frame.setSize(600, 600); // TODO add your handling code here: }
From source file:org.objectweb.proactive.benchmarks.timit.util.charts.BasicComparativeChartBuilder.java
/** * Creates a sample chart.//from w ww. j a v a2 s .c o m * * @param dataset a dataset. * * @return The chart. */ private JFreeChart createChart() { // create the chart... final JFreeChart chart = ChartFactory.createBarChart(this.chartTitle, // chart title "", // x axis label DEFAULT_Y_AXIS_NAME, // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.addSubtitle(new TextTitle(this.subtitle + "Time used is : " + TIME_ATTRIBUTE_NAME)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.black); plot.getRangeAxis().setLabelAngle((0 * Math.PI) / 2.0); ((BarRenderer) plot.getRenderer()).setItemMargin(0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:researchbehaviour.MoreAboutApplicant.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {//from w w w.j a v a2s .c o m FileReader reader = new FileReader("xml.txt"); BufferedReader br = new BufferedReader(reader); String line; line = br.readLine(); String[] strArray = line.split(" "); String[] FName = strArray[0].split(">"); String applicantName = FName[1] + " " + strArray[1]; jLabel7.setText(applicantName); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String Default = "Default"; String Applicant_Rate = "Applicant Rate"; String openness = "Openness"; String extraversion = "Extraversion"; String emotional_stability = "Emotional stability"; String conscientious = "Conscientious"; String agreeableness = "Agreeableness"; String Education = "Education"; // BehaviourA be = new BehaviourA(); PersonalityValues pv = new PersonalityValues(); double agr = 0; double con = 0; double ext = 0; double emo = 0; double ope = 0; double edu = 0; // agr = be.agreeablenessPersentage(); // con = be.conscientiousPersentage(); // ext = be.extraversionPersentage(); // emo = be.emotional_stabilityPersentage(); // ope = be.opennessPersentage(); // edu = be.educationPersentage(); // agr = pv.agrvalue(); con = pv.convalue(); ext = pv.extvalue(); emo = pv.emovalue(); ope = pv.opevalue(); edu = pv.eduvalue(); dataset.addValue(ope, Applicant_Rate, openness); dataset.addValue(ext, Applicant_Rate, extraversion); dataset.addValue(emo, Applicant_Rate, emotional_stability); dataset.addValue(con, Applicant_Rate, conscientious); dataset.addValue(agr, Applicant_Rate, agreeableness); dataset.addValue(edu, Applicant_Rate, Education); ChangeValues cvv = new ChangeValues(); ArrayList<Double> updateVal1 = new ArrayList<Double>(); updateVal1 = cvv.changedCutOff(); dataset.addValue(updateVal1.get(2), Default, openness); dataset.addValue(updateVal1.get(1), Default, extraversion); dataset.addValue(updateVal1.get(3), Default, emotional_stability); dataset.addValue(updateVal1.get(4), Default, conscientious); dataset.addValue(updateVal1.get(0), Default, agreeableness); dataset.addValue(70, Default, Education); JFreeChart barChart = ChartFactory.createBarChart("APPLICANT STATUES", "Personality factor", "Persentage", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = (CategoryPlot) barChart.getPlot(); plot.setDomainGridlinesVisible(true); ChartPanel chartPanel = new ChartPanel(barChart); chartPanel.setBounds(4, 9, 810, 422); jPanel3.add(chartPanel); jPanel3.repaint(); } catch (IOException ex) { Logger.getLogger(MoreAboutApplicant.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.rapidminer.gui.plotter.charts.HistogramColorChart.java
@Override protected void updatePlotter() { prepareData();/*from ww w . j av a 2 s.c o m*/ String maxClassesProperty = ParameterService .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT); int maxClasses = 20; try { if (maxClassesProperty != null) { maxClasses = Integer.parseInt(maxClassesProperty); } } catch (NumberFormatException e) { // LogService.getGlobal().log("Deviation plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.", // LogService.WARNING); LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.plotter.charts.HistogramColorChart.parsing_property_error"); } JFreeChart chart = null; if (nominal) { // ** nominal ** int categoryCount = this.categoryDataset.getRowCount(); boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend; String domainName = valueColumn >= 0 ? this.dataTable.getColumnName(valueColumn) : "Value"; chart = ChartFactory.createBarChart(null, // title domainName, "Frequency", categoryDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips false); // urls CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.WHITE); plot.setForegroundAlpha(this.opaqueness); BarRenderer renderer = new BarRenderer(); if (categoryDataset.getRowCount() == 1) { renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else { for (int i = 0; i < categoryDataset.getRowCount(); i++) { Color color = getColorProvider(true) .getPointColor((double) i / (double) (categoryDataset.getRowCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setBarPainter(new RapidBarPainter()); renderer.setDrawBarOutline(true); plot.setRenderer(renderer); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } } else { // ** numerical ** int categoryCount = this.histogramDataset.getSeriesCount(); boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend; String domainName = valueColumn >= 0 ? this.dataTable.getColumnName(valueColumn) : "Value"; chart = ChartFactory.createHistogram(null, // title domainName, "Frequency", histogramDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips false); // urls XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.WHITE); plot.setForegroundAlpha(this.opaqueness); XYBarRenderer renderer = new XYBarRenderer(); if (histogramDataset.getSeriesCount() == 1) { renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else { for (int i = 0; i < histogramDataset.getSeriesCount(); i++) { Color color = getColorProvider(true) .getPointColor((double) i / (double) (histogramDataset.getSeriesCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setBarPainter(new RapidXYBarPainter()); renderer.setDrawBarOutline(true); plot.setRenderer(renderer); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // Correctly displays dates on x-axis if (datetime) { DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(Tools.DATE_TIME_FORMAT.get()); plot.setDomainAxis(dateAxis); } // range axis Range range = getRangeForDimension(valueColumn); if (range != null) { plot.getDomainAxis().setRange(range); } // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } if (histogramDataset.getSeriesCount() == 1) { String key = histogramDataset.getSeriesKey(0).toString(); int index = this.dataTable.getColumnIndex(key); if (index >= 0) { if (this.dataTable.isNominal(index)) { String[] values = new String[dataTable.getNumberOfValues(index)]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(index, i); } plot.setDomainAxis(new SymbolAxis(key, values)); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } } } } } // set the background color for the chart... chart.setBackgroundPaint(Color.white); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // Disable zooming for Histogram-Charts panel.setRangeZoomable(false); panel.setDomainZoomable(false); // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }