List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:com.kurvlrgui.gui.ChartPanel.java
/** * Creates new form ChartPanel/*from w w w. j a v a 2 s . co m*/ */ public ChartPanel(String title, NumericData s1, NumericData s2) { initComponents(); calculated = new XYSeries("Calculated"); for (NumericPair np : s1.values) { calculated.add(np.x, np.y); } observed = null; if (s2 != null) { observed = new XYSeries("Observed"); for (NumericPair np : s2.values) { observed.add(np.x, np.y); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(calculated); if (s2 != null) dataset.addSeries(observed); JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); panel = new org.jfree.chart.ChartPanel(chart); panel.setHorizontalAxisTrace(true); panel.setVerticalAxisTrace(true); this.add(panel); }
From source file:de.uniol.ui.tsv.ui.StepChartDialog.java
protected JFreeChart createChart() { JFreeChart chart = ChartFactory.createXYStepChartFast(title, xTitle, yTitle, xy, PlotOrientation.VERTICAL, true, false, false);/* w w w . j a va 2 s .co m*/ chart.setBackgroundPaint(Color.white); chart.getLegend().setBackgroundPaint(new Color(224, 224, 224)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setRenderer(new XYStepRendererFast(null, null)); XYItemRenderer xyr = plot.getRenderer(); // xyr.setBaseToolTipGenerator(new XYToolTipGenerator() { // public String generateToolTip(XYDataset dataset, int series, // int item) { // return nf.format(dataset.getXValue(series, item)) // + tooltipRangeUnits + ", " // + nf2.format(dataset.getYValue(series, item)) // + tooltipValueUnits; // } // }); for (int i : seriesStrokes.keySet()) { xyr.setSeriesStroke(i, seriesStrokes.get(i)); } for (int i : seriesColors.keySet()) { xyr.setSeriesPaint(i, seriesColors.get(i)); } DateAxis da = new DateAxis(xTitle); if (useRelativeHourFormat) { da.setDateFormatOverride(new RelativeHourFormat()); } da.setLowerMargin(0.03); plot.setDomainAxis(da); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setRange(new Range(minRange, maxRange)); return chart; }
From source file:hudson.plugins.codeviation.JavaFileIterableView.java
public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { Lookup lookup = Lookup.getDefault(); ChartConfProvider provider = null;/*from w w w. j a va 2 s . c om*/ ChartConf conf = getChartConf(req); if (lookup != null) { for (ChartConfProvider prov : lookup.lookupAll(ChartConfProvider.class)) { for (ChartConf c : prov.getChartConfs()) { if (c.equals(conf)) { provider = prov; } } } } if (provider == null) { provider = new CountsStatHandler(); conf = provider.getChartConfs()[0]; } Graph graph = conf.createGraph(); if (graph == null) { getLogger().info("Date:" + getMinDate() + "," + getMaxDate()); graph = new Statistics(getMinDate(), getMaxDate()); } JavaFileHandler handler = conf.getStatHandler(); graph.setJavaFileHandler(handler); graph.setItemsCount(100); handler.init(graph); graph.addJavaFiles(getJavaFiles()); handler.initGraphPaint(conf); JFreeChart chart = graph.getChart(conf, true); chart.setBackgroundPaint(Color.WHITE); chart.setTitle((String) null); XYPlot plot = (XYPlot) chart.getPlot(); // plot.setDomainGridlinePaint(Color.BLACK); // plot.setRangeGridlinePaint(Color.BLACK); // // plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // // plot.setDomainCrosshairVisible(true); // plot.setRangeCrosshairVisible(true); // XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; // renderer.setBaseShapesVisible(true); //// renderer.setBaseShapesFilled(true); // renderer.setUseFillPaint(true); // // // renderer.setSeriesItemLabelsVisible(1, true); // renderer.setUseOutlinePaint(true); renderer.setStroke(new BasicStroke(2.0f)); //// renderer.getPlot().setRenderer(1, r)getRenderer(1).setStroke(); //// renderer.setStroke(); // // // renderer.setS } // ChartUtil.generateGraph(req, rsp, chart, 400, 400); }
From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AggregationExecutionChartBuilder.java
@SuppressWarnings("deprecation") private void customizeChart(JFreeChart chart) throws IOException { chart.setBackgroundPaint(Color.white); chart.setBorderVisible(settings.isBorder()); TextTitle chartTitle = chart.getTitle(); customizeTitle(chartTitle, DEFAULT_TITLE_FONT); addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT); addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata")); StackedBarRenderer renderer = new StackedBarRenderer(true); plot.setRenderer(renderer);//from ww w . j av a 2s . c o m int index = 0; renderer.setSeriesPaint(index++, GREEN_COLOR); if (settings.isShowIgnored()) { renderer.setSeriesPaint(index++, Color.yellow); } renderer.setSeriesPaint(index, Color.red); renderer.setToolTipGenerator(new DefaultTooltipGenerator()); renderer.setItemURLGenerator(new CategoryURLGenerator() { @Override public String generateURL(CategoryDataset data, int series, int category) { Comparable<?> valueKey = data.getColumnKey(category); ChartLongValue value = (ChartLongValue) valueKey; return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');"; } }); CategoryAxis domainAxis = plot.getDomainAxis(); customizeAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setCategoryMargin(0.01); ValueAxis rangeAxis = plot.getRangeAxis(); customizeAxis(rangeAxis); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1.0); if (rangeAxis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setTickUnit(new NumberTickUnit(.10)); numberAxis.setNumberFormatOverride(PERCENT_FORMATTER); } plot.setForegroundAlpha(0.8f); }
From source file:org.jfree.chart.demo.TimeSeriesDemo11.java
/** * Creates the demo chart.//w w w . jav a 2s . co m * * @param title the title. * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final String title, final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Date", "Price", dataset, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.blue); return chart; }
From source file:com.orange.atk.atkUI.coregui.StatisticTool.java
/** * Creates the chart./*from www . j a v a 2 s .c o m*/ * * @param piedataset * the data set * @return the created chart */ private JFreeChart createChart(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D("", piedataset, true, true, false); jfreechart.setBackgroundPaint(Color.lightGray); PiePlot pie3dplot = (PiePlot) jfreechart.getPlot(); pie3dplot.setStartAngle(0); pie3dplot.setDirection(Rotation.CLOCKWISE); pie3dplot.setForegroundAlpha(0.5F); pie3dplot.setNoDataMessage("No data to display"); pie3dplot.setSectionPaint(0, Color.GREEN);// passed pie3dplot.setSectionPaint(1, Color.RED);// failed pie3dplot.setSectionPaint(2, Color.ORANGE);// skipped pie3dplot.setSectionPaint(3, Color.LIGHT_GRAY);// not analysed pie3dplot.setToolTipGenerator(new MyToolTipGenerator()); pie3dplot.setLabelGenerator(new MySectionLabelGenerator()); pie3dplot.setLegendLabelGenerator(new MySectionLabelGenerator()); return jfreechart; }
From source file:dinamica.SyncChartOutput.java
public void print(GenericTransaction t) throws Throwable { //get chart parameters Recordset chartinfo = t.getRecordset("chartinfo"); //get chart data String id = chartinfo.getString("data"); Recordset data = (Recordset) getSession().getAttribute(id); if (data == null) throw new Throwable( "Invalid Recordset ID:" + id + " - The session does not contain an attribute with this ID."); //general chart params Integer width = (Integer) chartinfo.getValue("width"); Integer height = (Integer) chartinfo.getValue("height"); //load chart plugin String plugin = (String) chartinfo.getValue("chart-plugin"); AbstractChartPlugin obj = (AbstractChartPlugin) Thread.currentThread().getContextClassLoader() .loadClass(plugin).newInstance(); JFreeChart chart = null; synchronized (data) { chart = obj.getChart(chartinfo, data); }/*from ww w.j av a 2 s . c o m*/ //set gradient chart.setBackgroundPaint(getGradient()); //set border and legend params chart.setBorderPaint(Color.LIGHT_GRAY); chart.setBorderVisible(true); if (chart.getLegend() != null) { chart.getLegend().setBorder(0.2, 0.2, 0.2, 0.2); chart.getLegend().setPadding(5, 5, 5, 5); chart.getLegend().setMargin(4, 5, 4, 4); } //render chart in memory BufferedImage img = chart.createBufferedImage(width.intValue(), height.intValue()); ByteArrayOutputStream b = new ByteArrayOutputStream(32768); //encode as PNG ImageIO.write(img, "png", b); //send bitmap via servlet output byte image[] = b.toByteArray(); getResponse().setContentType("image/png"); getResponse().setContentLength(image.length); OutputStream out = getResponse().getOutputStream(); out.write(image); out.close(); //save image bytes in session attribute if requested if (chartinfo.containsField("session")) { String session = chartinfo.getString("session"); if (session != null && session.equals("true")) getSession().setAttribute(chartinfo.getString("image-id"), image); } }
From source file:EHRAppointment.ChartPanelDraw.java
private ChartPanel createChart(XYDataset dataset, String type) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(type, "Date", getValueAxis(), dataset); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); plot.setRenderer(renderer);/*w w w. j av a2 s . c o m*/ final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return new ChartPanel(chart); }
From source file:classes.SharedClass.java
public void getStatistics() { result = db.select("member", new String[] { " count(id) id" }, new String[] { "id" }, new String[] { "99999" }, "!=", "and"); try {/*from w w w. j a v a2 s. co m*/ if (result.next()) { memberId = result.getInt("id"); } } catch (SQLException ex) { Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } //book result = db.select("book", new String[] { "count(id)" }, new String[] { "id" }, new String[] { "99999" }, "!=", "and"); try { if (result.next()) { bookId = result.getInt(1); } } catch (SQLException ex) { Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex); } //operations result = db.select("operations", new String[] { "count(id)" }, new String[] { "type" }, new String[] { "borrowed" }, "=", "and"); try { if (result.next()) { operationsId = result.getInt(1); } } catch (SQLException ex) { Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex); } DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); dataSet.setValue(memberId, "Percent", "Members"); dataSet.setValue(bookId, "Percent", "Books"); dataSet.setValue(operationsId, "Percent", "Borrowe books"); JFreeChart chart = ChartFactory.createBarChart3D("Statistics", "Fields", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.yellow); chart.getTitle().setPaint(Color.red); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.blue); ChartFrame frame = new ChartFrame("Statistics", chart); frame.setLocationRelativeTo(null); frame.setSize(500, 550); frame.setVisible(true); }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.RealisierungLineChart.java
private JFreeChart createProgressChart(Object dataset) { final double plotGap = 10.0; final int axisUpperBoundPadding = 50; final int labelFontSize = 10; XYDataset data1 = (XYDataset) dataset; XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis(Messages.RealisierungLineChart_1); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(Messages.RealisierungLineChart_2)); plot.setGap(plotGap);// w ww. j av a 2 s .c om plot.add(subplot1, 1); plot.setOrientation(PlotOrientation.VERTICAL); CountMassnahmen command = new CountMassnahmen(); try { command = ServiceFactory.lookupCommandService().executeCommand(command); } catch (CommandException e) { ExceptionUtil.log(e, Messages.RealisierungLineChart_3); } int totalNum = command.getTotalCount(); NumberAxis axis = (NumberAxis) subplot1.getRangeAxis(); axis.setUpperBound(totalNum + axisUpperBoundPadding); ValueMarker bst = new ValueMarker(totalNum); bst.setPaint(Color.GREEN); bst.setLabel(Messages.RealisierungLineChart_4); bst.setLabelAnchor(RectangleAnchor.LEFT); bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, labelFontSize)); //$NON-NLS-1$ bst.setLabelTextAnchor(TextAnchor.CENTER_LEFT); subplot1.addRangeMarker(bst, Layer.BACKGROUND); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(Messages.RealisierungLineChart_6, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); return chart; }