List of usage examples for org.jfree.chart.plot CategoryPlot addRangeMarker
public void addRangeMarker(Marker marker)
From source file:lu.lippmann.cdb.weka.SilhouetteUtil.java
/** * // www . java 2s . com * @param sils * @return */ public static JPanel buildSilhouettePanel(final Instances ds, final WekaClusteringResult result) { final Map<Integer, List<Double>> sils = computeSilhouette(ds, result); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final JFreeChart chart = ChartFactory.createBarChart("Silhouette", "Category", "Value", dataset, PlotOrientation.HORIZONTAL, true, true, false); int nbClass = sils.keySet().size(); int id = 0; double minValue = 0; int counter[][] = new int[nbClass][4]; for (int i = 0; i < nbClass; i++) { final double[] tree = ArrayUtils.toPrimitive(sils.get(i).toArray(new Double[0])); for (double val : tree) { if (val > 0.75) { dataset.addValue(val, "Cluster " + i + " ++", "" + id); counter[i][0]++; } else if (val > 0.50) { dataset.addValue(val, "Cluster " + i + " +", "" + id); counter[i][1]++; } else if (val > 0.25) { dataset.addValue(val, "Cluster " + i + " =", "" + id); counter[i][2]++; } else { dataset.addValue(val, "Cluster " + i + " -", "" + id); counter[i][3]++; } if (val < minValue) { minValue = val; } id++; } } final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.WHITE); categoryplot.getDomainAxis().setVisible(false); categoryplot.setDomainGridlinesVisible(false); categoryplot.setRangeGridlinesVisible(false); categoryplot.getRangeAxis().setRange(minValue, 1.0); //Add line markers ValueMarker target = new ValueMarker(0.75); target.setPaint(Color.BLACK); target.setLabel(" ++"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0.5); target.setPaint(Color.BLACK); target.setLabel(" +"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0.25); target.setPaint(Color.BLACK); target.setLabel(" ="); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0); target.setPaint(Color.BLACK); target.setLabel(" -"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); //Remove visual effects on bar final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); //set bar colors int p = 0; final int max = ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.size(); for (int i = 0; i < nbClass; i++) { final Color[] color = new ArrayList<Color[]>(ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.values()) .get((max - i) % max); final int nbColors = color.length; for (int k = 0; k < counter[i].length; k++) { if (counter[i][k] > 0) barrenderer.setSeriesPaint(p++, color[(nbColors - k - 3) % nbColors]); } } //remove blank line between bars barrenderer.setItemMargin(-dataset.getRowCount()); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("Silhouette plot")); chartPanel.setBackground(Color.WHITE); chart.setTitle(""); return chartPanel; }
From source file:spec.reporter.Utils.java
public static void createBmResultGraph(BenchmarkRecord record) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String iterName = ""; double max = 0; double min = Long.MAX_VALUE; for (int i = 0; i < record.iterRecords.size(); i++) { BenchmarkRecord.IterationRecord iterRecord = (BenchmarkRecord.IterationRecord) record.iterRecords .get(i);/*from ww w . j a v a 2 s. c o m*/ String shortName = iterRecord.iterName.replaceFirst("ation", ""); if (iterRecord.score > max) { max = iterRecord.score; iterName = shortName; } if (iterRecord.score < min) { min = iterRecord.score; } dataset.addValue(iterRecord.score, " ", shortName); } JFreeChart chart = ChartFactory.createLineChart(" ", "iterations", Constants.WORKLOAD_METRIC, dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(201, 222, 254)); plot.setRangeGridlinePaint(Color.WHITE); if (record.isValidRun() && min != Long.MAX_VALUE) { plot.getRangeAxis().setRange(min - 10, max + 10); } else { plot.getRangeAxis().setRange(0, max + 10); } ValueMarker vm = new ValueMarker(record.maxScore); vm.setLabel(Utils.df.format(record.maxScore)); vm.setLabelAnchor(RectangleAnchor.TOP_LEFT); vm.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT); plot.addRangeMarker(vm); CategoryMarker marker = new CategoryMarker(iterName); marker.setDrawAsLine(true); marker.setPaint(vm.getPaint()); plot.addDomainMarker(marker); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setFillPaint(Color.WHITE); renderer.setSeriesPaint(0, Color.BLUE.darker()); try { ChartUtilities.saveChartAsJPEG(new File(Utils.getFullImageName(record.name + "_results")), chart, 300, 200); } catch (Exception e) { System.out.println("Problems..."); } }
From source file:utils.ChartUtils.java
/** * Update values of a bar chart/* www . ja va2 s. co m*/ * * @param labelsByFreq Labels ordered by frequency * @param nInstances Number of instances * @param cp CategoryPlot */ public static void updateValuesBarChart(ImbalancedFeature[] labelsByFreq, int nInstances, CategoryPlot cp) { DefaultCategoryDataset data = new DefaultCategoryDataset(); double prob; labelsByFreq = MetricUtils.sortByFrequency(labelsByFreq); double sum = 0.0; for (int i = 0; i < labelsByFreq.length; i++) { prob = labelsByFreq[i].getAppearances() * 1.0 / nInstances; sum += prob; data.setValue(prob, labelsByFreq[i].getName(), " "); } cp.setDataset(data); // add mean mark sum = sum / labelsByFreq.length; Marker start = new ValueMarker(sum); start.setPaint(Color.red); start.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); start.setLabel(" Mean: " + MetricUtils.truncateValue(sum, 3)); cp.addRangeMarker(start); }
From source file:utils.ChartUtils.java
/** * Update IR bar chart/*w w w. ja v a2 s . c om*/ * * @param labelsByFrequency Labels ordered by frequency * @param IR Imbalance Ratio values * @param cp CategoryPlot */ public static void updateIRBarChart(ImbalancedFeature[] labelsByFrequency, double[] IR, CategoryPlot cp) { DefaultCategoryDataset myData = new DefaultCategoryDataset(); double prob = 0; labelsByFrequency = MetricUtils.sortByFrequency(labelsByFrequency); double sum = 0.0; for (int i = labelsByFrequency.length - 1; i >= 0; i--) { prob = IR[i]; sum += prob; myData.setValue(prob, labelsByFrequency[i].getName(), " "); } cp.setDataset(myData); // add mean mark sum = sum / labelsByFrequency.length; Marker meanMark = new ValueMarker(sum); meanMark.setPaint(Color.red); meanMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); meanMark.setLabel(" Mean: " + MetricUtils.truncateValue(sum, 3)); cp.addRangeMarker(meanMark); //Add Imbalance limit mark Marker limitMark = new ValueMarker(1.5); limitMark.setPaint(Color.black); limitMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); if ((sum < 1.3) || (sum > 1.7)) { limitMark.setLabel(" Imbalance limit (IR=1.5)"); } cp.addRangeMarker(limitMark); }
From source file:com.googlecode.logVisualizer.chart.turnrundownGantt.GanttChartBuilder.java
private void addDayMarkers(final CategoryPlot plot) { for (final DayChange dc : getLogData().getDayChanges()) { final ValueMarker day = new ValueMarker(dc.getTurnNumber()); day.setLabel("Day " + dc.getDayNumber()); day.setLabelAnchor(RectangleAnchor.TOP_RIGHT); day.setLabelTextAnchor(TextAnchor.TOP_LEFT); day.setStroke(new BasicStroke(2)); day.setPaint(Color.BLUE); plot.addRangeMarker(day); }//from w ww .jav a 2 s . c o m }
From source file:com.googlecode.logVisualizer.chart.turnrundownGantt.GanttChartBuilder.java
private void addLevelMarkers(final CategoryPlot plot) { for (final LevelData ld : getLogData().getLevels()) { final ValueMarker level = new ValueMarker(ld.getLevelReachedOnTurn()); level.setLabel("Level " + ld.getLevelNumber()); level.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); level.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); level.setStroke(new BasicStroke(2)); level.setPaint(new Color(0, 150, 0)); plot.addRangeMarker(level); }// www .j a v a2s. c om }
From source file:UserInterface.PDCPrimaryDoctorRole.PDCPrimaryDoctorReportsJPanel.java
private void populateGraphs(Patient patient, String attribute) { int lowerNormal = 0; int higherNormal = 0; int yAxis = 0; DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); for (VitalSigns vitalSigns : patient.getVitalSignsHistory().getVitalSignsHistory()) { if (attribute.equalsIgnoreCase("ECG")) { yAxis = vitalSigns.getEcg(); lowerNormal = 46;//from w w w .j ava 2s .c om higherNormal = 50; } else if (attribute.equalsIgnoreCase("HEART RATE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 60; higherNormal = 90; } else if (attribute.equalsIgnoreCase("RESPIRATORY RATE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 12; higherNormal = 25; } else if (attribute.equalsIgnoreCase("WEIGHT IN KG")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 80; higherNormal = 85; } else if (attribute.equalsIgnoreCase("SYSTOLIC BLOOD PRESSURE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 90; higherNormal = 120; } Date currentTimeStamp = new Date(); int currentTime = (int) (currentTimeStamp.getTime()) / (1000 * 60); int vitalSignsTime = (int) vitalSigns.getTimeStamp().getTime() / (1000 * 60); if (currentTime - vitalSignsTime <= 1) { line_chart_dataset.addValue(yAxis, attribute, vitalSigns.getTimeStamp()); } } JFreeChart lineChart = ChartFactory.createLineChart(attribute + " Over Time", "Time", attribute, line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot pi = lineChart.getCategoryPlot(); pi.setRangeGridlinePaint(Color.WHITE); pi.getRenderer().setSeriesPaint(0, Color.GREEN); pi.setBackgroundPaint(Color.BLACK); ValueMarker marker = new ValueMarker(lowerNormal); marker.setLabel("Normal Range"); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelPaint(Color.WHITE); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker.setPaint(Color.CYAN); pi.addRangeMarker(marker); ValueMarker marker2 = new ValueMarker(higherNormal); marker2.setLabel("Normal Range"); marker2.setLabelPaint(Color.WHITE); marker2.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker2.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker2.setPaint(Color.CYAN); pi.addRangeMarker(marker2); reportJPanel.setLayout(new java.awt.BorderLayout()); ChartPanel panel = new ChartPanel(lineChart); reportJPanel.add(panel, BorderLayout.CENTER); reportJPanel.validate(); }
From source file:Gui.admin.NouveauStatistique.java
private void StatistiquesBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StatistiquesBouttonActionPerformed int size = tablemesEvaluation.getRowCount(); List<Double> notes = new ArrayList<Double>(); List<Integer> ids = new ArrayList<Integer>(); List<String> noms = new ArrayList<String>(); EvaluationDAO evaluationDAO = new EvaluationDAO(); System.out.println("ouh ouh " + size); //System.out.println(evaluationDAO.getMoyenneByAdherent(8)); int idadh;/*from w w w .j av a 2s . c o m*/ float ess; for (int i = 0; i < size; i++) { System.out.println(tablemesEvaluation.getValueAt(i, 4).toString()); idadh = Integer.parseInt(tablemesEvaluation.getValueAt(i, 1).toString()); String nom = (tablemesEvaluation.getValueAt(i, 2).toString()); // notes.add((new Double (tablemesEvaluation.getValueAt(i,2).toString()))); System.out.println(" id adherent " + idadh); // System.out.println("moyenne "+); ess = evaluationDAO.getMoyenneByAdherent(idadh); System.out.println(ess); // notes.add((new Double (evaluationDAO.getMoyenneByAdherent((int) tablemesEvaluation.getValueAt(i,1))))); notes.add((new Double(ess))); ids.add((int) tablemesEvaluation.getValueAt(i, 1)); noms.add(nom); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < size; i++) { dataset.setValue(new Double(notes.get(i)), "notes", new String(noms.get(i))); } //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Noms des adhrents", "Notes", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(700, 800); ValueMarker marker = new ValueMarker(15); marker.setLabel(" seuil de l'valuation "); marker.setLabelAnchor(RectangleAnchor.CENTER); marker.setPaint(Color.YELLOW); p.addRangeMarker(marker); p.setRangeGridlinePaint(Color.RED); try { } catch (Exception e) { } /* String note =noteTxt.getText(); String idAdherent=idAdherentEvaluText.getText(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(new Double(note), "notes", new Double(idAdherent)); //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p= chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(450,350); */ try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("statistiques.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } }
From source file:net.praqma.jenkins.memorymap.MemoryMapBuildAction.java
protected JFreeChart createPairedBarCharts(String title, String yaxis, double max, double min, CategoryDataset dataset, List<ValueMarker> markers) { final CategoryAxis domainAxis = new ShiftedCategoryAxis(null); final NumberAxis rangeAxis = new NumberAxis(yaxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(max);//from w w w .j a v a 2 s . co m rangeAxis.setLowerBound(min); /*TODO : wrong scale choosen - Jes * if the user selects Mega or Giga as the scale, but there only are * a couple of Kilo in the graph it would have no ticks on the axis. * this can be solved by. redefining the ticks, * We have not done this because it's a bit tricky to figure out the rigth * factor to devid with * * but the method wuld be * double factor = 10 * rangeAxis.setStandardTickUnits(new StandardTickUnitSource(max / factor)); */ //StackedAreaRenderer2 renderer = new StackedAreaRenderer2(); BarRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); for (ValueMarker mkr : markers) { plot.addRangeMarker(mkr); } JFreeChart chart = new JFreeChart(plot); chart.setPadding(new RectangleInsets(30, 15, 15, 15)); chart.setTitle(title); return chart; }
From source file:org.fhaes.jsea.JSEABarChart.java
/** * Creates a demo chart.//w ww. ja va 2 s.c o m * * @return A chart. */ @SuppressWarnings("deprecation") public static JFreeChart createChart(String title, double[] meanByWindow, int lengthOfWindow, int yearsPriorOfEvent, int yearsAfterEvent, double[][] leftEndPointSim, double[][] rightEndPointSim, String outputFilePrefix, int alphaLevel, int segmentIndex) { JSEABarChart.meanByWindow = meanByWindow; JSEABarChart.lengthOfWindow = lengthOfWindow; JSEABarChart.yearsPriorOfEvent = yearsPriorOfEvent; JSEABarChart.leftEndPointSim = leftEndPointSim; JSEABarChart.rightEndPointSim = rightEndPointSim; JSEABarChart.alphaLevel = alphaLevel; CategoryPlot plot = new CategoryPlot(); plot.setDataset(0, createDataset()); plot.setOrientation(PlotOrientation.VERTICAL); CustomBarRenderer renderer = new CustomBarRenderer(createPaint(lengthOfWindow, Color.gray)); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); renderer.setOutlinePaint(Color.yellow); renderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(0, renderer); Color allcolors[] = { Color.red, Color.green, Color.blue }; System.out.println("here is the alphlevel " + alphaLevel); // for (int k = 0; k <= 5; k++) { // if (k <= 2) { // / plot.setDataset(k + 1, createEndDataset(k, true)); // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k], k)); // } else { // plot.setDataset(k + 1, createEndDataset(k - 3, false)); // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k - 3], k - 3)); // } // } // for (int k = 0; k <1; k++) { // if (k <= 2) { plot.setDataset(1, createEndDataset(alphaLevel, true)); plot.setRenderer(1, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel)); // } else { plot.setDataset(4, createEndDataset(alphaLevel, false)); plot.setRenderer(4, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel)); // } // } plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // plot.setBackgroundPaint(Color.WHITE); plot.setDomainAxis(new CategoryAxis("LAG")); plot.addRangeMarker(new ValueMarker(0)); plot.setRangeAxis(new NumberAxis(outputFilePrefix)); plot.setRangeGridlinesVisible(true); JFreeChart chart = new JFreeChart(plot); chart.setTitle(title); chart.removeLegend(); chart.setBackgroundPaint(Color.WHITE); return chart; }