protected JFreeChart createChart(XYDataset dataset) { SymbolAxis domainAxis = new SymbolAxis("Domain", new String[] {"A", "B", "C", "D"}); SymbolAxis rangeAxis = new SymbolAxis("Range", new String[] {"V", "X", "Y", "Z"}); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); if (!legendPanelOn) renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); setXSummary(dataset); if (legendPanelOn) chart.removeLegend(); return chart; }
/** * Applies the attributes for this theme to a {@link ValueAxis}. * * @param axis the axis (<code>null</code> not permitted). */ protected void applyToValueAxis(ValueAxis axis) { axis.setLabelFont(this.largeFont); axis.setLabelPaint(this.axisLabelPaint); axis.setTickLabelFont(this.regularFont); axis.setTickLabelPaint(this.tickLabelPaint); if (axis instanceof SymbolAxis) { applyToSymbolAxis((SymbolAxis) axis); } if (axis instanceof PeriodAxis) { applyToPeriodAxis((PeriodAxis) axis); } }
/** * Applies the attributes for this theme to a {@link ValueAxis}. * * @param axis the axis ({@code null} not permitted). */ protected void applyToValueAxis(ValueAxis axis) { axis.setLabelFont(this.largeFont); axis.setLabelPaint(this.axisLabelPaint); axis.setTickLabelFont(this.regularFont); axis.setTickLabelPaint(this.tickLabelPaint); if (axis instanceof SymbolAxis) { applyToSymbolAxis((SymbolAxis) axis); } if (axis instanceof PeriodAxis) { applyToPeriodAxis((PeriodAxis) axis); } }
private JFreeChart createXYSymbolicAxisChart(String title, XYDataset dataset) { SymbolAxis domainAxis = new SymbolAxis("Domain", new String[] {"A", "B", "C", "D"}); SymbolAxis rangeAxis = new SymbolAxis("Range", new String[] {"V", "X", "Y", "Z"}); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart("SymbolicAxis Demo 1", plot); if (lineCondition.indexOf("noshape")!=-1) renderer.setBaseShapesVisible(false); else renderer.setBaseShapesVisible(true); if (lineCondition.indexOf("noline")!=-1) renderer.setBaseLinesVisible(false); if (lineCondition.indexOf("nofill")!=-1){ renderer.setBaseShapesFilled(false); renderer.setBaseFillPaint(Color.white); renderer.setDrawOutlines(true);} else { renderer.setBaseShapesFilled(true); renderer.setUseFillPaint(false); } renderer.setUseFillPaint(true); //renderer.setFillPaint(Color.white); return chart; }
@Override protected void updatePlotter() { int categoryCount = prepareData(); 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("Series 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.SeriesChartPlotter.parsing_property_error"); } boolean createLegend = categoryCount > 0 && categoryCount < maxClasses; JFreeChart chart = createChart(this.dataset, createLegend); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // domain axis if (axis[INDEX] >= 0) { if (!dataTable.isNominal(axis[INDEX])) { if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); if (getRangeForDimension(axis[INDEX]) != null) { domainAxis.setRange(getRangeForDimension(axis[INDEX])); } domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); domainAxis.setVerticalTickLabels(isLabelRotating()); } } else { LinkedHashSet<String> values = new LinkedHashSet<String>(); for (DataTableRow row : dataTable) { String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX])); if (stringValue.length() > 40) { stringValue = stringValue.substring(0, 40); } values.add(stringValue); } ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]), values.toArray(new String[values.size()])); categoryAxis.setLabelFont(LABEL_FONT_BOLD); categoryAxis.setTickLabelFont(LABEL_FONT); categoryAxis.setVerticalTickLabels(isLabelRotating()); chart.getXYPlot().setDomainAxis(categoryAxis); } } // 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); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
JFreeChart ChartMeds(Integer demographicNo,String patientName, String chartTitle,String[] drugs) { MiscUtils.getLogger().debug("In ChartMeds"); org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", "MEDS", dataset, true, true, true); XYPlot plot = chart.getXYPlot(); // plot.getDomainAxis().setAutoRange(true); // Range rang = plot.getDataRange(plot.getRangeAxis()); // // log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin() + " eee " + plot.getDomainAxis().getLowerMargin()); // plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin()*6); // plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin()*6); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin()*1.7); // // plot.getDomainAxis().setUpperMargin(0.9); // plot.getDomainAxis().setLowerMargin(0.9); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4); XYTaskDataset drugDataset = getDrugDataSet( demographicNo,drugs); SymbolAxis yAxis = new SymbolAxis("Meds", getDrugSymbol(demographicNo,drugs)); yAxis.setGridBandsVisible(false); XYBarRenderer xyrenderer = new XYBarRenderer(); xyrenderer.setUseYInterval(true); xyrenderer.setBarPainter(new StandardXYBarPainter()); //XYPlot xyplot = new XYPlot(drugDataset, xAxis, yAxis, xyrenderer); XYPlot xyplot = new XYPlot(drugDataset, plot.getDomainAxis(), yAxis, xyrenderer); xyplot.getDomainAxis().setUpperMargin(0.9); xyplot.getDomainAxis().setLowerMargin(0.9); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new DateAxis("Date/Time")); cplot.add(xyplot); chart = new JFreeChart(chartTitle,cplot); chart.setBackgroundPaint(Color.white); return chart; }
/** Creates domain axis */ private SymbolAxis createAxis(String label, String[] seriesLabels) { SymbolAxis leftLocalSymbolAxis = new SymbolAxis(label, seriesLabels); leftLocalSymbolAxis.setGridBandsVisible(false); return leftLocalSymbolAxis; }
@Override protected void updatePlotter() { int categoryCount = prepareData(); 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("Series 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.SeriesChartPlotter.parsing_property_error"); } boolean createLegend = categoryCount > 0 && categoryCount < maxClasses; JFreeChart chart = createChart(this.dataset, createLegend); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // domain axis if (axis[INDEX] >= 0) { if (!dataTable.isNominal(axis[INDEX])) { if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); if (getRangeForDimension(axis[INDEX]) != null) domainAxis.setRange(getRangeForDimension(axis[INDEX])); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); domainAxis.setVerticalTickLabels(isLabelRotating()); } } else { LinkedHashSet<String> values = new LinkedHashSet<String>(); for (DataTableRow row : dataTable) { String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX])); if (stringValue.length() > 40) stringValue = stringValue.substring(0, 40); values.add(stringValue); } ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]), values.toArray(new String[values.size()])); categoryAxis.setLabelFont(LABEL_FONT_BOLD); categoryAxis.setTickLabelFont(LABEL_FONT); categoryAxis.setVerticalTickLabels(isLabelRotating()); chart.getXYPlot().setDomainAxis(categoryAxis); } } // 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); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
JFreeChart ChartMeds(String demographicNo,String patientName, String chartTitle,String[] drugs) { MiscUtils.getLogger().debug("In ChartMeds"); org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", "MEDS", dataset, true, true, true); XYPlot plot = chart.getXYPlot(); // plot.getDomainAxis().setAutoRange(true); // Range rang = plot.getDataRange(plot.getRangeAxis()); // // log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin() + " eee " + plot.getDomainAxis().getLowerMargin()); // plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin()*6); // plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin()*6); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin()*1.7); // // plot.getDomainAxis().setUpperMargin(0.9); // plot.getDomainAxis().setLowerMargin(0.9); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4); XYTaskDataset drugDataset = getDrugDataSet( demographicNo,drugs); SymbolAxis yAxis = new SymbolAxis("Meds", getDrugSymbol(demographicNo,drugs)); yAxis.setGridBandsVisible(false); XYBarRenderer xyrenderer = new XYBarRenderer(); xyrenderer.setUseYInterval(true); xyrenderer.setBarPainter(new StandardXYBarPainter()); //XYPlot xyplot = new XYPlot(drugDataset, xAxis, yAxis, xyrenderer); XYPlot xyplot = new XYPlot(drugDataset, plot.getDomainAxis(), yAxis, xyrenderer); xyplot.getDomainAxis().setUpperMargin(0.9); xyplot.getDomainAxis().setLowerMargin(0.9); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new DateAxis("Date/Time")); cplot.add(xyplot); chart = new JFreeChart(chartTitle,cplot); chart.setBackgroundPaint(Color.white); return chart; }
public BufferedImage generateChart(Map<String, List<Double>> data, Map<Integer, String> runToCommit, String yCaption, int width, int height) { // create dataset YIntervalSeriesCollection dataset = new YIntervalSeriesCollection(); YIntervalSeries s1 = new YIntervalSeries(yCaption); int i = 0; for (Integer run : runToCommit.keySet()) { String commit = runToCommit.get(run); DescriptiveStatistics stats = getStats(data.get(commit)); double mean = stats.getMean(); double std = stats.getStandardDeviation(); s1.add(i++, mean, mean - 1.96 * std, mean + 1.96 * std); } dataset.addSeries(s1); // create chart //NumberAxis xAxis = new NumberAxis("Revision number"); Set<String> strings = data.keySet(); final String[] stringsArray = new String[strings.size()]; int k = 0; for (String str : strings) { stringsArray[k++] = StringUtils.abbreviate(str, 10); } ValueAxis xAxis = new SymbolAxis("Commits", stringsArray); NumberAxis yAxis = new NumberAxis("Cluster processing time (ms)"); yAxis.setAutoRangeStickyZero(false); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseLinesVisible(true); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setBaseShapesVisible(false); renderer.setErrorPaint(Color.blue); renderer.setErrorStroke(new BasicStroke(1.0f)); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); JFreeChart chart = new JFreeChart("Average time to process queued work", plot); chart.setBackgroundPaint(Color.white); // create output image BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); graphics.setBackground(Color.white); graphics.clearRect(0, 0, width, height); // render chart.draw(graphics, new Rectangle2D.Double(0, 0, width, height)); return image; }
/** * Applies the attributes for this theme to a {@link SymbolAxis}. * * @param axis the axis (<code>null</code> not permitted). */ protected void applyToSymbolAxis(SymbolAxis axis) { axis.setGridBandPaint(this.gridBandPaint); axis.setGridBandAlternatePaint(this.gridBandAlternatePaint); }
/** * Applies the attributes for this theme to a {@link SymbolAxis}. * * @param axis the axis ({@code null} not permitted). */ protected void applyToSymbolAxis(SymbolAxis axis) { axis.setGridBandPaint(this.gridBandPaint); axis.setGridBandAlternatePaint(this.gridBandAlternatePaint); }