public void paintDeviationChart(Graphics graphics, int width, int height) { prepareData(); JFreeChart chart = createChart(this.dataset); // 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); } Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height); chart.draw((Graphics2D) graphics, drawRect); }
/** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart( "Performance: JFreeSVG vs Batik", null /* x-axis label*/, "Milliseconds" /* y-axis label */, dataset); chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG " + "format (lower bars = better performance)")); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); chart.getLegend().setFrame(BlockBorder.NONE); return chart; }
/** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart( "Performance: JFreeSVG vs Batik", null /* x-axis label*/, "Milliseconds" /* y-axis label */, dataset); chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG " + "format (lower bars = better performance)")); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); chart.getLegend().setFrame(BlockBorder.NONE); return chart; }
@Override public void setPropertyValue(Object id, Object value) { LegendSettings ts = getValue(); if (id.equals(LegendSettings.PROPERTY_showLegend)) ts.setShowLegend((Boolean) value); else if (id.equals(LegendSettings.PROPERTY_font)) ts.setFont(MFontUtil.setMFont(value)); else if (id.equals(LegendSettings.PROPERTY_position)) ts.setPosition((EdgeEnum) posD.getEnumValue(value)); else if (id.equals(LegendSettings.PROPERTY_horizontalAlignment)) ts.setHorizontalAlignment(((JFreeChartHorizontalAlignmentEnum) hp.getEnumValue(value)).getJFreeChartValue()); else if (id.equals(LegendSettings.PROPERTY_verticalAlignment)) ts.setVerticalAlignment(((JFreeChartVerticalAlignmentEnum) vp.getEnumValue(value)).getJFreeChartValue()); else if (id.equals(LegendSettings.PROPERTY_backgroundPaint)) ts.setBackgroundPaint((PaintProvider) value); else if (id.equals(LegendSettings.PROPERTY_foregroundPaint)) ts.setForegroundPaint((PaintProvider) value); RectangleInsets ri = PadUtil.setPropertyValue(id, value, ts.getPadding()); if (ri != null) ts.setPadding(ri); BlockFrame bf = ts.getBlockFrame(); ri = PadUtil.setPropertyValue(id, value, bf == null ? null : bf.getInsets(), LegendSettings.PROPERTY_blockFrame); if (ri != null) ts.setBlockFrame(new BlockBorder(ri.getTop(), ri.getLeft(), ri.getBottom(), ri.getRight())); }
/** * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D. * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same * {@link DimensionConfig} s. */ private List<LegendTitle> createLegendTitles() { List<LegendTitle> legendTitles = new LinkedList<LegendTitle>(); LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration(); LegendTitle legendTitle = new SmartLegendTitle(this, new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2), new ColumnArrangement( HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2)); legendTitle.setItemPaint(legendConfiguration.getLegendFontColor()); RectangleEdge position = legendConfiguration.getLegendPosition().getPosition(); if (position == null) { return legendTitles; } legendTitle.setPosition(position); if (legendConfiguration.isShowLegendFrame()) { legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor())); } ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor()); wrapper.add(legendTitle.getItemContainer()); wrapper.setPadding(3, 3, 3, 3); legendTitle.setWrapper(wrapper); legendTitles.add(legendTitle); return legendTitles; }
public void paintDeviationChart(Graphics graphics, int width, int height) { prepareData(); JFreeChart chart = createChart(this.dataset); // 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); } Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height); chart.draw((Graphics2D)graphics, drawRect); }
public ChartPanel createChart(final String title, final CategoryDataset dataset, final String xlabel, final String ylable) { JFreeChart chart = ChartFactory.createLineChart(title, xlabel, ylable, dataset); ChartUtils.setAntiAlias(chart); ChartUtils.setLineRender(chart.getCategoryPlot(), false,true);// ChartUtils.setXAixs(chart.getCategoryPlot()); ChartUtils.setYAixs(chart.getCategoryPlot()); chart.getLegend().setFrame(new BlockBorder(Color.WHITE)); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
public ChartPanel createChart(final String title, final CategoryDataset dataset, final String xlabel, final String ylable) { JFreeChart chart = ChartFactory.createBarChart(title, xlabel, ylable, dataset); ChartUtils.setAntiAlias(chart); ChartUtils.setBarRenderer(chart.getCategoryPlot(), false); ChartUtils.setXAixs(chart.getCategoryPlot()); ChartUtils.setYAixs(chart.getCategoryPlot()); chart.getLegend().setFrame(new BlockBorder(Color.WHITE)); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
public ChartPanel createChart(String title, DefaultPieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, dataset); ChartUtils.setAntiAlias(chart); ChartUtils.setPieRender(chart.getPlot()); chart.getLegend().setFrame(new BlockBorder(Color.WHITE)); chart.getLegend().setPosition(RectangleEdge.RIGHT); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
public ChartPanel createChart(final String title, final CategoryDataset dataset, final String xlabel, final String ylable) { JFreeChart chart = ChartFactory.createStackedBarChart(title, xlabel, ylable, dataset); ChartUtils.setAntiAlias(chart); ChartUtils.setStackBarRender(chart.getCategoryPlot()); ChartUtils.setXAixs(chart.getCategoryPlot()); ChartUtils.setYAixs(chart.getCategoryPlot()); chart.getLegend().setFrame(new BlockBorder(Color.WHITE)); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
/** * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D. * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same * {@link DimensionConfig} s. */ private List<LegendTitle> createLegendTitles() { List<LegendTitle> legendTitles = new LinkedList<LegendTitle>(); LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration(); LegendTitle legendTitle = new SmartLegendTitle(this, new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2), new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2)); legendTitle.setItemPaint(legendConfiguration.getLegendFontColor()); RectangleEdge position = legendConfiguration.getLegendPosition().getPosition(); if (position == null) { return legendTitles; } legendTitle.setPosition(position); if (legendConfiguration.isShowLegendFrame()) { legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor())); } ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor()); wrapper.add(legendTitle.getItemContainer()); wrapper.setPadding(3, 3, 3, 3); legendTitle.setWrapper(wrapper); legendTitles.add(legendTitle); return legendTitles; }
/** * Check that the equals() method distinguishes all fields. */ public void testEquals() { CompositeTitle t1 = new CompositeTitle(new BlockContainer()); CompositeTitle t2 = new CompositeTitle(new BlockContainer()); assertEquals(t1, t2); assertEquals(t2, t1); // margin t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // border t1.setBorder(new BlockBorder(Color.red)); assertFalse(t1.equals(t2)); t2.setBorder(new BlockBorder(Color.red)); assertTrue(t1.equals(t2)); // padding t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // contained titles t1.getContainer().add(new TextTitle("T1")); assertFalse(t1.equals(t2)); t2.getContainer().add(new TextTitle("T1")); assertTrue(t1.equals(t2)); }
/** * Check that the equals() method distinguishes all fields. */ @Test public void testEquals() { CompositeTitle t1 = new CompositeTitle(new BlockContainer()); CompositeTitle t2 = new CompositeTitle(new BlockContainer()); assertEquals(t1, t2); assertEquals(t2, t1); // margin t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // border t1.setBorder(new BlockBorder(Color.red)); assertFalse(t1.equals(t2)); t2.setBorder(new BlockBorder(Color.red)); assertTrue(t1.equals(t2)); // padding t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // contained titles t1.getContainer().add(new TextTitle("T1")); assertFalse(t1.equals(t2)); t2.getContainer().add(new TextTitle("T1")); assertTrue(t1.equals(t2)); t1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(t1.equals(t2)); t2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(t1.equals(t2)); }
/** * Check that the equals() method distinguishes all fields. */ @Test public void testEquals() { CompositeTitle t1 = new CompositeTitle(new BlockContainer()); CompositeTitle t2 = new CompositeTitle(new BlockContainer()); assertEquals(t1, t2); assertEquals(t2, t1); // margin t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // frame t1.setFrame(new BlockBorder(Color.RED)); assertFalse(t1.equals(t2)); t2.setFrame(new BlockBorder(Color.RED)); assertTrue(t1.equals(t2)); // padding t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // contained titles t1.getContainer().add(new TextTitle("T1")); assertFalse(t1.equals(t2)); t2.getContainer().add(new TextTitle("T1")); assertTrue(t1.equals(t2)); t1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.YELLOW)); assertFalse(t1.equals(t2)); t2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.YELLOW)); assertTrue(t1.equals(t2)); }
private void incluirLegenda(final XYPlot plot) { if (isLegenda()) { LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 11)); lt.setBackgroundPaint(new Color(255, 255, 255, 100)); lt.setBorder(new BlockBorder(new Color(180, 180, 180))); lt.setPosition(RectangleEdge.TOP); XYTitleAnnotation ta = new XYTitleAnnotation(0.01, 0.98, lt, RectangleAnchor.TOP_LEFT); ta.setMaxWidth(0.48); plot.addAnnotation(ta); } }
/** * Check that the equals() method distinguishes all fields. */ public void testEquals() { CompositeTitle t1 = new CompositeTitle(new BlockContainer()); CompositeTitle t2 = new CompositeTitle(new BlockContainer()); assertEquals(t1, t2); assertEquals(t2, t1); // margin t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // frame t1.setFrame(new BlockBorder(Color.red)); assertFalse(t1.equals(t2)); t2.setFrame(new BlockBorder(Color.red)); assertTrue(t1.equals(t2)); // padding t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertFalse(t1.equals(t2)); t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); assertTrue(t1.equals(t2)); // contained titles t1.getContainer().add(new TextTitle("T1")); assertFalse(t1.equals(t2)); t2.getContainer().add(new TextTitle("T1")); assertTrue(t1.equals(t2)); t1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(t1.equals(t2)); t2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(t1.equals(t2)); }
private void setPlotMessage(String messageText) { chart.getXYPlot().clearAnnotations(); TextTitle tt = new TextTitle(messageText); tt.setTextAlignment(HorizontalAlignment.RIGHT); tt.setFont(chart.getLegend().getItemFont()); tt.setBackgroundPaint(new Color(200, 200, 255, 50)); tt.setFrame(new BlockBorder(Color.white)); tt.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation message = new XYTitleAnnotation(0.5, 0.5, tt, RectangleAnchor.CENTER); chart.getXYPlot().addAnnotation(message); }
protected JFreeChart createChart(XYDataset dataset, String name) { String title = name; JFreeChart xyLineChart = ChartFactory.createXYLineChart( title, // title "t", // x-axis label "n", // y-axis label dataset); String fontName = "Palatino"; xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); XYPlot plot = (XYPlot) xyLineChart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLowerMargin(0.0); // plot.getRangeAxis().setRange(0.0, 1.01); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); xyLineChart.getLegend().setFrame(BlockBorder.NONE); xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); // set the default stroke for all series int i = 0; for (String celltype : getTimeSeries().getDataSeriesNames()) { r.setSeriesPaint(i, CellTypeColor.getColor(celltype)); i++; } r.setSeriesPaint(i, Color.BLACK); return xyLineChart; }
protected JFreeChart createChart(XYDataset dataset, List<String> celltypes) { String title = "Cell cycle times"; JFreeChart xyLineChart = ChartFactory.createXYLineChart( title, // title "t", // x-axis label "T", // y-axis label dataset); String fontName = "Palatino"; xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); XYPlot plot = (XYPlot) xyLineChart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLowerMargin(0.0); // plot.getRangeAxis().setRange(0.0, 1.01); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); xyLineChart.getLegend().setFrame(BlockBorder.NONE); xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); // set the default stroke for all series int i = 0; for (String celltype : celltypes) { r.setSeriesPaint(i, CellTypeColor.getColor(celltype)); i++; } return xyLineChart; }